Don't ask the AI to behave. Stop it misbehaving.
In my last post I handed our AI new starter a notebook: a first page of house rules they read every morning, and a stack of pages they look up when the task calls for it. It’s the single biggest improvement you can make to how an agent behaves.
It’s also, fundamentally, a request.
The notebook says “never drop the production database”. It doesn’t stop anyone dropping it. Most of the time the rule is followed. But “most of the time” isn’t a phrase I’m comfortable using about anything that can run commands on my machine, and an agent that’s been nudged by something it read, or has simply lost the thread, will walk straight past a polite note. Tell me you’ve never had a new starter do something you told them not to?
If you want to see how often your AI assistant of choice is ignoring that polite note on the fridge, go ahead and implement the controls below, then count how many times an hour a guard has to step in. You’ll see what I mean.
Asking versus stopping
There’s a line from the UK’s National Cyber Security Centre I keep coming back to. The aim, they say, is to restrict AI using “known controls implemented in rules and code, rather than expecting an AI to limit another AI”.
In other words, don’t ask the model to police itself. Put something in the way. A notebook means “I forgot” is less likely to end up in the incident post-mortem. But what if we simply never gave the new starter the tools to do it in the first place?
That’s possible because the agent never actually does anything itself. It runs inside a harness: the program that carries out its requests on your machine (Claude Code, in my case). Every action the agent wants to take, whether that’s running a command, reading a file or editing one, is a tool call: a request the harness can carry out, or refuse. It’s the equivalent of setting up your new starter’s machine before handing it to them; give them what they need and no more.
A note in the notebook says what you’d like. A control in the harness decides what’s possible. Every guard below is an ordinary program, run before the AI sees or does anything. They’re deterministic. They can be wrong, but they can’t be ignored, forgotten or talked round.
I run three of them, from weakest to strongest.
Guard one: the receptionist
The first guard sits on the way in. Before a prompt I’ve typed is sent anywhere, a small script reads it and refuses it if it plainly belongs somewhere else.
That script is a hook: something the harness runs automatically at a set moment (before a prompt is sent, before a command runs) that can let the moment pass or stop it dead.
- It runs locally, before anything leaves the machine.
- It catches a typed prompt that names something from the wrong side of a boundary.
- It misses everything else: the contents of files, a pasted screenshot, anything the agent reads after the prompt has gone. That’s why it’s the weakest of the three.
It also has an honest flaw. Some of the terms it watches for are ordinary English words, so now and then a perfectly harmless prompt gets refused. I’ve accepted that rather than solved it. A receptionist who occasionally stops the postman is a better trade than one who waves everybody through.
Guard two: the badge reader
The second guard sits in front of every command the agent runs and every file it writes. It doesn’t care what I typed. It cares what the agent is about to do.
- It runs before every shell command and every write.
- It catches commands that reach outside the folder the session belongs in, and wide searches that would sweep across folders they’ve no business in.
- It misses anything that doesn’t go through a tool call.
If the first guard is the receptionist, this one is the badge reader on every door. You got into the building; that doesn’t mean you get into every room.
Guard three: the bricked-up door
The third isn’t a script at all. It’s a line in a settings file that says, in effect, “this folder does not exist as far as you’re concerned”, and the harness enforces it on every read and every edit.
That’s a deny rule, and its shape is about as simple as configuration gets:
{
"permissions": {
"deny": ["Read(<somewhere it shouldn't be>/**)", "Edit(<somewhere it shouldn't be>/**)"]
}
}
There’s no logic to get wrong and no pattern to dodge. A denied path is denied. Better still, in Claude Code’s settings a deny always beats an allow, at every layer, so nothing further down can quietly widen access again.
Why you need all three
If deny rules are that strong, you might reasonably ask why I bother with the weaker two. The answer is that each guard sees something the others can’t:
| Guard | Runs on | Catches | Misses |
|---|---|---|---|
| Receptionist (prompt check) | What I type, before it’s sent | Intent, before anything happens | Files, images, anything read later |
| Badge reader (tool-call check) | Every command and write | Actions that reach too far | Anything that isn’t a tool call |
| Bricked-up door (deny rule) | Every read and edit | Any access to a denied path | Things that aren’t paths at all |
Think of it as Swiss cheese. Every slice has holes; the trick is stacking them so the holes don’t line up.
⚠️ Warning: a control you’ve described but not switched on is worse than an inconvenient one. It gives you the confidence of a guard with none of the protection. If a guard gets in the way of legitimate work, fix the workflow, don’t disarm the guard.
Fail closed
Every one of my guards follows one rule above all others: if it isn’t sure, it blocks. Its configuration is missing? Block. It can’t make sense of what it was given? Block. It doesn’t recognise the account it’s running under? Block.
The alternative, failing open, means allowing things through when the guard itself is broken. That sounds friendlier, and it’s a trap, because a guard that fails open can stop working and nobody notices. It simply looks like a very quiet guard.
I found that out the useful way round. An early version of one of my guards had a bug that swallowed its own input, so it never actually saw what it was meant to be checking. Because it failed closed, everything was blocked, and I knew within seconds. Had it failed open, it would have sat there for weeks looking like a guard that never had anything to report.
⚠️ Warning: a guard that has never blocked anything isn’t proof that nothing bad happened. Check it can block before you trust its silence.
Log the match, not the message
A guard should keep a record of what it stopped, so you can check it’s working. But a guard that recorded the prompts it blocked would be storing exactly the content it exists to keep out.
So mine log the time, the account and which rule matched. Never the text. The logs are for auditing the guard, not for re-reading my conversations. And the guards have their own tests, like any other code, because “it looked right when I wrote it” isn’t a test.
The feedback loop
Early on, these guards were getting hit so often it became an awkward meme that Claude and I shared. I literally have pages of “war stories” that Claude writes up as amusing anecdotes for all the times it trips over one of the guards because, if I don’t laugh at it, I’d be liable to have Claude end the conversation on me for a sustained overabundance of abuse in its direction.
Intellectually, I’m aware Claude isn’t the “he” I often anthropomorphise and get angry at; building these controls is what has kept me sane because once you have these all set up, aligned, tweaked to your preferences, AI stops fighting you and drilling holes through the Swiss cheese, and starts actually working with you. But getting those controls aligned requires a feedback loop.
Sooner or later you’ll need to do something a guard forbids, and usually the thing you need to do is fix the guard. The tempting move is to switch it off “just for a minute”.
The better move is a separate, deliberate way in. I have a second launch command for exactly that work, and it’s deliberately narrow:
- It’s a separate command, not a setting. Escalating is a decision you make each time, not a switch someone forgets to put back.
- It lifts one control, not all of them.
- It refuses to start anywhere except the folder it exists for.
My normal day-to-day sessions cannot modify their guards, their harness, or anything else about what they’re allowed to do. When they trip something, they report to me, generally with one of those annoying breathless AI apologies which you know means nothing coming from an AI sociopath agent because they’re just appeasing/manipulating you instead of feeling actual regret. But then we can discuss why it hit the guard, and once we’ve worked out what change is needed to avoid the guard next time we either update the notebook, or pass a note to our new starter’s supervisor.
That second launch command is the supervisor: it reads the request, makes the desired change, then stops. It doesn’t get involved in the daily rigmarole.
Don’t trust the documentation (including mine)
When I designed these guards, I tested my assumptions about how the harness behaves against the real thing, rather than trusting what the documentation said it would do. Several of my designs changed as a result, including what happens when a hook itself fails.
So test your guard by watching it block something, not by reading that it should.
Summary
None of this makes the agent trustworthy. It makes the agent’s mistakes survivable, which is a far more achievable goal. Your setup will look different from mine, and it should, but if I were starting again tomorrow I’d:
- Enforce, don’t ask. Write the rules in the notebook, then make the ones that really matter impossible to break.
- Layer your guards, because no single one sees everything.
- Fail closed, so a broken guard is loud rather than invisible.
- Log what matched, never what was said.
- When a guard trips, treat it as feedback: fix the notebook, or have the supervisor fix the guard, never by switching it off.
What’s the one thing you’d brick up first?