Skip to content
Apsan Works

AI Agent Guardrails: What Actually Stops Something From Going Wrong

A real guardrail is a specific set of constraints enforced in code, not a polite request in a system prompt, and the two are not interchangeable.

6 min read

Every vendor pitch for an AI agent includes the word guardrails somewhere, usually as a single reassuring line near the end. It rarely says what the guardrail actually is, and that gap is not an accident. A real guardrail is a specific piece of engineering with a specific cost, and a lot of what gets marketed as one is a sentence in a system prompt asking the model to please behave.

Those are not the same thing, and the difference is the whole subject of this article.

The test for a real guardrail

Ask one question about any claimed guardrail: is this enforced by code the agent cannot argue with, or is it a request made to the model in natural language?

A system prompt that says “never delete a customer record without confirmation” is a request. The model reads it, and in the overwhelming majority of cases it complies, because that is what these models are trained to do. But a request is not a constraint. Nothing prevents the model from generating a tool call that violates it, under the right combination of confusing context, adversarial input, or a genuinely ambiguous situation the prompt writer never anticipated. When that happens, there is no second line of defense, because the instruction was the only line.

A real guardrail sits below the model, in the code that actually executes tool calls. The model can propose whatever it wants. The system decides whether to honour it.

The four constraints that actually hold

We touched on these briefly in AI agents vs chatbots, where they show up as the four problems that only exist once a system can act. Here is what each one looks like as code rather than as a concept.

Permission scoping means the agent’s tools are defined narrowly enough that the worst case is bounded before anything runs. An agent that reads customer records should be handed a tool that can only read customer records, not a general database credential it is trusted not to misuse. This is enforced the same way you would scope any service account: at the infrastructure level, with a role that simply cannot perform the forbidden action, not with an instruction telling it not to. An MCP server is one concrete way to build that boundary, where the tool list itself is the set of actions that exist at all.

Approval gates sit in front of anything irreversible. Sending, paying, deleting, publishing, any action with a real-world consequence that cannot be undone, requires either a human click or a confidence threshold high enough that the system is willing to stand behind the decision alone. The gate lives in the code path between the model’s proposed action and the actual API call, so there is no route around it that does not involve changing the software.

Rate and time constraints stop an agent from doing the right thing at the wrong volume or the wrong hour. An outreach agent that is only allowed to send between defined hours, on weekdays, up to a daily cap, will not send outside that window no matter how confident it feels at 3am, because the clock check happens in code before the send call is even attempted. This is the specific mechanism behind the trust section on our homepage: the agent can generate the intent to send at any hour. It cannot generate the send.

Stopping conditions cap the loop itself. Iteration limits, wall-clock timeouts, and hard spend ceilings mean a confused agent eventually halts instead of continuing to act on bad premises indefinitely. Without this, the failure mode is not dramatic, it is expensive: a loop that keeps calling tools based on an increasingly wrong understanding of the situation, racking up cost and side effects the whole time.

Where teams actually get this wrong

The common failure is building the first three constraints and skipping the fourth, or building all four for the obvious dangerous actions while missing the one nobody thought to scope. Skipping guardrails entirely is rare.

The why agents fail in production article covers this from the reliability angle: nobody defined what the agent was not allowed to decide, so it decided anyway, in a case nobody had specifically forbidden because nobody had thought of it. Guardrails written after an incident are a list of things that already went wrong. Guardrails written well are a list of everything the agent’s tools make possible, with a deliberate decision made about each one, before the first real run.

That inventory is tedious and it is also the actual work. A tool that can send an email can also send it to the wrong person, send it too many times, or send it with a subject line pulled from bad extraction. Each of those is a separate thing to decide about, not one blanket “email sending is guarded” checkbox.

Confidence is not a guardrail on its own

A confidence score is genuinely useful, but only as an input to a guardrail, not as the guardrail itself. “The model was 87% confident” is not a decision. What the system does with that number, whether it proceeds automatically, escalates to a person, or refuses outright, is where the actual protection lives, and that logic has to be written down as code with explicit thresholds, not left as a vague sense that high confidence means it is probably fine.

This is also where evaluation and guardrails meet. A threshold is only meaningful if you know what accuracy that confidence level actually correlates with, which is exactly the measurement work covered in how to evaluate an AI agent before you trust it. A guardrail set without that measurement is a number picked because it felt reasonable, not because it was checked against real outcomes.

What this costs, honestly

Guardrails are not free, and pretending otherwise undersells the engineering. Every gate is a place where automation slows down or defers to a human, which is friction by design. The four constraints above take real time to scope properly, and scoping them badly, either too loose or so tight the agent can barely function, is easy to do on a first pass.

The alternative costs more. An agent with no enforced constraints is not actually faster in any way that matters, because the first serious incident erases whatever time it saved and usually a good deal of trust along with it. The honest framing is that guardrails are the cost of being allowed to automate something that matters, and the systems worth building are the ones where that cost was paid deliberately rather than discovered afterward.

We build the guardrails in first, not last. See how we approach agent work, or read the full FAQ on AI, agents, and trust.

Tell us what is slowing you down

A short conversation is usually enough to tell whether this is a build, an automation, or something you should not do at all. We will tell you which.