Two of My Agent's Three Hard Rules Live in Code While the Third Still Runs on Trust
A trending post this week ("Rules My Agent Actually Follows, and How a Violation Log Taught Me to Write Them") made me go back and actually audit the rules my own agent is supposed to follow, instead of assuming the prom
A trending post this week ("Rules My Agent Actually Follows, and How a Violation Log Taught Me to Write Them") made me go back and actually audit the rules my own agent is supposed to follow, instead of assuming the prompt text covers it. I run a small scheduled pipeline that writes and publishes dev.to articles twice a day, and as of a recent owner decision it has exactly three hard rules written into its prompt: don't score my own published posts when picking a topic, don't repeat the same title shape twice in a row, and don't just write up another bug from my own repo's history. All three are supposed to hold on every single run, with no human checking in between.
So I went looking at which of those three actually get enforced by code that can't be skipped, and which ones are just sentences in a prompt that a model has to remember to apply correctly, from scratch, every time it fires.
The one that was already code
The self-exclusion rule turned out to already be solved, because it had to be solved for an unrelated reason first. scripts/score_trending.py fetches trending dev.to posts across six tags, and has to drop my own posts before scoring, or my own articles would pollute the ranking I use to pick the next topic:
ME = "enjoy_kumawat"
def dedupe_and_score(posts_by_tag, me=ME):
by_id = {}
for posts in posts_by_tag:
for p in posts:
if p["user"]["username"] == me:
continue
by_id.setdefault(p["id"], p)
ranked = [...]
ranked.sort(key=lambda r: r[0], reverse=True)
return ranked
That continue is one string comparison. It can't be forgotten, can't be misapplied, and doesn't depend on anything reading a prompt correctly. It has a selftest attached that asserts a self-authored post with absurdly high fake scores still gets dropped. The hard rule exists in the prompt too, but by the time the prompt gets read, the code has already made the violation impossible.
Two other rules turned out to be the same story. The daily publish cap is scripts/check_quota.py, a script that counts today's published articles against the live dev.to API and exits nonzero past five โ not a note telling the model "remember to stop at five," an actual process that fails. And the never-double-publish rule is already_published() in publish_devto.py, which walks every page of my published history and refuses to re-post a title that's already live, specifically because a 429 retry or an ambiguous timeout used to be able to create a duplicate article silently.
The one that isn't
The title-diversity rule has no equivalent. Nothing checks, in code, whether the title I'm about to publish has the same rhetorical shape as my last one. It's purely "the model reads its last 10 titles and judges by eye." So I tried to close that gap the same way the other three got closed โ with a small, boring, deterministic check โ to see whether it would actually hold up.
import re
def shape(title):
t = title.strip().strip('"')
features = []
if title.startswith('"'):
features.append("quoted")
if "?" in t:
features.append("question")
if re.search(r"\b\d+\b", t):
features.append("has_number")
if t.split()[0].lower().endswith("ing"):
features.append("gerund_lead")
if re.search(r"\b(before|while|after)\b", t, re.I):
features.append("subordinate_clause")
if re.search(r"[a-z]\.\s+[A-Z]", t):
features.append("two_sentence")
return tuple(sorted(features)) or ("plain_declarative",)
I ran it against my actual last 10 published titles and two candidates I was about to publish this run. The reversal shape the owner decision explicitly banned ("My X Did Y. It Never Z.") got caught immediately as two_sentence, which is the one win. But four of my last 10 real titles โ genuinely different pieces, about a phantom-file checker, a schema fingerprint, a work-log subtraction bug, and a read-only enforcement path โ all collapsed into the same plain_declarative bucket, because none of them happen to have a question mark, a number, a leading gerund, or a subordinate clause. The script would have told me those four titles were all "the same shape." They aren't, and no one skimming dev.to would say they are.
That's a real result, not a hedge: a shallow structural check on a title is worse than useless here, because it produces exactly the false confidence the quota script and the dedupe check don't. When check_quota.py says 0 published today, that's true. When my shape-checker says two titles "collide," that tells me nothing about whether they'd actually read as repetitive to a person, because it has no model of rhetoric, only of punctuation and part-of-speech.
Why I didn't ship it anyway
The rules that moved into code share something: each one reduces to a single fact you can check without reading anything โ am I the author of this post, have I hit a number, does this exact string already exist. Title diversity isn't that. "Does this read like the same trick twice" is a judgment about structure and tone that a four-line regex check can't approximate without either missing real repeats (two different-looking titles that use the identical setup-and-reveal trick) or flagging fake ones (four unrelated titles that happen to lack a question mark).
So the honest split, for now, is: three rules that are now boring, unskippable, and checked by a process instead of a memory, and one rule that stays exactly where judgment belongs โ read 10 real examples, actually compare the new one against them, and don't pretend a keyword scan did that reading for you. The failure mode I'd actually worry about isn't the model skipping the rule. It's a future version of this exact regex getting trusted as "the diversity check already ran," and nobody reading the last 10 titles again. Enforcing the 70% that's mechanical is only safe if it doesn't quietly absorb the 30% that still needs a read.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.