Check Harmful Content with Reasoning Traces
Learn how to enable reasoning traces in the Nemotron 3.5 Content Safety NIM. Reasoning traces show the model’s step-by-step analysis before it issues a safety verdict, making decisions auditable and easier to debug.
By following this tutorial, you learn how to toggle reasoning on and off with a single configuration flag, and how to use a custom safety policy with reasoning enabled.
Prerequisites
- The NVIDIA NeMo Guardrails library installed.
- A personal NVIDIA API key generated on build.nvidia.com.
Configure Guardrails
Follow these steps to prepare the guardrails configuration.
-
Create a configuration directory by running the following command.
-
Save the following as
config/config.yml.Setting
enable_thinking: trueinstructs the model to emit a<think>…</think>block containing its reasoning trace before the safety verdict. Set it tofalsefor lower-latency classification without traces.The
request_categories: "/categories"parameter instructs the model to include theSafety Categoriesfield in the response. Omitting this causes the model to default to/no_categories, which suppresses that field. The 24-category taxonomy is applied regardless.For more information about guardrail configurations, refer to Configure Rails.
-
Save the following as
config/prompts.yml.Nemotron 3.5 Content Safety builds the full safety prompt server-side. The
prompts.ymlpasses only the conversation turns to classify. Thenemotron_content_safety_parse_*output parsers strip any<think>block and read the verdict lines (User Safety: safe/unsafe,Safety Categories: …).max_tokensis set to500(rather than100) to allow room for the reasoning trace.
Run the Guardrails Chat Application
-
Set the NVIDIA_API_KEY environment variable.
-
Run the interactive chat application.
-
Enter an unsafe prompt.
The model’s raw output before parsing contains the reasoning trace and the verdict:
-
Enter a safe prompt.
Import the NeMo Guardrails Library in Python
-
Install the IPython REPL and run it.
-
Load the guardrails configuration you created earlier.
-
Verify the guardrails with an unsafe request.
The content safety rail blocks the harmful request.
-
Verify the guardrails with a safe request.
The model responds with information about health benefits of exercise.
Toggle Reasoning On and Off
Change enable_thinking in config.yml to switch modes without any other configuration changes.
Use enable_thinking: true when you need to audit decisions, debug false positives, or understand how the model applies a custom policy. Use enable_thinking: false for latency-sensitive production deployments.
Use a Custom Safety Policy
Nemotron 3.5 Content Safety supports inline custom policies via custom_policy in chat_template_kwargs. With reasoning enabled, the model explains how it applies your policy before issuing a verdict.
Add custom_policy to the parameters block in config.yml:
When custom_policy is set, the model applies your free-text behavioral instructions instead of the built-in 24-category taxonomy. The request_categories parameter is not needed here: it requests category labels from the active policy, and the custom policy above does not define named categories. For more information about custom policies, refer to Custom policy with Nemotron 3.5 Content Safety.
Deploy Nemotron 3.5 Content Safety NIM Locally
This section shows how to run the Nemotron 3.5 Content Safety model locally while still using the build.nvidia.com hosted main model. The prerequisites are:
- The NeMo Guardrails library installed.
- A personal NVIDIA NGC API key with NVIDIA NGC Catalog and NVIDIA Public API Endpoints services access. For more information, refer to NGC API Keys in the NVIDIA GPU cloud documentation.
- Docker installed.
- NVIDIA Container Toolkit installed.
- GPUs meeting the memory requirements for the Nemotron 3.5 Content Safety NIM.
To run the Nemotron 3.5 Content Safety NIM in a Docker container, follow these steps:
-
Update the
config.ymlfile to point to a local NIM deployment. Add abase_urlfield underparameters: -
Start the Nemotron 3.5 Content Safety NIM Docker container.
-
Export your personal NGC API key to an environment variable.
Log in to the NGC registry.
-
Download the container.
-
Create a model cache directory on the host machine.
-
Run the container with the cache directory mounted.
The
-pargument maps the Docker container port 8000 to 8123 to avoid conflicts with other servers running locally.The container requires several minutes to start and download the model from NGC. Monitor progress with
docker logs nemotron-content-safety. -
Confirm the service is ready.
This returns the following response.
-
-
Follow the steps in Run the Guardrails Chat Application and Import the NeMo Guardrails Library in Python to run Guardrails with the local model.