Quick Start
1
Create a Guardrail
2
Async Guardrail
User Interaction Flow
GuardrailResult
Result of guardrail validation.Factory Methods
Instance Methods
Guardrail Trait
Synchronous validation interface.AsyncGuardrail Trait
Asynchronous validation interface.GuardrailAction
Action to take when validation fails.GuardrailConfig
Configuration for guardrail behavior.Builder Methods
Common Guardrail Patterns
Length Limiter
Profanity Filter
Best Practices
Chain multiple guardrails
Chain multiple guardrails
Use different guardrails for different concerns: length, content, format.
Use async for external APIs
Use async for external APIs
When calling moderation APIs, use AsyncGuardrail to avoid blocking.
Provide helpful error messages
Provide helpful error messages
Clear error messages help users understand why content was blocked.
Configure appropriate failure actions
Configure appropriate failure actions
Use Retry for transient issues, Stop for hard violations, Fallback for graceful degradation.
Related
Hooks
Lifecycle hooks
Agent
Agent API

