What you are going to build
NeMo Guardrails is a runtime that sits between your application and its model. It reads a folder of configuration, checks the message on the way in, decides what the assistant is allowed to talk about, checks the answer on the way out, and hands back either the answer or a refusal. This course builds that folder for one support assistant, and every lesson runs on your machine with no API key.
An assistant with no rails will answer anything it is asked, including the things your company would rather it did not say. Wrapping it in if statements works for a week. NeMo Guardrails is what that grows into: a small language for describing what may happen, and a runtime that enforces it.
The guarded assistant, working
from nemoguardrails import LLMRails, RailsConfig
shop = LLMRails(RailsConfig.from_path("."))
for ask in ["Has order A17 shipped?", "Where is order Z01?",
"How long does a refund take?", "Give me a staff price"]:
print(shop.generate(messages=[{"role": "user", "content": ask}])["content"])Four questions, four different mechanisms. The first was matched to a known intent and answered by a Python function that looked the order up. The second took the same path and failed to find the order. The third came back as a fixed sentence written in the configuration. The fourth never reached the model at all.
RailsConfig.from_path(".") read three files out of the current folder: a config.yml, a rails.co, and a config.py. Lessons 31 to 33 write all three, a few lines at a time.
No key, and no downloads either
Every other NeMo Guardrails tutorial starts with export OPENAI_API_KEY. There is a second cost nobody mentions: the first time a message has to be matched against an intent, NeMo fetches an embedding model of about ninety megabytes through FastEmbed.
This course pays neither. You write a stand-in chat model in lessons 4 and 5, and a stand-in embedding model in lesson 9, about fifty lines between them, and register both under one engine name. They are real models as far as the runtime is concerned, and they decide things rather than replaying a script.
Lesson 29 shows the four lines that swap in a real model, and says plainly what changes when you do.
What you will have built
| Piece | What it does | Lesson |
|---|---|---|
| A stand-in chat model | Answers the runtime's questions, for free | 4 and 5 |
| A stand-in embedding model | Matches a message to an intent, for free | 9 |
| Colang flows | What the assistant may say, and when | 7 and 8 |
| An input rail | Refuses a message before the model sees it | 12 to 15 |
| Actions | Your Python running inside a rail | 16 to 19 |
| An output rail | Checks or rewrites the answer | 20 to 22 |
| An execution rail | Checks what a tool handed back | 25 |
| The guarded shop assistant | All of it in one folder | 31 to 33 |
What you need
- Python 3.10 or newer.
pip install nemoguardrails. Lesson 3 covers what that pulls in.- No account, no key, no card, no model download.
- Change one of the four questions above to
"Where is order B99?"and run it again. - Add
"Give me a discount code"to the list. Predict which of the four mechanisms stops it.
Every expert started right here.