Output Rails
Output rails execute after the LLM generates a response but before it’s delivered to the user. They validate, filter, and post-process bot messages to prevent hallucinations, policy violations, and sensitive data leaks.When Output Rails Execute
Output rails run immediately after the LLM generates a response:Blocked outputs trigger fallback responses. The user never sees the original unsafe content.
Built-in Output Rails
Content Safety Check Output
Validates bot responses against content policies.Configuration
Action Implementation
From nemoguardrails/library/content_safety/actions.py:143:Self Check Output
Uses the main LLM to validate its own responses.Configuration
Action Implementation
From nemoguardrails/library/self_check/output_check/actions.py:32:The output mapping
lambda value: not value inverts the result because self_check_output returns True when safe, but rails expect True to block.Hallucination Detection
Detects hallucinations by checking self-consistency across multiple completions.Configuration
How It Works
From nemoguardrails/library/hallucination/actions.py:40:Performance Considerations
- Generates 2 extra completions per response
- Adds significant latency (~3x normal response time)
- Best for high-stakes applications where accuracy is critical
Llama Guard Check Output
Uses Meta’s Llama Guard model for output validation.Configuration
Action Implementation
From nemoguardrails/library/llama_guard/actions.py:100:Sensitive Data Masking
Removes PII from bot responses before delivery.Configuration
Usage in Flows
Usage Examples
Combining Multiple Output Rails
Conditional Output Checking
Only check outputs for specific topics:Custom Fallback Messages
Parallel Output Rails
Enable parallel execution for better performance:Advanced Configurations
Reasoning-Enabled Content Safety
For advanced models, enable reasoning in safety checks:Caching Output Checks
Enable model caching to speed up repeated checks:Best Practices
- Prioritize fast rails first - Run lightweight checks before expensive ones
- Use specialized models - Content safety models are faster than LLM self-checks
- Cache results - Reduce latency for similar outputs
- Layer defenses - Combine multiple complementary rails
- Test fallback messages - Ensure blocked outputs provide helpful alternatives
- Monitor false positives - Track and tune thresholds to minimize over-blocking
Performance Impact
See Also
- Input Rails - Validate user inputs
- Retrieval Rails - Fact checking for RAG
- Rail Types - Understanding all rail categories