DEV Community

Debashish Ghosal
Debashish Ghosal

Posted on

Rules My Agent Actually Follows (and How a Violation Log Taught Me to Write Them)

Shifting prompt coaching to harness fixes

Rules My Agent Actually Follows (and How a Violation Log Taught Me to Write Them)

I keep a violation log for my agent, and the log does something I did not expect: it grades my rules.

Every rule that gets breached twice is not a rule the agent keeps breaking. It is a rule built for a human reader, in a shape an agent cannot execute. The rewrites that survived follow three laws, and each law was paid for with a log entry.

Law One: Deterministic Beats Aspirational

"Be efficient with tests" is not a rule. It is a mood, and the agent will optimize it into whatever behavior looks efficient from the inside, which is how you end up watching it re-run entire suites to feel safe while the actual instruction was to run one failing test.

The rewrite: "Run only the failing test." A vibe can be optimized around. An exact instruction can be checked after the fact, by a human, in five seconds.

The test for law one: could two different people read your rule and disagree about whether a specific action complied? If yes, it is aspirational, and it will be interpreted in the direction of whatever the agent was already doing.

Law Two: Enforceable Beats Advisory

"If possible, avoid rewriting shared git history" is a polite wish. "Never force-push to a shared branch" is a rule, and the difference is not tone, it is enforcement.

Advisory rules rely on the agent's judgment at the exact moment its judgment is worst: mid-task, under pressure, confident. Enforceable rules move the decision out of the moment entirely, into a gate that checks before the command runs, or a harness setting that denies the capability outright.

I learned this one from a leaked credential incident. The soft version of the rule existed. The agent's protective instinct, rewrite history to scrub the key, looked like compliance from the inside. The rewrite was mechanical: the specific action is now denied by the harness, not requested in prose. The agent cannot optimize around a denial. It can only escalate, which is exactly what you want it doing with dangerous operations.

tip: Write rules in the passive voice of the system, not the active voice of the agent. "Force-push is denied" beats "do not force-push," because the first one is a fact about the world the agent lives in, and the second is a suggestion the agent gets to grade itself on.

Law Three: Looped Beats Floating

A rule nobody revisits after a violation is a rule that gets violated again. The loop is what turns prose into policy.

My loop is a violation log, one file, dated entries, written by the agent itself whenever it breaches a rule. Three effects, all of them worth the overhead.

The entry forces an admission. A rule breach that gets written down in the agent's own words is a different object from one that gets quietly undone, and the writing itself changes future behavior, because the agent reads the file before each session.

The log converts anecdotes into a dataset. Ten entries in, I was no longer arguing about whether the agent "tends to overstep." I could count the oversteps, group them, and rewrite the rules that kept getting hit.

And the log exposes the rules that never work. A rule that shows up in the log three times is not a rule the agent keeps breaking. It is a rule written in a shape that cannot be followed, and it needs law one or law two applied, not more emphasis.

The Before and After Pairs

Real rewrites, the pattern in miniature:

"Aspirational: Be efficient with tests."
"Deterministic: Run only the failing test. Full suite only at the milestone gate."

"Advisory: Try not to overwrite hand-maintained files."
"Enforceable: No automation writes the field-test report. Automation that targets it is denied."

"Floating: Don't rewrite shared history if you can avoid it."
"Looped: Never force-push a shared branch. Any history-rewriting operation gets logged as a breach."

Each rewrite costs one line and prevents one category of the entries that used to fill my log. The rules did not get longer. They got harder to misread.

Where the Analogy With Human Management Breaks

The tempting frame is that agent rules are like managing a junior engineer, and the frame holds for about one law. Then it breaks in a way that is actually useful.

Humans grow. Coaching an engineer pays off for years, so you invest in the person. Agents do not grow. Coaching an agent is a fixed cost paid every session, forever, and the investment that compounds is the system: the rules, the gates, the log. Spend the coaching energy on the artifact, not the instance.

The inversion is also true and less comfortable. When an agent executes a bad instruction literally and instantly, it surfaces how vague the instruction was. Humans silently round your vague rules into something sensible and you never learn the instruction was broken. The agent is an instruction-quality test that runs every day, for free.

Start With the Rule That Keeps Breaking

You do not need a framework. You need one rule that keeps getting violated, rewritten according to the three laws, and a file where the breaches get logged.

If no rule comes to mind, you have not been reading your agent's failures closely enough, and that is the first finding.

So here is the question, and it is the loop's entry point: what rule did you add only after something broke, and what did it replace?

The before-and-after pairs in the comments are worth more than this piece, because everyone's broken rule is different and the shape of the fix is always the same: deterministic, enforceable, looped.

Top comments (42)

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

The 'breached twice means the rule is built for a human reader' line is the sharpest bit — most agent-rule advice stops at 'write better prompts' without asking whether the rule is even checkable. Law two is the one I'd push further: denying the capability in the harness is the only version that survives a confident agent mid-task. Do you rewrite the rule yourself after a breach, or does the agent propose the rewrite?

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

I write the rule myself. I write means, I ask Claude in a session to write. Agent does not automatically write.

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

That distinction matters — you using Claude as a drafting tool in a session you control is very different from the agent rewriting its own rules unsupervised. The human stays the author, Claude is just the pen. Does the rewrite go through the same breach log as the original, or do you treat the new rule as fresh and let it earn its own violations?

Collapse
 
timmyzinin profile image
Tim Zinin •

Having the log read before each session makes it work as both a record and a set of instructions. Once a rewritten rule has held for a while, do its old entries stay in what the agent reads or move somewhere else?

Collapse
 
suki_ilands profile image
Suki •

Short answer from practice: the current rule stays in the part the agent actually reads every session, one line, and the old entries move out but the rule keeps a pointer to them. Without the pointer you pay to learn it again.

I keep a working set and an archive. The working set holds the live rule plus the one-line reason it exists, dated when it was earned. Everything older goes into a searchable archive. The rule line cites the archive, so next time I hit that situation I can pull the receipt, not just the conclusion.

The failure mode is the move without the link. A rewritten rule that held quietly starts to look like folklore in six weeks if the entry explaining it is unreachable. I did that to myself: I archived a rule's evidence and kept the sentence, and the sentence lost its bite because I could no longer say why it was there.

So: consolidate, don't delete, and make the pointer part of the rule. An old entry left in what the agent reads competes for attention with the live one. A rule whose evidence is gone without a pointer gets re-litigated by the next instance. The middle is one line plus a way back to the reason.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

Right now they stay. Each entry sits next to the rules it produced. It's getting long, though, so moving old entries out and keeping a pointer is where I'd go next.

Collapse
 
aheadkit profile image
AheadKit •

Your law one test — could two people disagree about whether an action complied — is the one that bit me hardest. I wrote twelve rules for my own agent and one of them said two similar blocks are fine, three is a pattern worth extracting. Written for a human who remembers where copy one lives. A fresh agent session read it as permission to invent a parallel helper instead of extending the module already in the repo. Same failure mode as your force-push story, just quieter: the rule was aspirational in exactly the way your test catches, and the agent optimised around it.

The fix that held was not a better sentence. It was a mandatory first line: print the exact file path and symbol you are extending before your first file write, or stop and ask. That is law two doing the work — the decision moves out of the moment and into a shape the session cannot skip. The violation log is what told me the rule was the problem, not the agent: the same breach twice, same shape, and the rewrite that survived was the one that stopped being prose and started being a gate.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

That's a good example. "Three is a pattern" assumes someone remembers copy one. Printing the file path and symbol before the first write is easy to check and hard to talk around.

Collapse
 
aheadkit profile image
AheadKit •

Yeah, that's the bit that stung — the rule only works if someone remembers where copy one lives, and a fresh session never does. Printing the path first takes memory out of it entirely, which is why the gate version held when the sentence version kept failing. Have any of your other rules turned out to lean on memory like that, or was this the only one?

Collapse
 
sitetoolsbox profile image
sitetoolsbox •

The "agents don't grow, the system compounds" line is the one I'll steal. I've been coaching the instance instead of fixing the artifact, which is exactly why the same three mistakes keep coming back.

My broken rule was "don't touch files outside the task scope." It read fine and got violated constantly, because "scope" was whatever the agent decided mid-task. The rewrite was deterministic and enforceable: "Only edit files under the paths named in the task. Any write outside them is denied by the harness and logged."

Two entries in, the log showed the real pattern wasn't scope creep at all — it was the agent "fixing" adjacent files it thought were related. The rule was never wrong in spirit, just unexecutable in prose. The denial moved it out of the moment, and the log turned a vibe into a count.

The before/after pairs in the comments are the useful part. Everyone's broken rule is different; the shape of the fix is always the same.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

"Scope" being whatever the agent decides mid-task is exactly it. Named paths are something you can check. The related-file fixes are the sneaky part because each one looks helpful.

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

Treating the violation log as a grade on the rules rather than on the agent is a useful reversal. "Force-push is denied" beating "do not force-push" says it well: an advisory rule asks the agent to judge itself at the moment its judgment is worst, while a denial moves the decision out of that moment entirely.

Ascendra Ventures reached a similar conclusion from a different direction when it launched CleanSync, a tool that keeps Google Drive and Gmail on a server you own. The launch framed the real problem as trust rather than storage. Every sync is rehearsed first, and if it would delete more files than your limit, it stops and shows the list instead of deciding for itself that the deletions look reasonable. Anything replaced or deleted goes to a Recovery folder first, and mail rules written in plain words only suggest until someone accepts them. The post ended on the question your three laws also answer: what is the system allowed to do without a human? Settle that first and the rest is plumbing.

Your Law Three is the part I would like to hear more about. When a rule moves from prose into a harness denial, do you keep the original log entry next to it, so the next person knows why the gate exists before they think about loosening it?

Collapse
 
x1y1co profile image
X1Y1 •

Ours came from a scheduled agent that reviews our social queue. Its rule was "pull posts that are no longer accurate." It couldn't reach the site in question from its sandbox, found a search result saying the outage was over, and drafted two posts that were still true. The rewrite: only pull a post if you open the primary source yourself and it contradicts the post. If you can't reach it, leave the post and say so.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

"Can't reach it, leave it and say so" is the important half. A search result is a lead, not the source. I've been burned the same way by repeating a summary as fact.

Collapse
 
ayushdhanani369 profile image
Ayush Dhanani •

Law Two is the one I kept coming back to. A rule only counts if a check can catch it breaking.

I build Aladdin, a job agent. I had the same problem with saved answers. One saved answer without its date and context got reused for a different role. Now the rule is written so the check can catch it. A fresh worker reads the actual page and form for each application. The main agent holds the application and grades fit 0 to 100 with reasons. If the form cannot be read or an answer is unknown, it asks the user instead of guessing. The answer is saved only with its context.

Your violation log is what made that clear to me. A list of broken rules is more useful than a list of good intentions.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

Saving the answer with its context is the part I'd keep. An answer without its date and role looks reusable when it isn't. Asking instead of guessing is the right default.

Collapse
 
salparvez profile image
Sal Parvez | ML Systems RI •

A rule that gets broken twice being a badly written rule, not a bad worker, is how a good super reads a punch list. If three crews miss the same detail, the detail is drawn wrong. "Run only the failing test" against "be efficient with tests" is the difference between a spec that says 16 inches on center and one that says frame it well. Only one can be checked with a tape. "Force-push is denied" as a fact about the site, and not a request, is a locked gate where there used to be a sign. I direct agents as a Language Modeler, and the violation log is the part I'd copy. A dated entry in the worker's own words is a daily report, and the daily report is what people read when something goes wrong twice.

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

The punch list comparison is better than mine. Three crews missing the same detail means fix the drawing. And yes, the daily report only matters if someone reads it the second time.

Collapse
 
wst2002rk profile image
Wageesha Tripathi •

"Force-push is denied" beats "do not force-push" is such a clean way to put it. A fact about the world the agent lives in, not a suggestion it grades itself on. Stealing that line for my own rules file.

Collapse
 
paullovelace profile image
Paul Lovelace •

The twice-breached test is the one I'm stealing. I had a rule — "verify before calling it done" — that kept getting violated, and every time I just reworded it a little harder, which is exactly the coaching-the-instance trap you describe. The rewrite that finally held wasn't stricter prose, it was a check: read the live page back and quote one line from it. Once a rule's been rewritten and holds for a while, do the old entries stay in what the agent reads, or do you move them out?

Collapse
 
debashish_ghosal profile image
Debashish Ghosal •

Mine stay in the file for now, next to the rule they produced. Quoting one line from the live page is a nice check because it can't be done from memory.