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

NameTypeRequiredDescription
guardrail_id
stringRequiredGuardrail identifier.
input
stringRequiredInput text to evaluate.
mode
stringenforce or monitor mode.
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.