Guardrails API (Python)
Methods, examples, and parameters for client.guardrails.
Module Overview
Attach safety policies and moderation checks before and after model execution.
Available Methods
client.guardrails.list()- List available guardrails.client.guardrails.apply()- Apply a guardrail set to a request.client.guardrails.test()- Run dry-run policy evaluations.
Examples
Python
from therouter import TheRouter.ai
client = TheRouter.ai(
api_key=os.getenv("THEROUTER_API_KEY"),
base_url="https://api.therouter.ai/v1",
)
result = client.guardrails.test(
guardrail_id="gr_content_safety",
input="Classify this message for risk.",
)
print(result.verdict)guardrails-response.json
{
"id": "req_01HXYZ123",
"module": "guardrails",
"status": "ok"
}Parameter Types
| Name | Type | Required | Description |
|---|---|---|---|
guardrail_id | string | Required | Guardrail identifier. |
input | string | Required | Input text to evaluate. |
mode | string | enforce or monitor mode. |
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.