.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 usingdefine user:
examples/bots/hello_world/rails.co:
Defining Bot Messages
Define bot responses usingdefine bot:
Defining Flows
Flows define the conversation logic. Usedefine flow to create conversation sequences:
Off-Topic Rails
Define topics the bot should refuse to discuss. Fromexamples/bots/hello_world/rails.co:
Safety Rails
Define rails for handling unsafe content. Fromexamples/bots/abc/rails/disallowed.co:
Input/Output Rails
Define subflows for input and output processing. Fromexamples/configs/sample/config.co:
Jailbreak Detection Rails
Fromexamples/configs/jailbreak_detection/flows.co:
Variables and Context
Access and modify context variables in your flows:$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
Fromexamples/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
- If/Else Statements
- Pattern Matching
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 files4
Handle Edge Cases
Define flows for unexpected or unsafe user inputs
Testing Rails
- Interactive Chat
- Python Testing
Next Steps
Custom Actions
Call Python functions from your rails
Guardrails Library
Explore built-in guardrails