NeMo Engine

gllm-guardrailarrow-up-right | Tutorial: Guardrail | Engine: NeMo | API Referencearrow-up-right

What it does

NemoGuardrailEngine integrates with NVIDIA NeMo Guardrailsarrow-up-right to run LLM-based moderation.

In this library, NeMo Guardrails is wired to gllm-inference via a custom provider, so the engine can use the same model ecosystem you already use elsewhere in the SDK.

What it can handle (in this library)

Out of the box, the default NeMo configuration includes:

  1. Allowed & denied topic guardrails (allowlist / denylist / hybrid / disabled)

  2. Prompt injection / jailbreak detection (via predefined flows)

  3. Core safety restrictions (categories such as violence, hate, privacy, system manipulation, etc.)

circle-info

NeMo Guardrails as a framework can be extended to cover more cases (e.g., hallucination checks, toxicity policies), but those require custom guardrails configuration in config_dict and/or colang_config.

Use default config

from gllm_guardrail import NemoGuardrailEngine

engine = NemoGuardrailEngine()

Default model and credentials (important)

The default config_dict uses:

  1. Model: openai/gpt-5-nano

  2. Credentials: "OPENAI_API_KEY" (resolved from environment variables)

Use custom config

Configuration is done by passing a NemoGuardrailEngineConfig into the engine:

1) Topic safety settings

2) Enable/disable core restriction categories

How to change the LLM model and its configuration

The NeMo engine reads model configuration from config_dict["models"]. The provider is already set up to use gllm-inference:

  • engine: "gllm_invoker"

  • model: any model id supported by gllm-inference (e.g., "openai/gpt-4o-mini", "azure-openai/gpt-4o-mini", etc.)

  • parameters.credentials: can be either:

    • a string that is resolved from environment variables (recommended), or

    • a direct credential string/dict

  • parameters.model_kwargs: passed to the invoker builder (provider-specific fields + default_hyperparameters)

Example (switch model + tune hyperparameters):

circle-info

If credentials is a string, the engine resolves it like this:

  1. If it matches an environment variable key, it loads the env var value.

  2. Otherwise it treats the string as the credential value directly.

Blocking behavior: configure denial phrases

This engine decides “unsafe” by checking whether the NeMo output contains any configured denial_phrases substrings.

Recommended defaults for the built-in Colang flows:

Custom guardrails with Colang

If you already have your own NeMo Guardrails configuration, you can provide:

  1. colang_config (string), and/or

  2. config_dict (models + rails config)

Last updated