Guide

Guardrails: how to stop an AI agent from doing something stupid in production

An LLM hallucinates, obeys whoever manipulates it, and gets things wrong with confidence. The practical guide to the guardrails that separate a safe agent from an accident waiting to happen.

Sep 2, 2026·11 min read·.md

A language model has three flaws you can't ignore once it becomes an agent that acts in the real world: it hallucinates (invents things with confidence), it obeys (it can be manipulated into doing what it shouldn't), and it has no sense of consequence (to it, sending a PIX and sending a "good morning" are the same text operation).

While the agent only talks, that's annoying. When it executes — pays, cancels, deletes, unblocks — it's dangerous. Guardrails are the locks that guarantee that even when the model gets it wrong, it doesn't do damage. This is the practical guide from someone who runs agents in production.

The rule that governs everything: the model is not the authority

If you take a single sentence away from this text, take this one: the LLM decides what to do; your code is what executes, validates, and permits. I already wrote this in the function calling guide, and it comes back here as the foundation of all agent security.

The classic mistake is trusting the model to behave because you "asked nicely in the prompt." The prompt guides; it doesn't guarantee. The real lock is deterministic and lives outside the model — in the layer that receives its decision and chooses whether to obey. The model proposes; your code disposes.

With that principle in place, guardrails organize into layers.

1. Input guardrail

Before the message reaches the model:

2. Tool guardrail (the most critical)

This is where the damage happens, so this is where the lock has to be hardest. Every action that changes state in the real world goes through validation before it runs:

The golden rule: every tool that changes the real world needs validation, confirmation (when irreversible), and logging. The LLM can hallucinate; the tool layer can't.

3. Output guardrail

Before the response reaches the customer:

4. Operational guardrail

What runs the whole time, underneath:

The balance: too many locks break the product too

Excessive guardrails turn into an agent that refuses everything, asks for confirmation just to breathe, and frustrates the customer — and then nobody uses it, and a product nobody uses protects nothing. The art is to calibrate by the risk of the action: answering "what's my invoice?" is low risk, let it through; "cancel my plan" is irreversible, confirm it. Lock down hard where the damage is big; let it flow where it isn't.

This ties directly into my thesis on a product that's live: security that stops the product from existing isn't security, it's paralysis. The goal is an agent that can take the real world — including bad-faith users — without ceasing to be useful to the good ones.

The honest summary

An AI agent in production is trustworthy not because the model is smart, but because the architecture around it doesn't blindly trust it. The model proposes; the code validates, authorizes, confirms, and logs. The prompt guides; the code guarantees. Lock down in layers — input, tool, output, operation — and calibrate by the risk of each action.

Whoever skips this ships a demo that dazzles and an agent that, on the first clever user or the first expensive hallucination, becomes bad news. A guardrail isn't what blocks the product — it's what lets it go to production safely.


I build AI agents that act in production with the locks the real world demands — validation, confirmation, observability. If you're about to put an agent out there to actually execute, let's talk.

Frequently asked questions

What are guardrails in an AI agent?

They're the locks and validations that limit what the agent can say and do — checking the input, restricting the output, validating every tool call, requiring confirmation on irreversible actions, and enforcing scope limits. The goal is to guarantee that even when the model gets it wrong or is manipulated, it can't cause harm.

Why does an LLM need guardrails?

Because an LLM hallucinates (invents data with confidence), can be manipulated through prompt injection, and has no native sense of consequence. Without locks, an agent that takes real-world actions (pay, cancel, delete) can act on a hallucination. Guardrails live in your code layer, not in the model.

Do guardrails go in the prompt or in the code?

In both, but the lock that matters is in the code. Instructions in the prompt help the model behave, but they can be worked around through manipulation. Deterministic validation — in your code, before any action runs — is the one that can't be 'talked' into giving in. The prompt guides; the code guarantees.

LS
Written by Lucas Silva
I build AI products that ship — from diagnosis to production.
GuardrailsSecurityAI AgentsLLMProductionPrompt Injection

Got a business problem to solve with AI?

Tell me the problem and I'll hand you a product that actually runs.

Get in touch

Keep reading

Guide

MCP (Model Context Protocol): what it is and why it matters for AI agents

The no-nonsense guide to the Model Context Protocol: what it solves, when to use it, and why it became the 'USB-C' that connects AI agents to your business tools.

Case study

Nine founders, three days, nine projects live

I mentored at Paris Group's Founders AI immersion in Chapecó, Brazil. I walked nine business owners from a real bottleneck to a working product — and presented ConectaAI with a live phone call answered by AI. What makes an immersion actually ship.