Interceptors & Guardrails
Interceptors and Guardrails
Interceptors are custom logic that can run before or after a request is routed, allowing you to enrich, validate, or transform requests and responses. Guardrails are a common type of interceptor used to enforce policies.
Pre-request
Analyze or enrich request
Classify topic, check for risk, personalize
semantic_guardrail
, toxicity_guardrail
Post-request
Analyze or modify response
Moderate output, add fallback, redact sensitive info
fallback_response
When an interceptor runs, it can inject its results into the routing context, making them available for your conditional logic.
semantic_guardrail.result.topic
Detected topic from a guardrail
"billing"
Route to topic-specialized models
toxicity_guardrail.result
Toxicity score from a guardrail
0.8
Block or reroute harmful content
rate_limiter.result
Result of a rate limit check
true
Enforce usage quotas and prevent abuse
Note on Guardrails: Guardrails like
semantic_guardrail
andtoxicity_guardrail
are powerful examples of custom guardrails. Checkout Guardrails section for more details.
Last updated
Was this helpful?