Skip to main content
Rails are defined using Colang, a modeling language specifically created for designing flexible, yet controllable, dialogue flows. The .co files in your configuration contain Colang definitions.
NeMo Guardrails supports both Colang 1.0 (default) and Colang 2.0. This page focuses on Colang 1.0 syntax.

Basic Colang Syntax

Colang has a Python-like syntax designed to be simple and intuitive for developers.

Defining User Messages

Define what users might say using define user:
From examples/bots/hello_world/rails.co:

Defining Bot Messages

Define bot responses using define bot:

Defining Flows

Flows define the conversation logic. Use define flow to create conversation sequences:

Off-Topic Rails

Define topics the bot should refuse to discuss. From examples/bots/hello_world/rails.co:

Safety Rails

Define rails for handling unsafe content. From examples/bots/abc/rails/disallowed.co:

Input/Output Rails

Define subflows for input and output processing. From examples/configs/sample/config.co:

Jailbreak Detection Rails

From examples/configs/jailbreak_detection/flows.co:

Variables and Context

Access and modify context variables in your flows:
Common variables:
  • $user_message - The current user message
  • $bot_message - The bot’s response message
  • $context - The full conversation context
  • Custom variables defined in your flows

Capabilities Rails

From examples/configs/sample/config.co:

File Organization

Organize your rails into multiple .co files:

Activating Rails

Rails defined in .co files must be activated in config.yml:

Advanced: Conditional Flows

Best Practices

1

Use Descriptive Names

Choose clear, descriptive names for user/bot intents and flows
2

Provide Multiple Examples

Include various phrasings for each user intent
3

Organize by Topic

Group related rails in separate .co files
4

Handle Edge Cases

Define flows for unexpected or unsafe user inputs

Testing Rails

Next Steps

Custom Actions

Call Python functions from your rails

Guardrails Library

Explore built-in guardrails