Guardrails
Programmatic checks that validate what goes into and comes out of an LLM, blocking or rewriting unsafe content before it reaches the model or the user. They enforce rules the model cannot be trusted to follow on its own.
What it means
Guardrails are the validation layer that wraps an LLM call. Input guardrails inspect the prompt before it reaches the model - screening for prompt-injection, personally identifiable information, off-topic requests, or banned keywords. Output guardrails inspect the response before it reaches the user - catching hallucinations, toxic language, leaked secrets, malformed JSON, or answers that stray outside an allowed policy.
When a check fails, the guardrail can block the request, redact the offending span, retry with a corrected prompt, or fall back to a safe default. The key idea is that these are deterministic, testable rules running outside the model, so their behavior does not depend on the model choosing to comply. Some checks are simple regex or classifiers; others use a second LLM as a judge.
Why it matters
An LLM is probabilistic, which means it will eventually produce something you do not want it to. Guardrails turn “the model usually behaves” into an enforceable contract. For anything customer-facing or regulated, they are the difference between a demo and a shippable system - they cap the worst-case output, create an audit trail of what was blocked and why, and let you enforce policy without retraining. Because prompt injection has no complete fix, guardrails are a core part of defending against it rather than a nice-to-have.
In practice
Guardrails usually live at the gateway or proxy layer so every call passes through them. Portkey provides a library of input and output guardrails you attach to requests through its gateway, and Galileo runs protection checks for hallucination, injection, and unsafe content in real time. Pair guardrails with observability so every block is logged and reviewable - a guardrail you cannot inspect is a guardrail you cannot tune. Start with the highest-risk failure for your use case, add one check, and measure its false-positive rate before layering more. The best LLM guardrails tools roundup covers the tradeoffs.
Related Terms
Learn More
Free Newsletter
Get the LLM Evals Newsletter
Platform comparisons, pricing changes and eval technique deep-dives. No spam.
Portkey
Galileo