Free lesson · GenAI Safety & Evaluation Engineering
Compare guardrail frameworks: Guardrails AI vs NeMo Guardrails 0.20 vs NemoGuard NIMs vs Google Model Armor
You will implement the same content safety policy across four industry guardrail frameworks and compare them. Policy: block toxic content, filter PII, enforce topic relevance, reject prompt injection. Framework 1 (Guardrails AI): configure a Guard with ToxicLanguage, ProfanityFree, and CompetitorCheck validators. Wrap OpenAI calls with guard(client.chat.completions.create, ...). Framework 2 (NeMo Guardrails 0.20): write Colang 2.0 policy files defining user/bot message flows and safety rails. Configure NeMo Guardrails to use GPT-4o as the backing LLM (no NVIDIA NIM containers required). New in 0.20: LangGraph integration for multi-agent safety, parallel execution for input/output rails, and per-model LFU caching for NemoGuard models. Framework 3 (NemoGuard NIMs): deploy NVIDIA's dedicated safety microservices on GKE — NemoGuard Content Safety NIM, NemoGuard Topic Control NIM, and NemoGuard Jailbreak Detection NIM (Ardennes model). Also test Nemotron Content Safety Reasoning 4B — a 'Bring Your Own Safety Policy' model that provides chain-of-thought reasoning for safety decisions, adaptable to custom criteria. Framework 4 (Google Model Armor): GKE-native LLM firewall with content safety, injection detection, and SDP integration. Run all four on the same 200-request test set. Compare: detection accuracy, latency, developer experience, extensibility, and whether the system explains its safety decisions (reasoning). Generate a framework comparison matrix and recommendation.
Course: GenAI Evaluation, Safety & Governance · Chapter 12 · Content Safety Filters
Free to read — no subscription required.
Introduction
Teams that ship an LLM application quickly discover that "add a guardrail" is not one decision but a stack of them: which framework, which layer, which trade-off between latency, customisation, and vendor lock-in. Pick the wrong one and you either eat hundreds of milliseconds per request that you cannot optimise away, or you discover at audit time that you cannot explain why a specific message was blocked. By the end of this lesson you will be able to compare Guardrails AI, NeMo Guardrails 0.20, NemoGuard NIMs, and Google Model Armor across the dimensions that actually matter — architecture, policy language, latency, explainability, and lock-in — and justify which one (or which combination) fits a given deployment.
Key Terminology
- Guard — the Guardrails AI runtime object that wraps an LLM call and runs configured validators on the input and output. The unit of comparison for in-process Python frameworks in this lesson.
- Colang — NeMo Guardrails' domain-specific language for declaring conversational safety flows as
user … bot …pattern blocks. The thing that distinguishes NeMo from validator-list frameworks. - NemoGuard NIM — a containerised NVIDIA safety microservice (Content Safety, Topic Control, Jailbreak Detection, Nemotron Reasoning 4B) deployed on Kubernetes and called over REST. The unit of comparison for service-based frameworks.
- Model Armor — Google's GKE-native LLM firewall that intercepts traffic at the network layer rather than from application code. The unit of comparison for infrastructure-level frameworks.
- Rail — a single safety check (input, output, or dialog) executed as part of a guardrail pipeline. The latency budget of a framework equals the sum of its rails, or the max if parallel execution is enabled.
Concepts
Four architectural layers
Guardrails live at one of four layers, and the layer determines what you give up and gain. In-process Python (Guardrails AI) runs validators in the request thread — easiest to customise, but their execution time is added directly to user-facing response time. In-process DSL (NeMo Guardrails 0.20) embeds Colang flows inside the application — more expressive, with parallel rail execution and per-model LFU caching in 0.20 to amortise repeated checks. Service-based (NemoGuard NIMs) moves safety into dedicated GPU microservices — highest accuracy from purpose-built models, but adds network hops and GPU infrastructure. Infrastructure proxy (Model Armor) intercepts traffic outside the application as a sidecar or admission controller — zero code changes, uniform enforcement, but limited application context.
Policy expression and explainability
The four frameworks expose policy at different abstraction levels. Guardrails AI uses Python decorators and validator objects — programmers compose them like any other library. NeMo Guardrails uses Colang 2.0, where you declare flows matching user intents and bot responses; this captures multi-turn safety rules that flat validator lists cannot. NemoGuard NIMs accept either fixed category sets (Content Safety NIM) or natural-language policies (Nemotron Reasoning 4B), and the 4B model returns chain-of-thought explanations alongside verdicts. Model Armor uses YAML CRDs at the cluster level. Explainability degrades as you move away from the application: validator name → flow trace → chain-of-thought (4B only) → category label.
Comparison matrix
| Dimension | Guardrails AI | NeMo Guardrails 0.20 | NemoGuard NIMs | Model Armor |
|---|---|---|---|---|
| Architecture | In-process Python | In-process + Colang | K8s microservices | Network proxy |
| Policy language | Python validators | Colang 2.0 flows | REST + NL (4B) | YAML CRDs |
| Latency p50 | 50–150 ms | 80–200 ms | 100–300 ms | 30–80 ms |
| Explainability | Validator name | Flow trace | Chain-of-thought (4B) | Category label |
| Multi-agent | No | Yes (LangGraph) | No | No |
| GPU required | No | No | Yes | No |
| Vendor lock-in | None | Low (NVIDIA) | High (NVIDIA) | High (GCP) |
For deeper mechanics behind two contrasting rows of this matrix, see Code Walkthrough.
Code Walkthrough
The walkthrough below contrasts the two ends of the spectrum from the comparison matrix: an in-process Guard stack (Guardrails AI) and an out-of-process NemoGuard NIM call (Nemotron Reasoning 4B). Reading them side-by-side surfaces the architectural trade-off — direct latency with tight Python customisation versus a network hop with purpose-built model accuracy and chain-of-thought explanations.
Code snippetpython
1import os, openai 2from guardrails import Guard 3from guardrails.hub import ToxicLanguage, ProfanityFree, CompetitorCheck 4 5guard = Guard() 6guard.use(ToxicLanguage(threshold=0.5, on_fail="exception")) 7guard.use(ProfanityFree(on_fail="exception")) 8guard.use(CompetitorCheck(competitors=["CompetitorA"], on_fail="exception")) 9 10client = openai.OpenAI( 11 base_url=os.environ["OPENAI_PROXY_URL"] + "/v1", 12 api_key="student-token", 13) 14 15result = guard( 16 client.chat.completions.create, 17 model="gpt-4o", 18 messages=[{"role": "user", "content": user_input}], 19)
Code snippetpython
1import httpx 2 3async def check_with_reasoning(text: str, policy: str) -> dict: 4 """Call the NemoGuard Nemotron 4B reasoning model with a natural-language policy.""" 5 async with httpx.AsyncClient() as client: 6 response = await client.post( 7 "http://nemotron-safety-reasoning:8000/v1/safety/reason", 8 json={"text": text, "policy": policy, "chain_of_thought": True}, 9 timeout=10.0, 10 ) 11 return response.json() 12 13policy = "Children's education app. Block violence, weapons, drugs, adult themes." 14verdict = await check_with_reasoning(user_input, policy)
You'll know it works when the in-process snippet raises ValidationError on toxic input within roughly 100 ms while the NIM call returns a verdict object containing a chain-of-thought explanation in 200–500 ms. The latency gap and the explanation richness together let you defend a framework choice against a stakeholder who asks why one was picked over the other.
Do's and Don'ts
Do's
- ✓Do match the framework to the layer where safety policy lives — application-specific rules in Guardrails AI or NeMo Guardrails, organisation-wide policy in Model Armor.
- ✓Do measure per-rail latency in your own stack — published p50s are floors, not ceilings; compute-intensive validators like ToxicLanguage dominate the budget.
- ✓Do prefer the framework whose explainability you can defend — chain-of-thought from Nemotron 4B beats a category label in any audit or incident review.
Don'ts
- ✗Don't run a single framework as your only safety net — application bugs bypass code-level checks, so layer infrastructure-level enforcement (Model Armor) underneath.
- ✗Don't pick a framework on latency alone — Model Armor wins p50 but loses on custom rules and explainability, which matter more for regulated workloads.
- ✗Don't ignore vendor lock-in — NemoGuard NIMs (NVIDIA GPU) and Model Armor (GCP) constrain where you can deploy and what you can swap out later.
This lesson is free to read. Its 3 hands-on labs — real code, in a cloud IDE — are part of the GenAI Safety & Evaluation Engineering subscription.
From · cancel anytime · Already a subscriber? Sign in →
More free lessons in GenAI Evaluation, Safety & Governance
- Ch 9Build cost-performance analysis across providers
- Ch 10Detect cost anomalies and spending spikes
- Ch 10Build cost governance dashboard and chargeback
- Ch 12Compare guardrail frameworks: Guardrails AI vs NeMo Guardrails 0.20 vs NemoGuard NIMs vs Google Model ArmorYou are here
- Ch 13Detect PII with Presidio and Google Sensitive Data Protection
- Ch 13Implement reversible PII redaction
- Ch 13Build custom PII recognizers for domain data