| Example | Description |
|---|---|
| Custom Guardrail | Subclass BaseGuardrail and raise InputCheckError to block security-abuse prompts as a pre-hook. |
| OpenAI Moderation | Block flagged input with OpenAIModerationGuardrail as a pre-hook, including custom category lists and image moderation. |
| Output Guardrail | Reject responses under 20 characters with a post-hook that raises OutputCheckError. |
| PII Detection | Block SSNs, credit cards, emails, and phone numbers with PIIDetectionGuardrail, or mask them with mask_pii=True. |
| Prompt Injection | Block prompt injection and jailbreak attempts with PromptInjectionGuardrail as a pre-hook. |
| Mixed Hooks and Guardrails | Combine a logging pre-hook with PIIDetectionGuardrail; blocked runs return RunStatus.error instead of raising. |
Guardrails
Guardrails
Examples for input/output safety checks and policy enforcement.