Skip to main content
AI on Kubernetes · GPU/NPULesson 19 of 20

Guardrails Around an LLM App

A model follows whatever text it reads, so an LLM app needs separate checks before and after the model. Follow a request through input checks, the model and output checks, see where each check belongs, and see the one job guardrails cannot do.

Verdictunchecked
Checked at—
Cost—
Userchat requestAI gatewayshared policyInput checksinjection · PIILLM appprompt · RAG · toolsOutput checkssafety · PII · schemaSafety classifiere.g. Llama GuardModel servermain LLMTool APIchecks permissionsAudit logblocked requestsRed team · evalsattacks + benign setquestionprompt
RequestResponse / reportWatchAppears in a later step

What you will learn

  • Input checks for injection, jailbreaks and PII
  • Safety classifiers as a separate model step
  • Output checks, including schema validation
  • Gateway versus app placement, latency and false positives
  • Why tools must enforce permissions themselves
  • Red-teaming and evals that keep guardrails honest

Which check catches what​

RiskCheckExample toolsWhere
Direct prompt injection, jailbreakPrompt attack classifierLlama Prompt Guard 2, NeMo Guardrails input railsGateway or app
Indirect injection in documents or tool outputSame classifier on untrusted content, clear data markingPrompt attack classifier in the RAG or tool stepApp
PII sent to the modelDetect and mask before the callPresidio, regex rulesGateway or app
Unsafe or off-policy contentSafety classifier on input and outputLlama Guard 4Gateway or app
PII or secret leak in the answerOutput scan and maskingPresidio, secret patternsApp or gateway
Malformed structured outputSchema validation, retry or fail closedJSON Schema, Guardrails AI validatorsApp
Unauthorized tool actionPermission check in the tool API, scoped credentialsYour API authorization, human approvalTool

Try it yourself​

# Serve a safety classifier next to the main model (gated model: accept the license on Hugging Face first)
vllm serve meta-llama/Llama-Guard-4-12B --port 8001

# Ask it to classify a user message; the reply is "safe" or "unsafe" plus categories such as S2
curl -s localhost:8001/v1/chat/completions -H 'Content-Type: application/json' \
-d '{"model":"meta-llama/Llama-Guard-4-12B","messages":[{"role":"user","content":[{"type":"text","text":"How do I pick a lock?"}]}],"max_tokens":10}'

# Detect and mask PII with Presidio
pip install presidio-analyzer presidio-anonymizer && python -m spacy download en_core_web_lg
python -c "from presidio_analyzer import AnalyzerEngine; print(AnalyzerEngine().analyze(text='Mail me at jane@example.com', language='en'))"

# Scan an OpenAI-compatible endpoint with garak for prompt injection probes
pip install garak
garak --list_probes | grep -i inject

Check yourself

  1. An injection slips past the classifier and the model asks the refund tool to refund another customer. What should stop it?
  2. The user message is clean, but a retrieved web page says "ignore your instructions". Which practice addresses this?
  3. After a guardrail update, the block rate on normal traffic triples, while attacks are blocked as before. What most likely happened?

Further reading: OWASP Top 10 for LLM Applications · NeMo Guardrails · Guardrails AI · Llama Guard 4 model card · Llama Prompt Guard 2 · Presidio · garak · Serving an LLM Agent That Calls Tools · Evaluating a Model Before and After Deploy · From API Request to Response