Skip to content
James Kirkman , home

Decision · 2026

Learning the hard way: an agentic workflow is only as good as its guardrails

Adopted At work

The mistakes agents make, the guardrails that catch them, and when to take one out.

When you first dive into agentic engineering, the buzzwords can make your head spin. At the center of it all is the harness, the code around the model that gives it tools, context, and a loop to work in. It’s where your genius robot toddler lives. Left unchecked, it will make mistakes, and you learn quickly that half the job is reining it in. These are mistakes I’ve run into myself:

  • Tunnel vision. It fixates on the problem in front of it and loses the bigger picture.
  • Overreach. It jumps ahead to the next step without being asked, which makes the tunnel vision worse.
  • Agreeableness. Models lean toward agreeing with you unless you tell them to push back.
  • Half-answering. The final output doesn’t fully address what you asked for.
  • Grading its own homework. Its tests share its assumptions, so everything passes and the bug ships.
  • Moving the goalposts. When a test fails, it may loosen the test until it passes.
  • Collateral damage. It takes the shortest path to its goal, even when that path runs through someone else’s work.
  • Memory slips. As a long conversation gets compacted again and again, important context falls out.
  • Hallucination. It fills gaps with confident inventions, most often when the facts it needs are missing or buried in a crowded context.
  • Leaking sensitive data. It will copy personal data or secrets into a log, a commit, or a reply without a second thought.

So how do you rein it in? What counts as a guardrail, and where do you actually need one? The obvious answers are prompt injection and data leaks. In my experience, guardrails belong at every step of the workflow, including outside the harness, and they should come out when the evidence warrants it.

How I learned it the hard way

The lesson came early in building CCE-SRE-Expert, my team’s production Slack agent at Nike. The bot kept telling people to post in the team’s support channel while it was already in that channel. Left alone, it could bounce people in a loop. The bot answers in the channel, tells them to post in the channel, and answers again.

I tried fixing it in the prompt four times, including a phrase blacklist, a categorical rule, and a stronger rule that held even when a cited source said otherwise. Then it did it again, with every one of those instructions in the prompt. That’s when I accepted that a prompt is only a strong suggestion.

The rule wasn’t under-specified. The model’s own probabilities still put weight on “here’s a channel that handles this,” and no wording reliably drives that to zero.

So I stopped rewriting the prompt. The harness already knows which channel the bot is in before the model writes a word. A check now reads each answer before it posts, and if the answer sends people back to the channel they’re already in, the bot tries again.

Guardrails vs. gates

A guardrail is any rule an agent has to follow. Written in a prompt, it’s a request. A gate is a guardrail enforced in code. The work has to pass it to move on, and the model can’t talk its way past it.

Not every guardrail should be a gate. After the channel loop, I went through every rule in the bot’s prompt and sorted them. Rules that need judgment, like “cite a source or stay silent,” stayed in the prompt. Rules a program can check, like covering every incident in a thread or formatting for Slack, became checks on the answer. Rules about the order of steps, like “ticket first” and “confirm before writing,” moved into the harness, which won’t run a step until the one before it is done.

The rule I settled on is simple. A guardrail becomes a gate once a program can check it and it has failed in the prompt more than once. My game’s tooling uses the same rule, and about 30 of its 78 gates block in code today.

Kinds of gates

Since then I’ve built gates at every layer of my projects. They differ in where they sit and what they can stop.

  • Answer checks run in the agent’s harness after the model writes and before anything posts. The fix for the channel loop is one. When an answer breaks a rule, the harness retries.
  • Tool hooks in my production agent check each tool call before it runs, and can refuse it.
  • Order-of-action gates live in the harness’s state machine. A step can’t run until the step before it is done, which is how “ticket first” and “confirm before writing” hold every time.
  • Hooks in the coding agent fire inside a Claude Code session, before a tool call runs or when a prompt is submitted. In my Unreal game, one agent tried to stop its own test run by killing every Unreal process on the machine. That time it hit nothing, but it could have taken down another agent’s run. A hook now catches any command that kills the game or Unreal by name. An agent is refused, and in my own session it asks me first.
  • Repo hooks check every change before it leaves the machine, whoever wrote it. My team’s knowledge repo scans every push for sensitive data, and blocks significant changes that have no decision record. The game’s hook catches dead links and paths that only work on one machine before a document is pushed. A repo hook has to fail closed. Ours once skipped its checks silently inside a sandboxed agent shell, and now a test proves it can’t.
  • Workflow refusals are built into the game’s own tooling. It won’t start a new round of work until the last one has its optimization report, journal entry, handoff, and an architecture review that ends in an agreed plan. Its newer refusals also say why they fired, how to fix the problem, and who may override them, which is only me.
  • Verify gates are the tests and playtests that must pass before work merges. The game’s verify also fails when it finds that an agent’s change loosened a test, unless I’ve approved the loosening in writing.
  • People are the last gate. My production agent’s writes land as draft pull requests, and a person merges them.

An answer check sees the whole answer, but only after the model has written it. A tool hook stops an action before it happens. A repo hook doesn’t care whether a person or an agent made the change. A person is the most expensive gate, so I keep people in the loop for the changes that matter.

When a guardrail should come out

Guardrails aren’t free. Each one costs time, and one that raises false alarms blocks good work. So a guardrail comes out, or drops to a warning, when the evidence warrants it.

My production agent reviews change requests before an engineer approves them. Some of its checks had it recommending a block on critical changes over nitpicks, so I took those checks out.

In my game, every round ends with an audit of its gates. It records which rules held in code, which were followed or missed and what each miss cost, and how often each gate fired, so the ones that never fire can be retired. A new watcher raised three false alarms in its first run, so the hook that would enforce it stays off until the watcher can be trusted. Another gate blocked my prompt because the session was a day old, though it had used only about an eighth of its context. Age was the wrong measure. Now that gate only warns, and only at the end of a round or once the context grows large.