In Nvidia's NeMo Guardrails framework, Colang uses context variables (denoted by $) to store and pass information between chatbot interactions, while flows define conditional response paths using if-else logic; variables can be initialized at conversation start via context role or extracted from user input during conversation, enabling personalized and adaptive chatbot behavior.
Colang Variables and Flows in NeMo Guardrails | Chatbot Tutorial
Added:in this video we're going to be exploring kolang of guardrails a little more and specifically focusing on the variables and flows within the kovalang modeling language now kolang is the modeling language that has been built specifically for building conversational flows for chat Bots by Nvidia and is used by the Nvidia Nemo guardrails Library curling is pretty simple and relatively easy to read particularly if you know python as well but there are a few Concepts and items that we kind of need to figure out before we begin using guard rails more that being said whilst we're figuring this out we will be using gold rails on top of these anyway so we're kind of learning as we go now when I'm going through this notebook there'll be a link to this notebook at the top of the video right now and what we're going to do is just take a look at these these variables how we set them and also the flows so we have the definition of a flow that I've already shown you in a previous video but we also want to take a look at the like if else within a flow and how we can use that and that fits quite nicely for variables so what I first want to do is we'll initialize our openai API key and we're going to initialize our kolang file and our config file right so let's just take a quick look at what we have here we have a user greeting this is our user message canonical form and these are some utterances that can Define what that should look like then we have our bot message canonical form here and when this is called we're going to return this which is hey name right and just note here that the name is preceded by this dollar symbol that means that this is a context variable so a variable within the context of our colon file and then we Define a flow so this flow is initialized if we see a user greeting and we can see that we have an if else statement in here so if name basically is saying if the name exists if that variable has been set then the bot is going to use this greeting here such as username otherwise the bot's just going to do a greeting right we haven't defined this canonical form here but the way that kolang and guardrails works is actually the part can just read this and build its own sort of message from that so it will basically create a greeting so let's try this all right so we're going to initialize our rails using those configs and now here we're doing something slightly different to what we're doing before so before we were doing like this uh we had instead of messages we were just passing in a single parameter and that's a completely valid way of doing this but by passing in messages we can also pass in conversational history which one is very useful by itself but also we can pass in this context role in this context role I haven't defined anything here yet but it will allow us to pass in variables or set variables at the beginning of the conversation so within the the messages that we're using here we're allowed to use three different rows we have that context where we use that and we have the assistant okay I've commented this out because I want you to see an example of what that assistant role would look like but we're not actually going to be using it at least not yet so we'll initialize those messages and we'll pass them into our rails okay and we get this response from the assistant role saying hey there how can I help you okay very similar to the The Prompt approach it just we have that history in there and we have the content so with this okay the body's just saying hey there how can I help you we kind of wanted to trigger this so right now it's gone to else because there is no name defined it's just created a bug reading right it's generated the greeting by itself so if we'd like it to trigger the name here and Trigger the bot name greeting we need to pass in at name and we can do within the content So within content we're going to pass a dictionary and that dictionary can contain our context variables and their values okay so I'm going to pass in my name through this and actually I'm going to remove this middle message from the assistant and now this is exactly the same as what we had up here but now we just have the context variable a name for James so let's run this and we see now that it triggers the hey James so that is the form that we specified here okay so that's now working now let's try adding these context variables from within the conversation rather than just sort of start of it because we can do that too okay so what I'm going to do here is I'm going to find a few things so I'm going to define the user giving a name and there's a few examples here of what that would look like we still have these so these are from before the user greeting and the bot name greeting but then we Define a new flow this flow is when the user is giving a name okay so initialize by this and so this is kind of an interesting way of doing things we can take the name from the input and when we're using this syntax here an llm is actually going to extract the name okay it's the way that we're in here is very likely I'm saying extract the name from the user's response so an LM will actually do that and it will pass the name that it extracts into this name variable here and then after that we can actually call the bot name greeting right okay so here we're just saying if the name does not already exist which it won't do ask for the name okay so let's see how that will work run this we're going to have to remove the name parameter from the context so let me uh remove that as well we re-initialize our rails and now we're going to generate okay we see here that the assistant is saying hi there what's your name okay why is it doing that let's take a look we have our user greeting this is being initialized because we say hey there if not to name so no name is defined the bottle will ask for the name okay which is what it does hi there what is your name then we're going to respond okay so first we want to add this response from the assistant to our messages so we add that here and then we also add our our response okay I'm going to say I'm James okay we run that and now because we have the name because that has been added it will respond with hey James okay so we come up to here our input is us giving the name I said I'm James so we trigger this flow music of name we extract the name from the user giving it using the LM and then the Bots responds with this bot name greeting which is hey name which is exactly what we get down here okay so let's just say quick introduction to how variables and flows work within colang and Nemo guardrails I wanted that to be a very quick introduction to those in the next video what we're going to be looking at is something called actions so the execution of actual code from within our guard rails which will be pretty interesting so for now that's it for this video I hope it's been useful and interesting so thank you very much for watching and I will see you again in the next one
Up Next

LiteLLM Crash Course for Beginners: Unified LLM Gateway
@datasciencebasics
12K views•2025-06-02

Secure Multiparty Computation (MPC): Foundations & Challenges
@SimonsInstitute
7.3K views•2015-05-28

Bypassing Tor Censorship: Bridges and Pluggable Transport Guide
@Coding_ForEveryone
397 views•2024-06-11

Neural Networks Explained: Math, Layers, and Learning Fundamentals
@3blue1brown
21.9M views•2017-10-05
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Artificial Intelligence
![[ML News] Geoff Hinton leaves Google | Google has NO MOAT | OpenAI down half a billion](https://i.ytimg.com/vi/cjs7QKJNVYM/maxresdefault.jpg)




































