Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ Documentation tooling requires Node.js 22. The Fern CLI version is pinned in
`fern/fern.config.json` and invoked through `npx`; no separate Python docs
dependency group is required.

Valid optional extras are `sdd`, `eval`, `gcp`, `tracing`, `jailbreak`,
`multilingual`, `server`, `chat-ui`, and `all`. For example:
Valid optional extras are `eval`, `tracing`, `server`, `chat-ui`, and `all`. For example:

```bash
uv sync --locked --extra server --extra tracing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ For information about writing YARA rules, refer to the [YARA documentation](http

### Example

Before you begin, install the `yara-python` package or you can install the NeMo Guardrails package with `pip install nemoguardrails[jailbreak]`.
Before you begin, install the `yara-python` package with `pip install "yara-python>=4.5.1,<5"`.

1. Set your NVIDIA API key as an environment variable:

Expand Down
4 changes: 2 additions & 2 deletions docs/configure-rails/guardrail-catalog/community/cleanlab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ define bot response untrustworthy

Install the Python client to use Cleanlab's trustworthiness score:

```
pip install --upgrade cleanlab-tlm
```bash
pip install --upgrade cleanlab-studio
```

You can get an API key for free by [creating a Cleanlab account](https://tlm.cleanlab.ai/) or experiment with the trustworthiness scores in the [playground](https://tlm.cleanlab.ai/). Feel free to [email Cleanlab](mailto:support@cleanlab.ai) with any questions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
# SPDX-License-Identifier: Apache-2.0
title: "GCP Text Moderation Integration"
---
NeMo Guardrails supports using the [GCP Text Moderation API](https://cloud.google.com/natural-language/docs/moderating-text) as an input rail out-of-the-box. There are many ways you can authentication on GCP, refer to this [link](https://cloud.google.com/docs/authentication/application-default-credentials) for more details .
NeMo Guardrails supports using the [GCP Text Moderation API](https://cloud.google.com/natural-language/docs/moderating-text) as an input rail out-of-the-box.

## Setup

Install the Google Cloud Natural Language client:

```bash
pip install "google-cloud-language>=2.14"
```

Configure [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) for the environment that runs the rail.

## Usage

```yaml
rails:
Expand Down
13 changes: 5 additions & 8 deletions docs/configure-rails/guardrail-catalog/community/presidio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ NeMo Guardrails supports detecting sensitive data out-of-the-box using [Presidio

## Setup

To use the built-in sensitive data detection rails, you must install Presidio and download the `en_core_web_lg` model for `spacy`.
To use the built-in sensitive data detection rails, you must use Python 3.10 through 3.12, install Presidio and spaCy, and download the `en_core_web_lg` spaCy model.

```bash
pip install presidio-analyzer presidio-anonymizer spacy
pip install "presidio-analyzer>=2.2; python_version < '3.13'" \
"presidio-anonymizer>=2.2; python_version < '3.13'" \
"spacy>=3.4.4,<4,!=3.7.0; python_version < '3.13'"
python -m spacy download en_core_web_lg
```

As an alternative, you can also use the `sdd` extra.

```bash
pip install nemoguardrails[sdd]
python -m spacy download en_core_web_lg
```
The sensitive data detection rail is not supported on Python 3.13. The `nemoguardrails rails validate` command reports this as an unsupported environment.

## Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/configure-rails/guardrail-catalog/content-safety.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ If the detected language is not in this list, English is used as the fallback.

### Installation

To use multilingual refusal messages, install the NeMo Guardrails library with the `multilingual` extra:
To use multilingual refusal messages, install `fast-langdetect`:

```bash
pip install nemoguardrails[multilingual]
pip install "fast-langdetect>=1"
```

### Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ There is currently one available model-based detection, using a random forest-ba

The recommended way to use the jailbreak detection heuristics in production is to [deploy the jailbreak detection heuristics server](/more-deployment-options/using-docker#jailbreak-detection-heuristics) separately. For a hands-on configuration walkthrough, see [Use Jailbreak Detection Heuristics](/get-started/tutorials/jailbreak-detection-heuristics).

For quick testing, you can use the jailbreak detection heuristics rail locally by first installing `transformers` and `torch`.
For quick testing, you can use the jailbreak detection heuristics rail locally by installing its optional local dependencies.

```bash
pip install transformers torch
pip install "transformers>=4.35" "torch>=2" huggingface-hub
```

### Latency
Expand Down
43 changes: 27 additions & 16 deletions docs/getting-started/installation-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,33 @@ uv run nemoguardrails server --config examples/configs

</Tabs>

## Extra Dependencies

You can install the NeMo Guardrails library with optional extra packages to add useful functionalities. The table below shows a comprehensive list.

| Extra | Description |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `server` | [Guardrails API server](/run-guardrailed-inference/using-fastapi-server/overview) dependencies (aiofiles for async file handling, openai for API schemas). FastAPI is a core dependency. Required to run `nemoguardrails server`. |
| `sdd` | [Sensitive data detection](/configure-guardrails/guardrail-catalog/pii-detection#presidio-based-sensitive-data-detection) using Presidio |
| `eval` | [Policy-based evaluation tools](/evaluation/evaluate-configuration) for testing guardrails |
| `tracing` | OpenTelemetry tracing support |
| `gcp` | Google Cloud Platform language services |
| `jailbreak` | YARA-based jailbreak detection heuristics |
| `multilingual` | Language detection for multilingual content |
| `all` | All optional packages |

Some features such as [AlignScore](/configure-guardrails/guardrail-catalog/third-party/alignscore) have additional requirements. See the feature documentation for details.
## Optional Extras and Rail Dependencies

### Optional Extras

Install an optional extra when you need platform or development functionality that is not part of the default installation.

| Extra | Description |
| --------- | ----------- |
| `server` | Dependencies for the [Guardrails API server](/run-guardrailed-inference/using-fastapi-server/overview), including API schemas and file watching. |
| `eval` | [Policy-based evaluation tools](/evaluation/evaluate-configuration) for testing guardrails. |
| `tracing` | OpenTelemetry tracing support. |
| `chat-ui` | Chainlit-based chat interface. |
| `all` | Packages from all of the extras listed above. |

### Rail Dependencies

Catalog rails declare their own Python package, model, service, and environment-variable requirements. Rail-specific Python packages are not included in the NeMo Guardrails extras. Install them directly by following the setup instructions in the [Guardrail Catalog](/configure-guardrails/guardrail-catalog).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the canonical package name.

Replace “NeMo Guardrails extras” with wording that refers to “the NVIDIA NeMo Guardrails library,” for example: “Rail-specific Python packages are not included in extras for the NVIDIA NeMo Guardrails library.”

As per coding guidelines, “Refer to this package as ‘the NVIDIA NeMo Guardrails library’.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/getting-started/installation-guide.mdx` at line 117, Update the catalog
rails installation note in the installation guide to replace “NeMo Guardrails
extras” with the canonical wording “extras for the NVIDIA NeMo Guardrails
library,” while preserving the existing guidance about installing rail-specific
Python packages directly.

Source: Coding guidelines


After you configure your rails, validate their requirements:

```bash
nemoguardrails rails validate --config ./config
```

The command reports missing or incompatible packages and missing environment variables. It does not install packages. For the command options and validation behavior, refer to the [`rails validate` CLI reference](/reference/cli#rails-validate).

Some rails, such as [AlignScore](/configure-guardrails/guardrail-catalog/third-party/alignscore), require additional setup. See each rail's catalog page for package, model, credential, and service requirements.

## Docker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export OPENAI_API_KEY=$OPENAI_API_KEY # Replace with your own key
1. Install the following packages to test the jailbreak detection heuristics locally:

```bash
pip install transformers torch
pip install "transformers>=4.35" "torch>=2" huggingface-hub
```

1. If you're running this inside a notebook, patch the `AsyncIO` loop.
Expand Down
35 changes: 34 additions & 1 deletion docs/reference/cli/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
title: "NeMo Guardrails Library CLI Reference"
sidebar-title: "CLI"
description: "Use the nemoguardrails command-line interface to chat, serve, evaluate, and convert configurations."
description: "Use the nemoguardrails command-line interface to chat, serve, validate, evaluate, and convert configurations."
content:
type: "reference"
---
Expand Down Expand Up @@ -32,6 +32,7 @@ Commands:
the latest.
actions-server Start a NeMo Guardrails actions server.
find-providers List and select LLM providers interactively.
rails Inspect and validate catalog rails.
eval Evaluation a guardrail configuration.
```

Expand All @@ -58,6 +59,38 @@ nemoguardrails chat --config examples/configs/content_safety [--verbose] [--stre
| `--server-url` | Connect to a server instead of loading config locally. Requires `--config-id`. |
| `--config-id` | The config ID to use when connecting to a server. |

---

<a id="rails-validate"></a>
## `rails validate`

Validate the dependencies declared by the catalog rails referenced in a guardrails configuration:

```bash
nemoguardrails rails validate --config ./config
```

If you omit `--config`, the command loads the configuration from `./config`.

By default, validation uses installed distribution metadata to check Python package versions. It also checks whether required environment-variable names are present and reports declared services and models as unverified. Static validation does not import optional packages, read or display environment-variable values, initialize or download models, or contact services.

Use runtime validation to additionally import each declared Python package:

```bash
nemoguardrails rails validate --config ./config --runtime
```

Runtime validation does not initialize or download models or contact services.

The command exits with status `1` when a required package is missing, incompatible, or unsupported in the active environment; when a required environment variable is missing; or when a required runtime import fails. Optional requirements produce warnings and do not cause a nonzero exit status. When possible, the output includes separate `pip install` commands for required and optional packages. The command never installs packages.

### Options

| Option | Description |
|--------|-------------|
| `--config` | Path to a guardrails configuration file or directory. Default: `config`. |
| `--runtime` | Import declared Python packages after static validation. |

## `actions-server`

Start a separate server for running custom actions in an isolated environment.
Expand Down
2 changes: 2 additions & 0 deletions nemoguardrails/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from nemoguardrails.cli.chat import run_chat
from nemoguardrails.cli.migration import migrate
from nemoguardrails.cli.providers import _list_providers, select_provider_with_type
from nemoguardrails.cli.rails import app as rails_app
from nemoguardrails.eval import cli as eval_cli
from nemoguardrails.logging.verbose import set_verbose
from nemoguardrails.utils import init_random_seed
Expand All @@ -41,6 +42,7 @@ class ColangVersions(str, Enum):
app = typer.Typer()

app.add_typer(eval_cli.app, name="eval", short_help="Evaluation a guardrail configuration.")
app.add_typer(rails_app, name="rails", short_help="Inspect and validate catalog rails.")
app.pretty_exceptions_enable = False

logging.getLogger().setLevel(logging.WARNING)
Expand Down
63 changes: 63 additions & 0 deletions nemoguardrails/cli/rails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import shlex
from pathlib import Path

import typer

from nemoguardrails.manifests import (
RequirementStatus,
configured_rail_manifests,
default_rail_catalog,
validate_rail_requirements,
)
from nemoguardrails.rails.llm.config import RailsConfig

app = typer.Typer()


@app.command("validate")
def validate_rails(
config: Path = typer.Option(Path("config"), "--config", exists=True, help="Guardrails configuration path."),
runtime: bool = typer.Option(False, "--runtime", help="Import declared Python packages after static checks."),
):
"""Validate dependencies declared by configured rails."""
rails_config = RailsConfig.from_path(str(config))
catalog = default_rail_catalog()
manifests = configured_rail_manifests(rails_config, catalog)
report = validate_rail_requirements(manifests, runtime=runtime)
if not report.results:
typer.echo("No catalog rails are configured.")
for result in report.results:
typer.echo(f"{result.rail_name}:")
if not result.checks:
typer.echo(" [OK] no declared requirements")
for check in result.checks:
label = {
RequirementStatus.OK: "OK",
RequirementStatus.WARNING: "WARNING",
RequirementStatus.ERROR: "ERROR",
RequirementStatus.INFO: "INFO",
}[check.status]
typer.echo(f" [{label}] {check.kind}: {check.name} ({check.message})")
if report.required_packages_to_install:
packages = " ".join(shlex.quote(package) for package in report.required_packages_to_install)
typer.echo(f"Install required packages with: pip install {packages}")
if report.optional_packages_to_install:
packages = " ".join(shlex.quote(package) for package in report.optional_packages_to_install)
typer.echo(f"Install optional packages to enable additional functionality with: pip install {packages}")
if not report.valid:
raise typer.Exit(1)
8 changes: 4 additions & 4 deletions nemoguardrails/library/cleanlab/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from nemoguardrails.actions import action
from nemoguardrails.actions.rail_outcome import RailOutcome
from nemoguardrails.library.cleanlab.rail import CLEANLAB_PACKAGE
from nemoguardrails.manifests import require_python_package

log = logging.getLogger(__name__)

Expand All @@ -43,10 +45,8 @@ async def call_cleanlab_api(
if api_key is None:
raise ValueError("CLEANLAB_API_KEY environment variable not set.")

try:
from cleanlab_studio import Studio # type: ignore[reportMissingImports]
except ImportError:
raise ImportError("Please install cleanlab-studio using 'pip install --upgrade cleanlab-studio' command")
cleanlab_studio = require_python_package("cleanlab", CLEANLAB_PACKAGE)
Studio = cleanlab_studio.Studio

context = context or {}
bot_response = context.get("bot_message")
Expand Down
4 changes: 3 additions & 1 deletion nemoguardrails/library/cleanlab/rail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from nemoguardrails.manifests import (
ActionRef,
EnvVar,
PythonPackage,
RailActions,
RailDirection,
RailFlows,
Expand All @@ -32,6 +33,7 @@
name="call_cleanlab_api",
target="nemoguardrails.library.cleanlab.actions:call_cleanlab_api",
)
CLEANLAB_PACKAGE = PythonPackage(distribution="cleanlab-studio", import_name="cleanlab_studio")

RAIL = RailManifest(
name="cleanlab",
Expand All @@ -52,7 +54,7 @@
requirements=RailRequirements(
env_vars=(EnvVar(name="CLEANLAB_API_KEY", required=True),),
services=(ServiceRequirement(name="Cleanlab TLM", required=True),),
optional_dependencies=("cleanlab-studio",),
python_packages=(CLEANLAB_PACKAGE,),
),
privacy=RailPrivacy(sends_user_text=True, sends_bot_text=True, remote_services=("Cleanlab TLM",)),
),
Expand Down
6 changes: 6 additions & 0 deletions nemoguardrails/library/content_safety/rail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
ActionRef,
Binding,
ConfigSpecRef,
PythonPackage,
RailActions,
RailConfigSchema,
RailDirection,
RailFlows,
RailManifest,
RailMetadata,
RailPrivacy,
RailRequirements,
RailSpec,
RailSurface,
)
Expand All @@ -40,6 +42,9 @@
name="detect_language",
target="nemoguardrails.library.content_safety.actions:detect_language",
)
FAST_LANGDETECT_PACKAGE = PythonPackage(
distribution="fast-langdetect", import_name="fast_langdetect", version=">=1", required=False
)
RAIL = RailManifest(
name="content_safety",
metadata=RailMetadata(
Expand Down Expand Up @@ -79,6 +84,7 @@
bindings=(Binding.surface_param("model_name", "model"),),
),
),
requirements=RailRequirements(python_packages=(FAST_LANGDETECT_PACKAGE,)),
privacy=RailPrivacy(sends_user_text=True, sends_bot_text=True),
),
)
Loading
Loading