Retrieval Rails
Retrieval rails execute during RAG (Retrieval-Augmented Generation) pipelines to validate retrieved documents, filter chunks, and fact-check bot responses against the knowledge base.When Retrieval Rails Execute
Retrieval rails run at two key points in RAG workflows:Retrieval rails ensure only trusted, relevant, and safe content is used as context for LLM responses.
Built-in Retrieval Rails
Fact Checking with AlignScore
Verifies bot responses against retrieved evidence using information alignment scoring.Configuration
Action Implementation
From nemoguardrails/library/factchecking/align_score/actions.py:41:Self Check Facts
Uses the main LLM to verify responses against retrieved evidence.Configuration
Action Implementation
From nemoguardrails/library/self_check/facts/actions.py:43:AutoAlign Fact Checking
Integration with AutoAlign for advanced fact verification.Configuration
From examples/configs/autoalign/autoalign_factcheck_config/config.yml:Sensitive Data Detection in Retrieval
Filter PII from retrieved documents before using as context.Configuration
Usage in Flows
Usage Examples
Conditional Fact Checking
Only check facts for specific topics: From examples/configs/autoalign/autoalign_groundness_config/rails/factcheck.co:Custom Accuracy Thresholds
From examples/configs/rag/fact_checking/rails/factcheck.co:- Block responses with accuracy < 0.4
- Warn for accuracy between 0.4 and 0.6
- Allow for accuracy ≥ 0.6
Multi-Stage Retrieval Validation
Advanced Configurations
Custom Fact Checking Prompts
Override the default fact-checking task prompt:Chunk-Level Validation
Fallback Strategies
Best Practices
- Always validate retrieved chunks - Don’t assume knowledge base quality
- Use appropriate thresholds - Tune accuracy thresholds based on domain risk
- Provide fallbacks - Have graceful degradation when fact checks fail
- Filter sensitive data early - Remove PII before using chunks as context
- Cache fact check results - Avoid redundant checks for similar responses
- Monitor accuracy scores - Track distribution to tune thresholds
Performance Considerations
Fact-checking adds latency to every RAG response. Consider using it selectively for high-stakes queries.
Troubleshooting
No Evidence Available
AlignScore Endpoint Issues
See Also
- Output Rails - Response validation
- Input Rails - Query validation
- RAG Configuration - Setting up retrieval