Colang 1.0 Examples
This page showcases complete, real-world Colang 1.0 examples from the NeMo Guardrails source code.Example 1: Hello World Bot
The simplest conversational bot with greeting and emotional response handling. Source:examples/bots/hello_world/rails.co
- Simple greeting flow
- Conditional branching based on user sentiment
- Multiple utterance variations for better LLM matching
Example 2: Off-Topic Rails
Preventing the bot from discussing certain topics. Source:examples/bots/hello_world/rails.co
- Topic-based filtering
- Automatic refusal for off-topic questions
- Named flows for specific topics
Example 3: Comprehensive Safety Rails
A production-ready example with extensive safety guardrails. Source:examples/bots/abc/rails/disallowed.co
- Comprehensive safety coverage
- Specific, contextual refusal messages
- Separate flows for each safety category
- Production-ready safety rails
Example 4: Jailbreak Detection
Detecting and preventing jailbreak attempts. Source:examples/configs/jailbreak_detection/flows.co
- Intent-based routing
- General question handling
- Jailbreak detection hooks (configured in
config.yml)
Example 5: Edge Case Handling
Handling an off-topic question (cooking) that should be refused. Source:examples/bots/abc/rails/disallowed.co
- Shows how to block even benign topics if outside scope
- Demonstrates topic scoping strategy
Pattern Templates
Template 1: Simple Q&A
Template 2: Refusal Pattern
Template 3: Conditional Response
Template 4: Multi-Turn Interaction
Configuration Examples
Basic config.yml
With Custom Actions
Common Use Cases
Use Case 1: Customer Support Bot
Use Case 2: Educational Tutor
Use Case 3: Content Moderation
Testing Your Flows
Use the NeMo Guardrails CLI to test your Colang configurations:Best Practices from Examples
- Provide Multiple Utterance Examples: Include 2-5 variations for better LLM matching
- Use Specific Refusal Messages: Tailor refusals to the specific violation
- Organize by Category: Group related intents and flows together
- Test Edge Cases: Include boundary cases like “cooking” in the ABC example
- Be Comprehensive: Cover all safety categories relevant to your domain
- Use Clear Names: Make intent and flow names self-documenting
Next Steps
Introduction
Review Colang 1.0 fundamentals
Migrate to 2.0
Learn how to upgrade to Colang 2.0
Syntax Guide
Full syntax reference
Flows
Deep dive into flow patterns