NeMo Guardrails Library Configuration Overview#
Before using the NeMo Guardrails library, you need to prepare configuration files that define your guardrails behavior. When you initialize the library’s core classes or the nemoguardrails CLI chat or server, it will load these configuration files as shown in the next chapter Run the NeMo Guardrails Library with the Python APIs. This section provides complete instructions on preparing your configuration files and executable scripts.
A guardrails configuration includes the following components. You can start with a basic configuration and add more components as needed. All the components should be placed in the config folder, and the locations in the following table are relative to the config folder.
Component |
Required/Optional |
Description |
Location |
|---|---|---|---|
Core Configuration |
Required |
A |
|
Colang Flows |
Optional |
A collection of Colang files ( |
|
Custom Actions |
Optional |
Python functions decorated with |
|
Custom Initialization |
Optional |
Python code that runs once at startup to register custom LLM providers, embedding providers, or shared resources (for example, database connections). |
|
Knowledge Base Documents |
Optional |
Documents ( |
|
Example Configuration Folder Structures#
The following are example configuration folder structures.
Basic configuration
config/ └── config.yml
Configuration with Colang rails and custom actions
config/ ├── config.yml ├── rails/ │ ├── input.co │ ├── output.co │ └── ... └── actions.py # Custom actions called from Colang flows
Configuration with custom LLM provider registration
config/ ├── config.yml ├── rails/ │ └── ... ├── actions.py # Custom actions └── config.py # Registers custom LLM provider at startup
Complete configuration with all components
config/ ├── config.yml # Core configuration ├── config.py # Custom initialization (LLM providers, etc.) ├── rails/ # Colang flow files │ ├── input.co │ ├── output.co │ └── ... ├── actions/ # Custom actions (as a package) │ ├── __init__.py │ ├── validation.py │ ├── external_api.py │ └── ... └── kb/ # Knowledge base documents ├── policies.md ├── faq.md └── ...
Next Steps#
For each component, refer to the following sections for more details:
Configuring YAML File - A complete guide to writing your
config.ymlfile.Colang Guide -
.coflow files inrailsfolder.Configuring Custom Actions -
actions.pyoractions/folder for callable actions.Configuring Custom Initialization -
config.pyfor custom initialization.Knowledge Base -
kb/folder for RAG.
After preparing your configuration files, you can use the NeMo Guardrails SDK to instantiate the core classes (RailsConfig and LLMRails) and run guardrails on your LLM applications.
For detailed SDK usage, including loading configurations, generating responses, streaming, and debugging, refer to Run the NeMo Guardrails Library with the Python APIs.