Skip to main content

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
Key Features:
  • 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
Key Features:
  • 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
Key Features:
  • 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
Key Features:
  • 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
Key Features:
  • 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:
Example session:

Best Practices from Examples

  1. Provide Multiple Utterance Examples: Include 2-5 variations for better LLM matching
  2. Use Specific Refusal Messages: Tailor refusals to the specific violation
  3. Organize by Category: Group related intents and flows together
  4. Test Edge Cases: Include boundary cases like “cooking” in the ABC example
  5. Be Comprehensive: Cover all safety categories relevant to your domain
  6. 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