Hello World
This guide shows you how to create a “Hello World” guardrails configuration that controls the greeting behavior. Before you begin, make sure you have installed NeMo Guardrails.
Prerequisites
This “Hello World” guardrails configuration uses the OpenAI gpt-4o-mini model.
- Install the
openaipackage:
-
Obtain an OpenAI API key from the OpenAI API keys page. The key has the form
sk-....Note: Calls to the OpenAI API require a paid OpenAI account with available credits. If your account has no credits, requests fail with an
insufficient_quota(HTTP 429) error. Add billing details and credits at platform.openai.com/account/billing before running the example. -
Set the
OPENAI_API_KEYenvironment variable to your key:
- If you’re running this inside a notebook, patch the AsyncIO loop.
Step 1: create a new guardrails configuration
Every guardrails configuration must be stored in a folder. The standard folder structure is as follows:
See the Configuration Reference for information about the contents of these files as well as the components of NeMo Guardrails (rail kinds, supported model providers, and how user and bot intents are matched).
- From the root directory of your project, create a folder, such as config, for your configuration:
- Create a config.yml file with the following content:
The models key in the config.yml file configures the LLM model. For a complete list of supported LLM models, see Supported LLM Models.
Step 2: load the guardrails configuration
To load a guardrails configuration from a path, you must create a RailsConfig instance using the from_path method in your Python code.
Create a new Python file (for example, main.py) in the root directory of your project, alongside the config folder you created in Step 1. Do not place this file inside the config folder, because the path ./config is resolved relative to the working directory from which you run the script. If you run the script from inside config, you will see a ValueError: Invalid config path ./config..
Your project layout should look like this:
Add the following to main.py:
Step 3: use the guardrails configuration
Use this empty configuration by creating an LLMRails instance and using the generate_async method in your Python code:
The format for the input messages array as well as the response follow the OpenAI API format.
Step 4: add your first guardrail
To control the greeting response, define the user and bot messages, and the flow that connects the two together. See Core Colang Concepts for definitions of messages and flows.
- Define the
greetinguser message by creating a config/rails.co file with the following content:
- Add a greeting flow that instructs the bot to respond back with “Hello World!” and ask how they are doing by adding the following content to the rails.co file:
- Define the messages for the response by adding the following content to the rails.co file:
- Reload the config and test it:
Congratulations! You’ve just created you first guardrails configuration!
Other queries
What happens if you ask another question, such as “What is the capital of France?”:
For any other input that is not a greeting, the LLM generates the response as usual. This is because the rail that we have defined is only concerned with how to respond to a greeting.
CLI Chat
You can also test this configuration in interactive mode using the NeMo Guardrails CLI Chat command:
Without any additional parameters, the CLI chat loads the configuration from the config.yml file in the config folder in the current directory.
Sample session
Server and Chat UI
You can also test a guardrails configuration using the NeMo Guardrails server and the Chat UI.
To start the server, run the following command from the root directory of your project (the parent of the config folder):
The Chat UI interface is now available at http://localhost:8000:

Next
- Core Colang Concepts explains the Colang concepts messages and flows.
- Configuration Reference covers the full set of configuration options, supported model providers, and the available rail types. Reading it next will give you the foundation you need before adding more complex rails.