> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# Hello World

> Create your first guardrails configuration to control greeting behavior with Colang 1.0.

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](/get-started/installation-guide).

## Prerequisites

This "Hello World" guardrails configuration uses the OpenAI `gpt-4o-mini` model.

1. Install the `openai` package:

```bash
pip install openai
```

1. Obtain an OpenAI API key from the [OpenAI API keys page](https://platform.openai.com/api-keys). 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](https://platform.openai.com/account/billing) before running the example.

2. Set the `OPENAI_API_KEY` environment variable to your key:

```bash
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY
```

1. If you're running this inside a notebook, patch the AsyncIO loop.

```python
import nest_asyncio

nest_asyncio.apply()
```

## Step 1: create a new guardrails configuration

Every guardrails configuration must be stored in a folder. The standard folder structure is as follows:

```
.
├── config
│   ├── actions.py
│   ├── config.py
│   ├── config.yml
│   ├── rails.co
│   ├── ...
```

See the [Configuration Reference](/configure-guardrails/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).

1. From the root directory of your project, create a folder, such as *config*, for your configuration:

```bash
mkdir config
```

1. Create a *config.yml* file with the following content:

```yaml
models:
 - type: main
   engine: openai
   model: gpt-4o-mini
```

The `models` key in the *config.yml* file configures the LLM model. For a complete list of supported LLM models, see [Supported LLM Models](/about-nemo-guardrails-library/supported-llms).

## 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:

```
.
├── main.py
└── config
    ├── config.yml
    └── ...
```

Add the following to *main.py*:

```python
from nemoguardrails import RailsConfig

config = RailsConfig.from_path("./config")
```

## 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:

```python
from nemoguardrails import LLMRails

rails = LLMRails(config)

response = rails.generate(messages=[{
    "role": "user",
    "content": "Hello!"
}])
print(response)
```

```yaml
{'role': 'assistant', 'content': "Hello! It's nice to meet you. My name is Assistant. How can I help you today?"}
```

The format for the input `messages` array as well as the response follow the [OpenAI API](https://platform.openai.com/docs/guides/text-generation/chat-completions-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](/configure-guardrails/colang/colang-1/tutorials/2-core-colang-concepts) for definitions of *messages* and *flows*.

1. Define the `greeting` user message by creating a *config/rails.co* file with the following content:

```text
define user express greeting
  "Hello"
  "Hi"
  "Wassup?"
```

1. 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:

```python
define flow greeting
  user express greeting
  bot express greeting
  bot ask how are you
```

1. Define the messages for the response by adding the following content to the *rails.co* file:

```python
define bot express greeting
  "Hello World!"

define bot ask how are you
  "How are you doing?"
```

1. Reload the config and test it:

```python
config = RailsConfig.from_path("./config")
rails = LLMRails(config)

response = rails.generate(messages=[{
    "role": "user",
    "content": "Hello!"
}])
print(response["content"])
```

```
Hello World!
How are you doing?
```

**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?":

```python
response = rails.generate(messages=[{
    "role": "user",
    "content": "What is the capital of France?"
}])
print(response["content"])
```

```
The capital of France is Paris.
```

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:

```bash
$ nemoguardrails chat
```

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

```
$ nemoguardrails chat
Starting the chat (Press Ctrl+C to quit) ...

> Hello there!
Hello World!
How are you doing?

> What is the capital of France?
The capital of france is Paris.

> And how many people live there?
According to the latest estimates, the population of Paris is around 2.2 million people.
```

## 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):

```bash
$ nemoguardrails server --config=./config

INFO:     Started server process [27509]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```

The Chat UI interface is now available at `http://localhost:8000`:

![NeMo Guardrails Chat UI showing the Hello World configuration](https://files.buildwithfern.com/nvidia-nemo-guardrails.docs.buildwithfern.com/nemo/guardrails/95576d09c65bfb94f282f7d88f01f1870950af9644d9aebbd31ab55511a05aeb/_dot_dot_/docs/_static/images/hello-world-server-ui.png)

## Next

* [Core Colang Concepts](/configure-guardrails/colang/colang-1/tutorials/2-core-colang-concepts) explains the Colang concepts *messages* and *flows*.
* [Configuration Reference](/configure-guardrails/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.