Built-in Guardrails
PII Detection
Guardrails automatically detect and handle various types of personally identifiable information (PII) in both user inputs and agent outputs:email- Email addressescredit_card- Credit card numbers (validated with Luhn algorithm)ssn- Social Security Numbersphone- Phone numbersip_address- IP addresses (validated with stdlib)url- URLs
Content Moderation
Guardrails can detect and block toxic or harmful content using OpenAI’s moderation API:block_toxic- IfTrue, blocks toxic, harmful, or inappropriate content before it reaches the model (requiresOPENAI_API_KEYenvironment variable)
PII Handling Strategies
Each PII type can use one of these strategies to handle detected information:Basic Usage
Create a guardrail and add it to your agent. Guardrails automatically process both input and output:Content Moderation
Use OpenAI’s moderation API to detect and block toxic or harmful content:block_toxic- IfTrue, block toxic or harmful content using OpenAI moderation API (requiresOPENAI_API_KEYenvironment variable)
Custom Patterns
Add custom detection patterns for domain-specific sensitive information:- Compiled regex - Uses default “redact” strategy
- Tuple
(detector_func, strategy)- Custom detector function that returns a list of matches, with specified strategy