Skip to main content
This example demonstrates how to implement custom guardrails for input validation and output checking using Colang 2.x.

Overview

Custom guardrails allow you to:
  • Define custom validation logic for user inputs
  • Implement specialized output checking
  • Control conversation flow based on safety checks
  • Build reusable guardrail components

Basic Custom Input Guardrail

1

Configure the bot

2

Create custom input checking flow

This custom guardrail:
  • Checks every input using an LLM prompt
  • Returns a boolean indicating safety
  • Blocks unsafe inputs with a polite refusal

Advanced Content Safety Guardrail

Implement sophisticated content safety using NemoGuard models:
1

Configure multiple models

2

Define comprehensive input/output rails

3

Configure topical rules

Custom Action-Based Guardrail

Implement guardrails using Python actions for maximum control:
1

Create a custom action

2

Use the action in flows

LLama Guard Integration

Use Meta’s LLama Guard for safety checking:

Jailbreak Detection

Protect against prompt injection and jailbreak attempts:

Testing Custom Guardrails

Best Practices

  1. Layer Multiple Guardrails - Combine content safety, topic control, and jailbreak detection
  2. Use Appropriate Models - Choose specialized models for specific safety tasks
  3. Test Thoroughly - Cover edge cases and adversarial inputs
  4. Provide Clear Feedback - Tell users why their input was blocked
  5. Monitor Performance - Track guardrail activation rates and false positives
  6. Update Regularly - Refresh patterns and rules as new threats emerge