For NVIDIA NIM + Nemotron agents

Guardrails that
actually run
in-process.

Composable runtime safety for every NIM API call. Input filtering, PII scrubbing, cost limits, tool auditing. Zero external services. One import.

Used in production agent stacks • MIT licensed
nim-agent-guardrails header graphic
Zero infra
6
Built-in guardrails
0
External services
37
Unit tests passing
<1ms
Per guardrail overhead
Live in the browser

Interactive Guardrails Demo

Test the exact same guardrail logic that runs in Python — no API key, no backend.

Results will appear here after running the demo
Quick failing cases
6 built-in primitives

Composable by default

InputLengthGuardrail INPUT
Rejects inputs exceeding char or estimated token limits
Default: 4000 chars / 1500 tokens
BlockedTopicGuardrail IN / OUT
Blocks messages matching configurable regex patterns (weapons, illegal, etc.)
Case-insensitive • Custom patterns supported
PiiDetectionGuardrail OUTPUT (opt-in input)
Detects emails, phones, SSNs, credit cards with regex
Selective PII types • Works on input or output
OutputFormatGuardrail OUTPUT
Enforces max length, required sections, and prohibited phrases
Great for structured responses
CostLimitGuardrail INPUT
Cumulative + per-request token budget enforcement
Stateful across turns • Auto records usage
ToolCallAuditGuardrail TOOL
Allow/block lists, max calls per turn, full audit trail
Audit log always populated
Click any card above to load a matching scenario into the live demo →
Simple & composable

Wrap every turn in safety

Guardrails run before the NIM call, around tool execution, and on the final output. Short-circuit on the first failure.

1. INPUT GUARDRAILS
Length + token estimate
Blocked topics / jailbreaks
Budget check (pre-flight)
2. NVIDIA NIM CALL
Uses the official OpenAI-compatible endpoint at integrate.api.nvidia.com/v1.
Full tool calling support. Automatic usage tracking.
Nemotron • Llama 3.1 • Any NIM model
3. OUTPUT + TOOL GUARDS
Tool allow/block + rate limits
PII redaction / blocking
Format + prohibited phrases
Every turn produces a structured TurnRecord + full audit log (JSON).
Drop-in usage

Code that feels native

from nim_guardrails import (
    NimClient, GuardedAgent, AgentConfig,
    GuardrailChain, InputLengthGuardrail,
    BlockedTopicGuardrail, PiiDetectionGuardrail, CostLimitGuardrail
)

client = NimClient()   # reads NVIDIA_API_KEY

input_guards = GuardrailChain([
    InputLengthGuardrail(max_chars=2000),
    BlockedTopicGuardrail(),
    CostLimitGuardrail(max_total_tokens=50_000),
])

agent = GuardedAgent(
    client=client,
    config=AgentConfig(system_prompt="You are a helpful travel assistant."),
    input_guardrails=input_guards,
    output_guardrails=GuardrailChain([PiiDetectionGuardrail()]),
)

response, record = agent.run("Plan a trip to Tokyo")
print(response)
print("Blocked?", record.blocked)
print("Latency:", record.latency_ms)
All examples run with pip install "git+https://...[nim]"
Ready to make your NIM agents safe by default?
Install in seconds. Works with any OpenAI-compatible NIM endpoint.
View on GitHub