A language model is probabilistic. It usually delivers what you expect, but not always. Guardrails are the layers between user, model and systems that ensure the unexpected does not pass through unfiltered.
Input controls
Before the model: detecting whether a request is within the intended scope, detecting and if necessary masking personal data, limiting length and format, catching obvious abuse patterns. Input controls reduce cost and risk but do not reliably prevent prompt injection.
Output controls
After the model: validate structured outputs against a schema instead of parsing free text. For answers based on documents, check whether statements are supported by the retrieved sources, and show the sources — the most effective measure against hallucinations in RAG systems. Check content for prohibited categories, confidential data or suspicious links. On failure, do not silently deliver a bad answer but fall back cleanly.
Action controls
Once a model acts through tool calling, guardrails become permission questions: which tools are available, with which parameters, for which user and tenant? Consequential actions need confirmation. These controls belong in server-side code, not in the prompt, because a prompt can be talked round and code cannot.
What guardrails cost
Every additional check costs latency and often extra model calls. Too many filters make a product slow and frustrating because legitimate requests get rejected. Good guardrails are therefore targeted: they sit where an error would be expensive and are tested with real examples against false refusals. Ongoing evaluation measures both: errors prevented and unnecessary blocks.
Common misconceptions
First, that a strict system prompt is a guardrail — it is a request, not a control. Second, that a second model as checker solves all problems; it has the same weaknesses. Third, that guardrails are built once; they must evolve with model changes and new abuse patterns. In regulated settings, guardrails should also be documented, because they form part of human oversight and transparency.
