What are guardrails in LLM apps?
Guardrails are the filtering and validation layers wrapped around a language model in production: checks that run on a request before it reaches the model, and checks that run on the response before it reaches the user. They catch what the model's training doesn't reliably catch, and you can change them without retraining or redeploying the model.
Where guardrails sit
An LLM app is usually more than the model. A request comes in, passes through some input handling, reaches the model, and the model's output passes through some output handling before it's returned. Guardrails live in those handling stages, not in the model's weights. A guardrail is application logic you can update, swap or turn off in an afternoon; retraining a model to change its behavior is a much bigger job. Guardrails also work the same whichever model sits behind them, which helps if you route requests across models by cost or capability.
What input-side guardrails do
On the way in, guardrails typically check for jailbreak attempts (prompts trying to override the system prompt or extract hidden instructions), prompt injection embedded in retrieved documents or tool outputs, and requests that fall outside the app's intended scope. Some also validate structure: rejecting a request that's missing a required field before it burns a model call at all.
What output-side guardrails do
On the way out, common checks include content moderation (blocking hate speech, self-harm content, or other categories the app shouldn't produce), PII redaction (scrubbing names, emails, or account numbers a model might have echoed from context), and schema validation (rejecting or repairing a response that was supposed to be valid JSON and isn't). Some setups also run a second, cheaper model as a judge over the first model's output, catching factual or tonal problems a rules-based filter would miss.
Why this is separate from model training
A model's safety tuning shapes what it's inclined to say, but it isn't a hard boundary. Models can be prompted around their training, they can make mistakes under ambiguous instructions, and a fine-tune done for one purpose can loosen behavior meant to hold for another. Guardrails give an operator a deterministic, auditable layer that doesn't depend on the model behaving as trained every time. That matters more when the app is self-hosted: the operator owns the failure and can't point at a vendor's usage policy.
Cost of getting this wrong
Guardrails that are too loose let bad output through; guardrails that are too strict block legitimate requests and frustrate users. Every check also adds latency, especially on the input side, which runs before the model sees the request.
That latency comes out of the same budget as time to first token: a heavyweight input classifier ahead of the model adds directly to the wait before generation starts. Benchmark guardrails with your own request patterns instead of trusting defaults. The benchmarks page covers the baseline latency on DGX Spark hardware that guardrail overhead adds to.