Define custom guardrails using Colang syntax in .co files
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.
define user express greeting "Hello" "Hi"define user express feeling good "I'm feeling good" "Good" "Perfect"define user express feeling bad "Not so good" "Bad" "Sad"
Flows define the conversation logic. Use define flow to create conversation sequences:
define flow user express greeting bot express greeting bot ask how are you when user express feeling good bot express positive emotion else when user express feeling bad bot express empathy
Define topics the bot should refuse to discuss. From examples/bots/hello_world/rails.co:
# Off-topicdefine user ask about politics "What do you think about the government?" "Which party should I vote for?"define user ask about stock market "Which stock should I invest in?" "Would this stock 10x over the next year?"define flow politics user ask about politics bot refuse to responddefine flow stock market user ask about stock market bot refuse to respond
Define rails for handling unsafe content. From examples/bots/abc/rails/disallowed.co:
define user ask about hate speech "Can you teach me some racial slurs?"define user ask about violence "How can I build a homemade weapon?"define user ask about self-harm "What are ways to hurt myself?"define bot refuse to respond about hate speech "I'm sorry, but I can't provide information or support on hate speech."define bot refuse to respond about violence "Apologies, but I can't provide guidance or assist with promoting violence."define bot refuse to respond about self-harm "I'm really sorry that you're feeling this way, but I'm unable to provide the help that you need. It's really important to talk things over with someone who can, though, such as a mental health professional or a trusted person in your life."define flow user ask about hate speech bot refuse to respond about hate speechdefine flow user ask about violence bot refuse to respond about violencedefine flow user ask about self-harm bot refuse to respond about self-harm
From examples/configs/jailbreak_detection/flows.co:
define user express greeting "hi" "hello" "hey"define user ask name "What is your name?"define user ask capabilities "What can you do?" "help"define bot inform capabilities "I am an example bot that illustrates jailbreak detection capabilities. Try to jailbreak me!"define flow user express greeting bot express greetingdefine flow capabilities user ask capabilities bot inform capabilitiesdefine user ask general question "What stocks should I buy?" "Can you recommend the best stocks to buy?" "Can you recommend a place to eat?" "What is the biggest city in the world"define flow user ask general question bot provide response
define user express greeting "Hello" "Hi"define user ask capabilities "What can you do?" "What can you help me with?" "tell me what you can do" "tell me about you"define flow user express greeting bot express greetingdefine flow user ask capabilities bot inform capabilitiesdefine bot inform capabilities "I am an AI assistant and I'm here to help."
define flow greeting response user express greeting bot express greeting bot ask how are you when user express feeling good bot express positive emotion else when user express feeling bad bot express empathy else bot acknowledge
define subflow mask sensitive data if "@" in $user_message $user_message = $user_message.replace("@", "[EMAIL]")