AI Engineering & LLMs (50 Qs)•Part 4: LLM Security, Safety & OWASP Top 10 for LLMs
Guardrails Architecture: NeMo Guardrails, Llama Guard & Programmable Safety Rails
1. The Programmable Safety Layer
Modern enterprise systems do not connect user requests directly to LLMs. They place a Guardrails Engine as an intelligent proxy between users, models, and tools:
css
User Input ──► [ Input Rails ] ──► [ Main LLM Model ] ──► [ Output Rails ] ──► Safe Response
│ │
▼ ▼
• Block Toxic Prompts • Hallucination Check
• PII Masking • PII Leak Check
• Off-Topic Redirect • Brand & Tone Check
2. Guardrails Architecture Comparison
| Framework | Core Mechanism | Strengths | Trade-Off |
|---|---|---|---|
| NeMo Guardrails (NVIDIA) | Colang language + state machine modeling | Dialog flow control, topical steering, programmable rules | Learning curve for Colang DSL |
| Llama Guard (Meta) | Fine-tuned classifier model on safety taxonomy | Standardized safety classification across 14 risk categories | Adds ~50–100ms extra model inference latency |
| Guardrails AI | Pydantic-like RAIL XML/JSON validators | Structured output validation and correction | Focused primarily on schemas and regex |
3. Llama Guard 3 Integration Pattern
python
async def check_input_safety(llama_guard_client, user_prompt: str) -> bool:
# Llama Guard evaluates input across: Hate Speech, Self-Harm, Cyberattacks, CBRN
response = await llama_guard_client.chat(
messages=[{"role": "user", "content": user_prompt}]
)
# Returns "safe" or "unsafe
<category_code>"
is_safe = response.strip().startswith("safe")
return is_safe