InterviewHubPRO
Section Overview
Q38

Question 38 of 50

Part 4: LLM Security, Safety & OWASP Top 10 for LLMs

76%
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

FrameworkCore MechanismStrengthsTrade-Off
NeMo Guardrails (NVIDIA)Colang language + state machine modelingDialog flow control, topical steering, programmable rulesLearning curve for Colang DSL
Llama Guard (Meta)Fine-tuned classifier model on safety taxonomyStandardized safety classification across 14 risk categoriesAdds ~50–100ms extra model inference latency
Guardrails AIPydantic-like RAIL XML/JSON validatorsStructured output validation and correctionFocused 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