Guardrails
Guardrails let you intercept and filter AI responses before they are converted to speech. Use them to block inappropriate content, enforce compliance, or replace sensitive responses.Basic Usage
Guardrail Interface
Creating Guardrails
Use thePatter.guardrail() static method for convenience:
replacement is "I'm sorry, I can't respond to that." when not specified.
Blocked Terms
Blocked terms are matched case-insensitively against the AI response text:Custom Check Function
For more complex filtering, use acheck function that receives the full response text and returns true to block it:
Combining Blocked Terms and Check
A guardrail triggers if eitherblockedTerms match or the check function returns true. Blocked terms are evaluated first:
Multiple Guardrails
You can stack multiple guardrails. They are evaluated in order, and the first match triggers:How It Works
- The AI model generates a text response.
- Before TTS conversion, each guardrail is checked in order.
- If a guardrail triggers, the original response is discarded and the
replacementtext is spoken instead. - If no guardrail triggers, the original response is spoken normally.

