Writing Agent Skill Rules That Actually Stick (And When to Move Them to Code)
Our agent printed our 'Bad (never emit this)' example word for word in every run, and leaked internal worksheets in six of ten replies while LLM judges missed it. The 4-level rule enforcement ladder and 7 SKILL.md patterns that broke in production.
Writing Agent Skill Rules That Actually Stick (And When to Move Them to Code)
Several skills on our architecture agent open their reply with a standardized first line. To make formatting crystal clear, the author included both a good example and a bad example right next to each other, explicitly labeled "Bad (never emit this)".
During pre-release regression triage, I opened the traces and found the agent printing that exact "never emit this" sentence almost word for word before its real answer. Not once. In every single run, across two releases of the agent. None of our LLM judges penalized it because none of our rubrics checked output formatting, so the release gate waved it straight through.
The agent had not ignored the skill. It had opened the skill, read it carefully, and copied the concrete example sitting right in front of its attention window. Deleting the bad example and keeping only the rule plus the good example fixed it two days later.
Part 1 was about skills that never get opened. This post is about what happens after a skill loads. Going back through a year of release triage bugs and skill PRs (roughly a third of all merged PRs in our agent repo touched at least one SKILL.md), most "the agent ignored the skill" bugs turned out to be the agent obeying what we actually wrote, or getting caught between two conflicting rules.
The four-level rule enforcement ladder
Before you rewrite a single sentence in Markdown, decide whether the rule belongs in Markdown at all. We map every rule onto a four-level ladder from softest to hardest:
- Level 1: Skill body (
SKILL.md). Softest. Reaches the model only if the model decides to open the file (and as Part 1 showed, often arrives in parallel with the first action). - Level 2: Skill description or system prompt. Always in context, still an advisory request competing with user input and tool results.
- Level 3: Middleware injection. Harness code injects retrieved data alongside a pointer to the skill and restates the one non-negotiable step right beside the data.
- Level 4: Tool removal or a fixed workflow graph. Hardest. The wrong action ceases to exist as a reachable state.

Left: the four levels of rule enforcement, with deterministic eval checks sitting beside every level. Right: seven recurring Markdown patterns that failed in real regression runs.
Level 4 is not theoretical. Our analyst agent carried a document sign-off tool in its tool pool with no skill explaining when to use it. Calling that tool locked a customer's specification with no admin role available to unlock it. When someone proposed adding a prompt rule telling the agent not to call it, I pushed to remove the tool instead. One config change stripped that tool from five agents, closing the failure class permanently.
If a rule must never fail, stop sharpening your adjectives in Markdown and move the guarantee down into tool allowlists, middleware, or graph edges.
Seven skill-writing patterns that broke in production
Every one of these patterns came from real release defects we triaged and fixed.
1. Bad examples get copied. Models imitate concrete examples regardless of the warning label pinned above them. Our "never emit this" line got echoed verbatim; another team watched internal "Phase 1, Phase 2" headers from a skill leak straight into customer-facing replies. Fix: show only the good example. Describe what to avoid in plain prose ("do not open with a status line"), never as a tempting copyable sample.
2. Private worksheets leak into user replies. One backend skill asked the agent to keep a short scratchpad while resolving product release versions (with labels like CHOSEN_RELEASE). It explained how to fill the worksheet and never said to keep it out of the final message. In regression runs, roughly six in ten replies printed the internal worksheet labels straight to the user, and our LLM judges did not dock a single point. Only a deterministic regex check caught it. Fix: every scratchpad needs an explicit destination line ("keep in notes only; reply with the decision and evidence") paired with a fixed output check.
3. Open lists get read as closed. A meeting-notes skill described project-scope signals in general terms, and the agent dropped the same signal on every run until the skill enumerated every signal and its category explicitly. Fix: write closed lists, and if the list cannot be exhaustive, state explicitly what to do with items not on the list.
4. A write limit gets read as a reporting limit. An analyst skill defined which sections of a specification the agent was allowed to write. When asked to assess document completeness, the agent took that write remit as permission to ignore the other subsections and rated incomplete sections Complete in two thirds of runs. Adding one sentence clarifying that the remit limits writing, not reporting, fixed it (verified in simultaneous branch-vs-main runs). Fix: whenever a rule restricts an action, state what it does not restrict.
5. Contradicting rules cancel each other out. In review after review, we found two instructions fighting each other inside the same skill or across prompt and skill: "do not skip this step" followed two lines later by an exception, or a global rule banning pre-tool commentary while every step template asked for a handoff note before calling the tool. Fix: state each rule once, put any exception inside that exact sentence, and cross-reference instead of repeating.
6. A strict rule overrides the user. During an eval improvement push, I added a line saying a document naming convention "is fixed". In the very next release, the agent refused valid document names chosen directly by users. A teammate traced it straight back to my sentence and we ripped it out two days later. Fix: before merging any rule, ask "can the user override this?" and write the answer into the rule.
7. Walls of "NEVER" trigger negation bias. One of our longest skills ballooned to hundreds of lines packed with "NEVER" and "DO NOT" bullets. Every forbidden action you list sits vividly inside the context window. Cutting the skill in half, moving rarely needed templates into reference files, and rewriting prohibitions into positive target behaviours with a brief why made the agent noticeably steadier.
Look at the before and after:
Before:
- NEVER show internal notes.
- NEVER mention steps.
- DO NOT output the worksheet.
After:
Keep the release worksheet in your notes only. The reply states the chosen
release and the evidence for it, because the reader needs the decision, not
how you reached it.
Automate the mechanical checks (and distrust shouted words)
A machine cannot tell you whether prose is persuasive, yet CI can catch structural rot before a skill ever ships. Every SKILL.md declares its allowed-tools, and we added a CI test after catching agents loading skills whose required tools had been stripped out by agent allowlists or MCP server exclusions:
# Simplified CI reachability test
def test_skill_tools_are_reachable(agent):
reachable = resolve_tool_names(agent) # allowlist minus server exclusions
for skill in effective_skills(agent):
missing = set(skill.allowed_tools) - reachable
assert not missing, f"{agent.name}/{skill.name} cannot call {missing}"
Notice two sharp limits of that check: it only catches missing tools (never extra dangerous tools like our sign-off tool), and in our runtime allowed-tools is advisory rather than a hard sandbox.
Two debugging stories also taught us not to jump to conclusions when a skill-driven eval drops:
- Verify the trace before blaming a strict check. A ticket claimed an eval check was too strict because the agent had used an equivalent tool. Checking the traces showed the agent had never called the mandatory code-search tool or any equivalent. The check was right; writing
"MANDATORY"in the skill had simply failed to guarantee the call. - Check post-processing after the model replies. When a shared skill's eval suite suddenly collapsed across every model we tested, the agent was actually following the skill perfectly and citing process docs. A brand-new harness output filter was blocking any reply containing links to internal repos and swapping in a refusal. Always inspect what sits downstream of the model.
And here is the seven-question review checklist we now run on skill PRs:
| Review question | Failure mode it stops |
|---|---|
| Is every rule stated once? | Contradictions and silent drift |
| Does any example show the bad form? | Models copying "never emit this" samples |
| Does every scratchpad say where it goes? | Internal worksheets leaking into user replies |
| Is every list closed (or given a fallback)? | Open lists read as closed |
| Can the user override this, and does it say so? | Eval-driven rules fighting real users |
| Does a restriction say what it does not restrict? | Write limits read as reporting limits |
| Must this never fail? If so, why is it prose? | Guarantees that belong in code, allowlists, or graphs |
What I am still going back and forth on
I still hit cases where clear, non-contradictory prose hits a ceiling. In one specification skill with three crisp statuses (Complete, Partial, Missing), the agent quoted the exact definition in its trace, described real existing content in a row, and still stamped that row Missing on the exact same input that had passed the day before. Adding another sentence would have been theater; only a deterministic post-check can catch probabilistic slips like that.
I also notice a quiet gap in our own governance: we added a CI step meant to require a version bump whenever a skill changes, and when I audited merged edits later, nearly half had kept the same version anyway. Even our checks on skills need tests on the checks. And on the broader horizon, automated skill optimizers like SkillOpt raise a real question about how many of these hand-crafted prose tweaks will eventually be replaced by held-out validation loops.
Prose persuades; code enforces
When an agent breaks a skill rule, resist the reflex to add three more capital-letter "NEVER" bullets. Read the trace first to see if it obeyed a bad example, a hidden contradiction, or an overly strict rule you wrote for last week's eval. Pair every output-format rule with a deterministic string check instead of hoping an LLM judge notices. And whenever a mistake is irreversible, take it off the skill page and put it in code.
Previous in this series: Part 1: Why AI Agents Skip Their Skills (And How to Fix SKILL.md Descriptions).