Skip to main content

Prerequisites

Before installing NeMo Guardrails, ensure your system meets the following requirements:

Python Version

NeMo Guardrails supports the following Python versions:
  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13
Python 3.9 and earlier versions are not supported.

C++ Compiler and Dev Tools

NeMo Guardrails uses annoy, a C++ library with Python bindings for efficient similarity search. You’ll need a C++ compiler and development tools installed on your system.
Install Xcode Command Line Tools:
xcode-select --install
This provides the necessary C++ compiler (clang) and build tools.

Installation

1

Install via pip

The simplest way to install NeMo Guardrails is using pip:
pip install nemoguardrails
This installs the core package with all essential dependencies.
2

Verify Installation

Verify that NeMo Guardrails is installed correctly:
nemoguardrails --help
You should see the help menu with available commands:
Usage: nemoguardrails [OPTIONS] COMMAND [ARGS]...

Commands:
  actions-server    Start a NeMo Guardrails actions server.
  chat              Start an interactive chat session.
  evaluate          Run an evaluation task.
  server            Start a NeMo Guardrails server.
3

Test Python Import

Test that you can import the package in Python:
from nemoguardrails import LLMRails, RailsConfig
print("NeMo Guardrails installed successfully!")
If this runs without errors, you’re ready to go!

Optional Dependencies

NeMo Guardrails supports optional features through extras. Install them based on your needs:
pip install "nemoguardrails[openai]"

Optional Dependencies Details

Includes:
  • openai - Official OpenAI Python client
  • langchain-openai - LangChain integrations for OpenAI models
Required for using OpenAI models (GPT-3.5, GPT-4, etc.).
Includes:
  • tqdm - Progress bars for evaluation
  • numpy - Numerical computing
  • streamlit - Web UI for evaluation results
  • tornado - Web server framework
Required for running nemoguardrails evaluate command.
Includes:
  • presidio-analyzer - PII detection and analysis
  • presidio-anonymizer - PII anonymization
Required for detecting and masking sensitive data like emails, phone numbers, SSNs, etc.
Not available for Python 3.13
Includes:
  • google-cloud-language - Google Cloud Natural Language API
Required for using Google Cloud services.
Includes:
  • langchain-nvidia-ai-endpoints - LangChain integration for NVIDIA NIM
Required for using NVIDIA NIM (NVIDIA Inference Microservices).
Includes:
  • opentelemetry-api - OpenTelemetry API
  • aiofiles - Async file operations
Required for distributed tracing and observability.
Includes:
  • yara-python - Pattern matching for jailbreak detection
Required for advanced jailbreak attempt detection.
Includes:
  • fast-langdetect - Fast language detection
Required for multilingual content safety.
Includes:
  • aiofiles - Async file operations
  • openai - OpenAI client for server endpoints
Required for running nemoguardrails server with full features.

Development Installation

For contributing to NeMo Guardrails or running tests, install from source:
1

Clone the Repository

git clone https://github.com/NVIDIA-NeMo/Guardrails.git
cd Guardrails
2

Install with Poetry

NeMo Guardrails uses Poetry for dependency management:
pip install poetry
poetry install --with dev
3

Activate the Environment

poetry shell
4

Run Tests

pytest

Docker Installation

You can also run NeMo Guardrails in a Docker container:
# Build the image
docker build -t nemoguardrails .

# Run the server
docker run -p 8000:8000 -v $(pwd)/config:/config nemoguardrails \
  nemoguardrails server --config /config
For detailed Docker usage, see the Using Docker guide in the official documentation.

Environment Variables

For using LLM providers, you’ll typically need API keys set as environment variables:
OpenAI
export OPENAI_API_KEY="your-api-key-here"
Anthropic
export ANTHROPIC_API_KEY="your-api-key-here"
Cohere
export COHERE_API_KEY="your-api-key-here"

Troubleshooting

Windows users: Install Microsoft C++ Build Tools as described in the prerequisites section.
Linux/macOS users: Install build tools and Python development headers:
Ubuntu/Debian
sudo apt-get install build-essential python3-dev
macOS
xcode-select --install
The annoy library didn’t install correctly. This usually means the C++ compiler isn’t available. Install the required build tools for your platform.
Consider using a virtual environment to isolate dependencies:
python -m venv nemo-env
source nemo-env/bin/activate  # On Windows: nemo-env\Scripts\activate
pip install nemoguardrails

Next Steps

Quickstart Guide

Now that you have NeMo Guardrails installed, follow the quickstart guide to create your first guardrails configuration.