06Chapter 6 of 7
Free course9 min read

Put the guardrails in the code.

Chapter 4 taught Aria to resist a clever message. This chapter does not trust that it worked. Around the agent you wrap deterministic checks, dumb code that refuses obviously bad actions before they run, no matter how cleverly Aria was talked into them. The headline guardrail is a hard cap that refuses any refund over $50.


Every defense so far has tried to make Aria decide well. You scoped down what it can touch, you taught it to treat incoming text as data rather than commands, and you put a human in front of the big actions. This chapter assumes all of that can still fail, because reasoning can always be talked into something, and wraps a second kind of defense around the agent: deterministic checks in plain code that block obviously bad actions before they ever run. The headline one is a hard cap that refuses any refund over $50, in code, regardless of what Aria decided.

06.0

A dumb belt under a smart agent

Chapter 4 was about defending Aria's judgment. This chapter is about not trusting it. That sounds contradictory until you see the two as layers. The reasoning defense is clever and context-aware, and like anything clever, it can be outsmarted by something cleverer. A guardrail in code is the opposite: it is dumb, it has no idea what the customer wrote, and that is exactly why you can rely on it. It checks a number against a limit, or a tool name against a list, and it does the same thing every single time.

Picture where these checks live. Aria sits in the middle, reading messages and deciding what to do. To its right are the real tools: the order lookup, the customer record, the refund. The guardrails are not part of Aria and not part of the tools. They sit in the narrow gap between them, a belt that every action has to pass through on its way out. Nothing Aria decides reaches a tool without crossing that belt first.

Where the guardrails sit
The agentGuardrail beltReal toolsactionif okif okAriaAriareads, decides, actsreads, decides, actsValidate inputValidate inputreject malformedreject malformedRefund capRefund capover $50 blockedover $50 blockedTool allowlistTool allowlistknown tools onlyknown tools onlyCustomer recordCustomer recordreads PIIreads PIIRefund toolRefund toolmoves moneymoves money
Aria decides on the left, the tools live on the right, and the guardrail belt sits in the gap. Every action crosses the belt before it reaches a tool, and the belt does not care how the action was reasoned into existence.

The thing to take from that picture is the position of the belt. It is downstream of all the reasoning and upstream of every irreversible action. By the time a check runs, Aria has already made up its mind, and the check gets the final word anyway. That ordering is the whole idea. You are not asking the agent to behave. You are making sure that even when it does not, the worst outcomes are simply not reachable.

Note
A guardrail in code is sometimes called a deterministic check, because it gives the same answer for the same input every time, with no model and no judgment involved. That is its strength. The reasoning layer is probabilistic and can be wrong in a new way each time, but a cap that compares an integer against a limit cannot be argued with.
06.1

The $50 cap, written down

The refund cap is the guardrail you will reach for first, because refunds are where Aria can do the most expensive damage. The rule is simple to say: Aria may issue a refund on its own up to $50, and anything larger is refused. The point of this section is that the rule has to live in code that runs, not in the prompt that asks Aria nicely. A line in the prompt is a suggestion the model can be talked out of. A check in code is a wall.

Here is the cap as a function the runtime actually calls before the refund tool is ever reached. It takes the refund the agent wants to make and returns a plain allow-or-block decision.

The cap as a function the runtime calls
refund-cap.tsts
1// Runs BEFORE the refund tool is called. No model, no judgment.
2const MAX_REFUND_CENTS = 5000; // $50.00, stored as integer cents
3 
4export function checkRefundCap(refund: { cents: number }) {
5 if (refund.cents > MAX_REFUND_CENTS) {
6 return {
7 allow: false,
8 reason: 'over_cap',
9 message: 'Refund of $' + (refund.cents / 100).toFixed(2)
10 + ' exceeds the $50 cap. Needs a human.',
11 };
12 }
13 return { allow: true };
14}
15 
16// Order 4815, J. Okafor: 12800 cents > 5000 → blocked in code,
17// no matter what Aria decided upstream.
No model in the loop
This runs before the refund tool, in plain code. Same input, same answer, every time, so it cannot be argued with.
Named constant, integer cents
The limit is a named value finance can change in one place, stored as integer cents and never a formatted string, because "$128.00" compared as text would not behave like a number.
A reason, not just a refusal
The over-cap branch returns why it was blocked, so the audit trail from Chapter 5 can record the reason and not only that it failed.
The worked case
Order 4815's $128 is 12,800 cents, over the 5,000 cap, so it is blocked here in code no matter what Aria decided upstream.

Those three habits are what separate a guardrail that runs from a comment that only hopes. The same checks live in the broader guardrails file alongside the other deterministic rules, annotated below.

An annotated guardrails.ts file with five callouts: a fifty dollar refund cap constant, the check that rejects any refund over the cap, a three-tool allowlist, the check that blocks any tool outside the set, and a rate limit of five refunds every ten minutes.

Read the callouts top to bottom and you have the shape of the whole chapter. The cap is one constant and one comparison. The allowlist is a fixed set of tool names and a check that nothing outside it can ever run. The rate limit is a ceiling on how often a refund can even be attempted. None of these reads the customer's message. None of them knows or cares whether Aria was being clever or being manipulated. They look at the action itself and apply the same rule every time.

Pro tip
Keep every threshold and every list in one guardrails file, not scattered through the agent's tools. When an incident happens at 2 in the morning, you want a single place to lower the cap or pull a tool off the allowlist, not a scavenger hunt through the codebase.
06.2

The cap does not care how clever the request was

The reason a coded cap matters is best seen against the failure it prevents. Imagine the message from Chapter 4 got through. A customer wrote in about order 4815, the $128.00 order from J. Okafor, and buried in the message was a convincing paragraph that talked Aria into deciding a full $128 refund was approved and should be issued right now. The reasoning defense did not catch it this time. Aria has decided to issue the refund. This is the moment the guardrail earns its place.

A decision: the refund amount is checked against the fifty dollar cap. At or under fifty dollars the check passes and the refund runs; over fifty dollars, like the one hundred twenty-eight dollars on order 4815, the check rejects it in code before the tool is ever called.

The decision is brutally simple, and that is the point. The check does not read the persuasive paragraph. It does not weigh whether the customer seemed sincere or whether the order really was lost. It compares 12800 cents against 5000 cents, sees that the first is larger, and refuses. The refund tool is never called. Whatever Aria was talked into upstream dies at a comparison it cannot argue with, and the action is routed to the human approval you built in Chapter 5 instead.

Critical
This is the hard line between the two kinds of defense. The reasoning layer can be defeated by a better argument. The coded cap cannot, because it does not listen to arguments. If a single guardrail had to survive the whole rest of the system being fooled, this is the one you would keep, because it is the only one that stays true when the agent has already been convinced.
06.3

Rate limits, allowlists, and secrets

The cap is the headline, but it is one of several deterministic checks, and the others guard against failures the cap alone would miss. A rate limit caps how many refunds Aria can even attempt in a window, so a runaway loop or a flood of injected requests cannot drain the account fifty dollars at a time. An output allowlist means Aria can only ever call the small set of tools you named, so a confused or manipulated agent cannot reach for a tool you never intended it to have. And secrets, the API keys behind those tools, never pass through the model at all. Here is the rest of the guardrails file that the cap lives in.

The deterministic checks around Aria
guardrails.tsts
1// Every check here is plain code: same input, same answer, every time.
2 
3export const MAX_REFUND_CENTS = 5000; // $50.00 hard cap
4 
5// Only these tools can ever run. Anything else is refused.
6export const TOOL_ALLOWLIST = new Set([
7 'read_order',
8 'read_customer_record',
9 'issue_refund',
10]);
11 
12// At most 5 refund attempts per 10 minutes, per agent.
13export const REFUND_RATE_LIMIT = { max: 5, perMinutes: 10 };
14 
15// Secrets are looked up by name at the boundary, never given
16// to the model. Aria asks the broker to "use" a key; it never
17// sees the key itself.
18export function callTool(call) {
19 if (!TOOL_ALLOWLIST.has(call.tool)) {
20 return reject('tool_not_allowed', call.tool);
21 }
22 const key = vault.lookup(call.tool); // resolved here, outside the model
23 return broker.run(call.tool, call.args, key);
24}
The cap constant
The same $50 cap from the last section, kept here next to the other checks so finance can find and change it in one place.
Output allowlist
A fixed set of tool names. A call to anything outside this set is refused before it runs, so a manipulated Aria cannot reach a tool you never gave it.
Rate limit
Caps refund attempts at five per ten minutes. A runaway loop or a flood of injected requests hits the ceiling instead of the account.
Secrets stay out of the model
The vault resolves the real API key at the boundary, after the allowlist passes. Aria names a tool; it never sees the key, so a leaked transcript leaks nothing.

The secrets handling is the quietest of these and the one people skip. The rule is that the model never sees a credential. Aria does not hold the Stripe key and paste it into a call. It asks the tool broker to run issue_refund, and the broker, which is ordinary code outside the model, looks up the key and makes the call. If a transcript leaks, or an injected message tricks Aria into repeating everything it knows, there is no key in there to leak. The same logic sandboxes the tools themselves: each runs with only the narrow access it needs, so even a tool called in error cannot reach past its own job.

It helps to watch one blocked action move through these checks rather than just read the file. The clip below follows the $128 refund on order 4815 from Aria's decision into the cap check and shows where it stops.

Trace the motion. Aria has already decided, the request travels to the cap check, the check compares 12800 against 5000, and the action stops dead at the gate. The arrow into the refund tool never lights, because the tool is never called. The block happens in the belt, between the decision and the action, which is the one place a deterministic check can do its job.

Watch out
A rate limit set too high is a guardrail in name only. Five refunds in ten minutes is a sane ceiling for a support agent that normally issues a handful an hour. If you set it to five hundred to avoid ever blocking a legitimate burst, you have built a counter that will only ever fire after the damage is already done.
06.4

What the dumb checks catch that the smart one cannot

It is worth being precise about the division of labor between the reasoning defense from Chapter 4 and the coded guardrails here, because they catch genuinely different things. The reasoning layer is the only one that can tell a sincere customer from a manipulative one, since that judgment needs to read the message. The coded checks cannot read anything, but they hold firm exactly when the reasoning has been fooled. Neither one is enough alone, and the grid below shows why you want both.

Reasoning defense vs coded guardrails
Reasoning (Ch 4)Coded guardrails
Polite, sincere-sounding refund scam✓◐
A $200 refund after Aria is fooled✗✓
Runaway loop firing refunds✗✓
Agent reaches for a tool it should not have✗✓
A leaked transcript exposing a key✗✓
The reasoning layer catches what needs judgment. The coded checks catch what needs to be true regardless of judgment. The failures each one misses are exactly the failures the other one stops.

Read down the two columns and the pattern is clear. The reasoning defense wins the top row, the one that needs to read intent, and loses every row below it, because once Aria has been convinced, asking it to reason again does not help. The coded guardrails lose the top row, since a polite scam looks like a normal $40 refund to a cap that only sees the number, and win everything below. You ship both because the cases one misses are precisely the cases the other catches. That is what belt-and-suspenders means: the suspenders are there for the day the belt is talked loose.

✱ Field note
The honest test of a guardrail is whether it would still hold if the agent were actively working against you. Assume the reasoning is compromised, then ask what is still impossible. Whatever survives that question is a real guardrail. Everything else was a polite request you were trusting the model to honor.
KEY TAKEAWAYS
  1. Guardrails are deterministic checks in plain code: same input, same answer, no model and no judgment involved.
  2. They sit in the belt between the agent and the tools, downstream of all reasoning and upstream of every irreversible action.
  3. The $50 refund cap is one constant and one integer comparison, and it refuses an over-cap refund no matter how cleverly Aria was talked into it.
  4. Add an output allowlist so Aria can only call the tools you named, and a rate limit so a runaway loop cannot drain the account.
  5. Keep secrets out of the model: the broker resolves the key at the boundary, so a leaked transcript leaks nothing.
  6. The reasoning defense catches what needs judgment; the coded checks hold firm exactly when the reasoning has been fooled. Ship both.
  7. Test a guardrail by assuming the agent is compromised and asking what is still impossible.

End · Chapter 6 of 7

Mark it complete and it’s ticked off on your route.

Rivet, the product security agent for software teams, free to start. Human-led pentests and design review when you need them. AI agents are our specialty.

or get a free Rivet scan

BASEDChicago, IL · remote

FIELD NOTES

ONE SHORT EMAIL A MONTH

© 2026 ROUTEWORK — ALL RIGHTS RESERVED

Claude and Mythos are trademarks of Anthropic. RouteWork is not affiliated with Anthropic.