Skip to main content

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:
Output mapping:

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:
Hallucination detection works best with OpenAI models that support the n parameter for multiple completions. Other providers may not support this feature.

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:
The mapping function:

Sensitive Data Masking

Removes PII from bot responses before delivery.

Configuration

Usage in Flows

The action replaces detected entities:

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:
This provides explainable safety decisions with reasoning chains.

Caching Output Checks

Enable model caching to speed up repeated checks:
From nemoguardrails/library/content_safety/actions.py:196:

Best Practices

  1. Prioritize fast rails first - Run lightweight checks before expensive ones
  2. Use specialized models - Content safety models are faster than LLM self-checks
  3. Cache results - Reduce latency for similar outputs
  4. Layer defenses - Combine multiple complementary rails
  5. Test fallback messages - Ensure blocked outputs provide helpful alternatives
  6. Monitor false positives - Track and tune thresholds to minimize over-blocking

Performance Impact

See Also