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
35 small wins to finish your pathNext lesson

The server, the chat command and the rail library

This course used NeMo Guardrails from Python, one config at a time. The same package runs as a server, has a command line, and ships a library of ready-made rails.

The command line

Installing the package adds a nemoguardrails command. nemoguardrails chat --config=. opens an interactive conversation with a config folder. server starts an HTTP server that other applications call, actions-server runs actions in a separate process, eval evaluates a configuration, and convert moves Colang files from an older version to the latest.

Example
import subprocess
import sys

out = subprocess.run([sys.executable, "-m", "nemoguardrails", "--help"],
                     capture_output=True, text=True).stdout
for name in ["chat", "server", "actions-server", "eval", "convert"]:
    print(name, name in out)

The rail library

Example
import os
import nemoguardrails.library as library

folders = sorted(name for name in os.listdir(os.path.dirname(library.__file__))
                 if not name.startswith("_") and "." not in name)
print(len(folders))
print(", ".join(folders[:12]))

self_check is where self check input and self check output came from. The other folders include jailbreak and injection detection, content safety models such as Llama Guard, fact-checking and hallucination checks, sensitive data detection, and integrations with outside services. Each is switched on the way lesson 13 switched on self check input: a flow name in config.yml, plus whatever model or key the rail needs.

Other things this course did not cover

Retrieval rails, the retrieval list in config.yml, check the chunks fetched for a retrieval-augmented answer. stream_async streams a reply as it is written. Colang 2.0 is a rewrite of the language; colang_version still defaults to 1.0, which is what this course used throughout.

Guardrails AI is a different product with a similar name: a Python library of validators wrapped around a model call. NeMo Guardrails even ships an integration for it in its rail library. Tutorials for one do not apply to the other.
Try it yourself
  • Run nemoguardrails chat --config=. in a config folder from this course and hold a conversation.
  • Open library/jailbreak_detection and find the flow names it defines.
  • Print RailsConfig.from_content(yaml_content="models: []").colang_version.

Little by little, you're building something great.