Skip to content

DataRobot Moderations library

The DataRobot Moderations library applies guard-based moderation to LLM prompts and responses based on your guard configuration. You define guards in YAML (or programmatically), pass prompts and responses through a pipeline, and receive structured results that indicate whether content was blocked, replaced, or allowed with metrics attached.

Section Description
Moderations guardrails Configure guards in YAML, choose guard types and LLM backends, and use the Python API.
Using the Moderations CLI Install, authenticate, and run the dr-moderation CLI.

For each evaluation, the library can report:

  • Whether the prompt should be blocked.
  • Whether the completion should be blocked.
  • Metric values from model and out-of-the-box guards.
  • Whether the prompt or response was modified by a modifier guard.

Architecture

The library wraps the typical LLM prediction flow. It first runs prescore guards that evaluate prompts and enforce moderation when necessary. Prompts that pass prescore checks are forwarded to the LLM for completion. The library then evaluates those completions with postscore guards and enforces intervention as needed.

How to build it

The repository uses poetry to manage the build process and a wheel can be built using:

make clean
make

How to use it

You can install a generated or downloaded wheel file with pip; dependencies are installed automatically.

pip install datarobot-moderations

Optional extras

The base install covers token-count, ROUGE-1, cost, and NeMo guards. Heavier or cloud-specific dependencies are opt-in:

Extra What it enables
datarobot-sdk DataRobot model guards, DataRobot LLM evaluator type
llm-eval Faithfulness, Task Adherence, Agent Goal Accuracy, Guideline Adherence guards
nemo NeMo Guardrails colang-based flow guard
nemo-evaluator NeMo live-evaluation microservice guard
nvidia NVIDIA NIM / ChatNVIDIA LLM support
vertex Google Cloud Vertex AI LLM support
bedrock AWS Bedrock LLM support
all Every optional dependency at once

The library opts out of deepeval telemetry by default.

Example: task-adherence guard backed by a DataRobot LLM deployment

pip install 'datarobot-moderations[llm-eval,datarobot-sdk]'

Transient dependencies and build compatibility

Installing [all] (or the nemo / llm-eval extras individually) pulls in packages that nemoguardrails and deepeval declare as runtime dependencies but that this library never uses at runtime:

Package Pulled in by Problem
annoy nemoguardrails Requires a C++ compiler; breaks restricted build environments such as Kaniko
fastembed / onnxruntime nemoguardrails Heavy ML runtimes, hundreds of MB
fastapi / starlette / uvicorn nemoguardrails Web server stack, only used by nemoguardrails' built-in server
watchdog / prompt-toolkit / typer nemoguardrails, deepeval Dev-server and CLI tools
pyfiglet / wheel deepeval CLI banner / build artifact mis-declared as a runtime dep

To exclude them, add the following to your own project's pyproject.toml (these overrides are not inherited from this library):

[tool.uv]
override-dependencies = [
    "annoy; sys_platform == 'never'",
    "fastembed; sys_platform == 'never'",
    "onnxruntime; sys_platform == 'never'",
    "fastapi; sys_platform == 'never'",
    "starlette; sys_platform == 'never'",
    "uvicorn; sys_platform == 'never'",
    "watchdog; sys_platform == 'never'",
    "prompt-toolkit; sys_platform == 'never'",
    "typer; sys_platform == 'never'",
    "pyfiglet; sys_platform == 'never'",
    "wheel; sys_platform == 'never'",
]

Standalone Python API

Create a ModerationPipeline from a YAML file, a plain dict, or a Pydantic config object, then evaluate prompts, responses, or a full prescore → LLM → postscore pipeline. Each method has an async counterpart.

For constructor options, method parameters, return types, DataFrame schemas, streaming details, and environment variables, see Moderations guardrails.

Using the CLI

The package ships a dr-moderation CLI so you can manage guards without writing Python code. Commands include evaluate, add-guard, agent a2a connect, and serve (JSON-RPC over stdio or WebSocket).

For installation, authentication, command reference, YAML schema differences, and exit codes, see Using Moderations with the CLI.

Usage with DRUM

The library wraps DRUM's score method for prescore and postscore guards. With DRUM, run your custom model using drum score to use moderation features.

Install DRUM along with the optional extras required for your guards. If you are unsure which guards are in use, install [all]:

pip install datarobot-drum 'datarobot-moderations[all]'
drum score --verbose --logging-level info --code-dir ./ --input ./input.csv --target-type textgeneration --runtime-params-file values.yaml

For DRUM-specific guard configuration and the chat() hook response format, see Moderations in structured custom models.