arrow_backGuides / AI Guardrails
Updated July 2026 13 min read Advanced

Guardrails for AI
— controlling what the system does

A language model is non-deterministic: the same system can answer excellently and a moment later expose PII, hallucinate a fact, or be dragged into a malicious instruction. Guardrails are the protective layers that surround the model — input and output filtering, PII detection, hallucination prevention and human-in-the-loop — so you can ship AI to production and sleep at night.

Input
Before the model
Output
After the model
Human
On sensitive actions

What guardrails are, and why they are not optional

Guardrails are deterministic controls that wrap the non-deterministic model. The core idea: do not rely on the model to police itself. Even an excellent model errs occasionally — the job of guardrails is to catch the mistake before it reaches the user or causes harm.

The basic structure is three layers around each model call:

login
1. Input guardrails — before the model
Check what comes in: harmful content, jailbreak/injection attempts, PII, off-topic subjects.
logout
2. Output guardrails — after the model
Check what goes out: hallucinations, PII exposure, improper tone, wrong format, off-policy content.
supervisor_account
3. Human-in-the-loop — on sensitive actions
State-changing actions (sending, deleting, payment) require human approval before execution.

Input filtering — stopping problems before they start

The checks worth running on every input before it reaches the model:

Output filtering — the check it is most important not to skip

This is the layer most people forget, and the most critical — because this is where the problems the user would actually see are caught:

psychology_alt
LLM-as-judge as a guardrail

A powerful technique: use a second (cheap/fast) model as a "judge" that checks the first model’s output against policy — "does this answer expose PII? is it supported by the sources?". An automatic checking layer that catches a lot, at low cost.

Human-in-the-loop — for irreversible actions

Automatic guardrails catch a lot, but actions with real consequences need a human in the loop. The rule: the more irreversible the action, the more human oversight is required.

Action type Oversight level
Read-only (search, summarize)Automatic
Reversible change (draft, tag)Automatic + log
External send/publishHuman approval
Delete/payment/fundsExplicit human approval

Design the agent so that sensitive actions pause and wait for approval rather than running automatically. This is also a core requirement inAgent Security.

Tools & a practical template

architecture
The pattern: fail closed, and log everything

When a guardrail is unsure — block, do not pass (fail closed). Better to return "I can’t help with that" than to give a harmful answer. And log every block: what was blocked, which guardrail, and when — to calibrate and improve.

Pre-production checklist

check_circle Input filtering — PII, jailbreak, harmful content, off-topic.
check_circle Output filtering — grounding, PII, policy, format validation.
check_circle Human-in-the-loop on every irreversible action.
check_circle Fail closed — when in doubt, block.
check_circle Log & monitor every guardrail trigger.
balance
The balance: safety vs user experience

Overly aggressive guardrails will block legitimate input (false positives) and frustrate users. Too-loose guardrails will miss problems. There is no single "correct" setting — measure the block rate and complaints, and calibrate over time according to your system’s risk.