Skip to content

AI engineering · 21 July 2026 · 8 min read

Guardrails, not guidelines: how to stop AI coding agents breaking your architecture

Coding agents are brilliant at the task in front of them and blind to the system around it. Here's why they quietly erode your architecture, and the guardrails we use to stop it.

  • AI engineering
  • AI coding agents
  • Architecture
  • Code review
  • For CTOs and tech leads
  • For engineers
In this article
  1. Why do agents drift outside their task?
  2. Isn't a good AGENTS.md or CLAUDE.md file enough?
  3. The tool that died of growth
  4. Seven guardrails we use instead
  5. What does this mean for your business?
  6. What should your team do first?
  7. FAQ

The short answer: coding agents optimise for the task they've been given, not for the system it sits in. Ask one to fix a bug and it will fix the bug, and possibly also "tidy up" a neighbouring module, add a shortcut dependency that your architecture forbids, and reformat a shared file on the way out. None of that is malice. The agent simply can't see rules that only live in people's heads or in a README. The fix isn't to use agents less. It's to turn your architecture into something a machine can check, and to check it every time an agent finishes a piece of work.

We build almost everything at Daedalus with coding agents now. They're extraordinary. They're also the keenest, least supervised new joiners you'll ever hire. Here's what we learned the hard way, and what we do about it.

Why do agents drift outside their task?

Because nothing stops them. A human engineer who's been on a codebase for a year knows that the billing module doesn't talk to the reporting database directly, and that the shared config file is not to be touched on a Friday. An agent knows what's in its context window and what its instructions say.

So it does what any keen new joiner with no supervision would do. It solves the problem in front of it by the shortest route available. If the shortest route goes through a layer it shouldn't touch, it goes through that layer. If it spots something nearby that looks wrong, it fixes that too, helpfully.

Each individual change looks reasonable in a diff. The damage is cumulative: a dependency here, a shortcut there, and six months later nobody can change anything without breaking three other things. Agents just get you there faster, because they write code faster.

Isn't a good AGENTS.md or CLAUDE.md file enough?

No, and we say that as people who've written some very long instructions files.

Guidance in prose is a suggestion. Agents follow it most of the time, which sounds fine until you remember they're making hundreds of changes a day. "Most of the time" at that volume means a steady trickle of violations, each of which someone has to spot in review.

Instructions still matter. They tell an agent what good looks like. But anything that genuinely must hold should be enforced by something that can say no.

The tool that died of growth

We'd love to say we worked all this out from first principles. We didn't.

We once built an internal developer tool almost entirely with agents. Within weeks it had grown far beyond what the problem needed. It worked, in the sense that it did things. But it collapsed under its own weight, and we replaced it with a rewrite.

Our own postmortem put it in one sentence: machinery was built ahead of its callers, and the machinery for proving the tool worked grew faster than the tool itself. Agents had happily built elaborate safeguards around reading local files (which harms nothing), interfaces nobody called, and two separate storage layers before anything was slow enough to need a second one. Every change had to update code, documentation, contracts and tests together, so every change got more expensive.

The lesson we took from it: when agents make building cheap, deciding what not to build becomes the expensive part. That decision has to stay with people, and the system has to make it easy for them to enforce it. The rewrite has one rule above the rest: build a mechanism only when its first real caller arrives.

Seven guardrails we use instead

This is the setup we run today on our own products, including a real-time data platform written in Rust and TypeScript.

1. Write the architecture down as data, not prose

Our repositories declare their structure in a small config file: which groups of packages exist, and which groups each one may depend on. Core packages depend on nothing but core, infrastructure may use core, and applications sit on top. That's it.

Because it's data, a tool can check it. Because it's short, a person can read it in a minute and argue about it in a pull request, which is exactly where architecture arguments belong.

2. Let agents ask before they act

We built a small internal tool that knows the shape of each project: its packages, what each depends on, and the rules they keep. Agents talk to it over MCP (the standard way coding agents call tools), so before adding a dependency they can ask "may this package depend on that one?" and get a straight answer.

It sounds trivial. It removes a whole category of mistakes, because the agent finds out before writing the code rather than after.

3. Send the agent back when it breaks a rule

When an agent starts a turn, we record which violations already exist. When it tries to stop, we check again. If it introduced anything new, a hook sends it back with the exact problem, once, to fix its own mess.

Two details make this work in practice. First, it only counts what the agent added, so years of existing technical debt don't block every task. Second, it says why: "package A now depends on package B, which its group may not use" is something an agent can fix in seconds.

4. Fence the work

Each agent works in its own git worktree, a separate checkout of the repository, with a fence around the part it's allowed to change: some paths, some packages, a folder where it may add new files. Edits outside the fence are refused as they happen. When the work comes back, we check the net change against the fence again, from a record the agent can't edit.

This is what stops the helpful tidying. An agent asked to fix one module can't "improve" three others, because it can't save them.

5. Unknown is never yes

If the tooling can't tell whether a change is inside the rules, it says "unknown, and here's why", and an unknown is treated as a no at the point of merging. This is the opposite of how a lot of tooling behaves, and it's the single principle we'd keep if we had to throw everything else away. A guardrail that guesses is worse than none, because people start trusting it.

6. Small briefs, with a budget

Every piece of work starts as a short brief: the goal, the files, a rough budget of lines, and an explicit instruction to delete whatever the new code replaces. The budget isn't there to be hit exactly. It's there so that a 50-line fix that comes back at 2,000 lines is obviously a conversation, not a merge.

7. Review by a different model

The model that wrote the code never reviews it. Reviews run read-only on a frozen copy of the code, by a different model, often from a different AI provider, told exactly which rules to check against. Different models have different blind spots, which is precisely the point. Serious findings get fixed. Everything else is written down in one line or dropped, so review never turns into an endless loop.

What does this mean for your business?

AI coding agents promise speed, and they deliver it, at first. Without guardrails, the bill arrives later: a product that gets slower and more expensive to change every month, until a feature that used to take a week takes a month and nobody can quite say why.

So if you're paying for software built with AI, whether by your own team or a partner, it's worth asking one question: how do you stop the agents breaking the structure of the system? "We review everything carefully" isn't a great answer at the speed agents work. "Our rules are checked automatically every time an agent finishes" is. A codebase that stays easy to change is an asset, and it's one of the first things a technical due diligence will look at.

What should your team do first?

You don't need our tooling to get most of the benefit. You need the habits behind it:

  • Pick the five rules that must never break and turn them into automated checks: dependency rules, forbidden imports, a lint that fails the build.

  • Give each agent its own checkout and a clear scope, rather than letting several share one working copy.

  • Check at the end of every agent turn, not just in CI an hour later, so the agent that made the mess is still around to clean it up.

  • Make reviews independent, ideally a different model, and never the one that wrote the code.

  • Watch the size of changes. If agents are producing far more code than the problem needs, the problem isn't the agents. It's that nobody is deciding what not to build.

FAQ

Do we need to build custom tooling to do this? No. Dependency rules can be enforced with linters and build tools most teams already have, and both Claude Code and Codex support hooks that run checks before and after an agent acts. Custom tooling helps at scale, but the habits matter more than the tools.

Doesn't all this slow the agents down? A little, per task. Overall, it's much faster, because you stop spending your week finding and unpicking changes nobody asked for.

Will this work with Claude Code and Codex? Yes. We use both, and the same rules apply to each, because the checks look at what changed, not at which agent changed it.

What's the first step? Write your architecture down in a form a machine can check, then add one check at the end of every agent session. Everything else builds on that.


We embed engineers who help teams adopt agent-driven engineering without losing control of their codebase. If that sounds useful, we're happy to talk.

All articles

Read something that sounds like your problem?

A free 15-minute intro with our CEO. Bring the article, and he’ll tell you which service fits, if any. If a spreadsheet and two rules would do the job, we’ll say so.