Publish a Guardrail
Once a guardrail is configured and ready to be used, simply publish the guardrail. Once published, a new version of your guardrail will be created. This allows you to maintain full traceability of previous versions and publish a new one without impacting existing clients using earlier versions.
Once a new version is created, existing connected agents will continue using the previous version. To update them, you will need to explicitly request an update to the guardrail's latest version. Once a guardrail is deleted, it cannot be undone, and all existing agents will lose their guardrail configuration.
The guardrail can be used by the platform agents or directly for any external AI operation. To use it directly, simply use the integration button to see how to interact with the guardrail programmatically.
Via the SDK
Here is an example of publishing a guardrail that includes one Allowed Topic rule and one Toxicity rule. The Allowed Topic rule used in this example requires a valid OpenAI API key to function.
from superwise_api.models.agent.agent import OpenAIModel
from superwise_api.models.guardrails.guardrails import ToxicityGuard, AllowedTopicsGuard
open_ai_token = ""
model = OpenAIModel(api_token=open_ai_token, version="gpt-4o")
high_toxicity_guard = ToxicityGuard(name="Toxicity guard", tags=["input"], threshold=0.8, validation_method="sentence")
allowed_topics_guard = AllowedTopicsGuard(name="Cooking guard", tags=["input", "output"], topics=["cooking"], model=model)With the rules configured, we can use them to publish a guardrail version:
guardrail = sw.guardrails.create(name="My guardrail")
guardrail_version = sw.guardrails.create_version(guardrail_id=guardrail.id, name="My guardrail version", guardrules=[low_toxicity_guard, high_toxicity_guard])This guardrail version can now be used with the "run_versions" function:
input = "How long does it take to walk across the Manhattan bridge?"
guardrail_results = sw.guardrails.run_versions(tag="input", ids={guardrail_version.id}, query=input)Or be integrated with one of our agents, in connect guardrails.
Updated about 1 hour ago