Overview
A multi-rail configuration combines:- Input Rails: Validate and filter user inputs
- Output Rails: Check and moderate bot responses
- Dialog Rails: Control conversation topics and flows
- Retrieval Rails: Validate RAG outputs
Complete Multi-Rail Setup
1
Configure all models
Set up the main LLM and specialized safety models.
2
Define comprehensive input rails
Stack multiple input checks for robust protection.
3
Define comprehensive output rails
Validate bot responses before sending to users.
4
Define dialog rails for topic control
Control what topics the bot can discuss.
5
Configure prompts for all checks
6
Implement custom actions
Usage Example
Expected Behaviors
1
Safe, on-topic query
2
Off-topic query
3
Query with PII
4
Jailbreak attempt
5
Harmful content
Rail Execution Order
Rails execute in this sequence:Testing the Configuration
Performance Considerations
- Latency: Each rail adds processing time. Stack only necessary rails.
- Parallel Execution: Some rails can run in parallel for better performance.
- Caching: Enable caching for repeated content safety checks.
- Thresholds: Tune thresholds to balance security and user experience.
Best Practices
- Order Matters: Place fast, high-rejection-rate rails first
- Fail Fast: Block obvious violations early to save compute
- Clear Feedback: Provide specific messages for different rail failures
- Monitor Metrics: Track which rails activate most frequently
- Test Thoroughly: Cover edge cases and adversarial inputs
- Update Regularly: Refresh rails as new threats emerge
Related Examples
- Custom Guardrails - Building individual rails
- Chatbot Assistant - Practical multi-rail implementation
- Agentic Applications - Rails for autonomous agents