Skip to main content
This example demonstrates how to configure multiple guardrails working together to provide comprehensive input validation, output checking, and topical control.

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

  1. Order Matters: Place fast, high-rejection-rate rails first
  2. Fail Fast: Block obvious violations early to save compute
  3. Clear Feedback: Provide specific messages for different rail failures
  4. Monitor Metrics: Track which rails activate most frequently
  5. Test Thoroughly: Cover edge cases and adversarial inputs
  6. Update Regularly: Refresh rails as new threats emerge