NeMo Guardrailsnemoguardrails 0.24.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
20 small wins to finish your pathNext lesson

Install it, and what a config is

Lesson 2 ended with three things a hand-written guard cannot do. NeMo Guardrails provides all three, and the first thing to understand about it is that the unit of work is not a class you construct: it is a folder you write.

Install

bash
pip install nemoguardrails

That pulls in a runtime, a parser for the configuration language, and an embedding index. It does not pull in any model client. Which model you talk to is a line of configuration, not an install option.

A config is a folder

text
myconfig/
  config.yml     what models to use, which rails are on, which prompts to use
  rails.co       the conversation rules, written in Colang
  config.py      optional Python, run once when the config loads

Any number of .co files are allowed and they are all read. The names do not matter; the extension does. config.yml and config.py are the two fixed names.

The smallest config.yml

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

type says what the model is for, and main is the one that answers users. engine names a provider the runtime knows how to build, and model is that provider's own name for the model.

Reading it without running it

Example
from nemoguardrails import RailsConfig

config = RailsConfig.from_content(yaml_content="""
models:
  - type: main
    engine: openai
    model: gpt-4o-mini
""")
main = config.models[0]
print(main.type, main.engine, main.model)
print("colang version:", config.colang_version)

RailsConfig.from_content takes the same YAML as a string, which is what most lessons here use so that a whole configuration fits on the page. RailsConfig.from_path reads a folder, and lesson 26 switches to it.

colang_version came out as 1.0 and nothing in the YAML asked for it. That is the default, and it is the version this course teaches. Colang 2.0 exists, is still labelled beta in its own changelog, and is named in lesson 30.

What it will not do yet

Nothing above talked to a model, because engine: openai needs a key. The next lesson replaces that line with an engine you write yourself.

Try it yourself
  • Add a second entry under models with type: embeddings and print len(config.models).
  • Set colang_version: "2.0" in the YAML and print it again.

Slow is fine. Stopping is the only problem.