The Smallest Spec That Rejects Wrong Code: Discriminating Power, Counterexamples, and Spec Weight
Take two fixes an agent wrote for the same bug. Both fix the reported case and both have green CI, but only one doesn’t quietly change behavior nobody reported. The ticket is simple: a new vendor writes categories with a “/” instead of ” > “, so “Electronics/Audio” lands in the “Other” category.
") for r in raw_list]
return [CATEGORY_MAP.get(k, "Other") for k in keys]
# Fix B: guesses the category instead of returning "Other"
def map_categories(raw_list):
return [CATEGORY_MAP.get(r) or closest_match(r.split("/")[-1])
for r in raw_list]” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
# Fix A: normalizes the separator, nothing else changes
def map_categories(raw_list):
keys = [r.replace("/", " > ") for r in raw_list]
return [CATEGORY_MAP.get(k, "Other") for k in keys]
# Fix B: guesses the category instead of returning "Other"
def map_categories(raw_list):
return [CATEGORY_MAP.get(r) or closest_match(r.split("/")[-1])
for r in raw_list]
# Fix A: normalizes the separator, nothing else changes
def map_categories(raw_list):
keys = [r.replace("/", " > ") for r in raw_list]
return [CATEGORY_MAP.get(k, "Other") for k in keys]
# Fix B: guesses the category instead of returning "Other"
def map_categories(raw_list):
return [CATEGORY_MAP.get(r) or closest_match(r.split("/")[-1])
for r in raw_list]
Fix B returns “Audio” too. As a side effect, it sends every unknown category that used to land in “Other” and wait for manual review to its closest match, so “Automotive/Car Audio” ends up among the headphones. Spec length won’t tell you which of these diffs should pass review. For this fix, one thing matters most: whether the spec can tell the two versions apart.
If you approve specs before handing them to an agent, this is your problem. A spec that can’t tell these diffs apart gives you no grounds to reject the worse one, whether it has five lines or sixteen acceptance criteria. By the end, you’ll check your own spec’s discriminating power with counterexamples from an agent and pick its weight from a risk × ambiguity matrix — the matrix and four templates are waiting at the end, ready to copy.
Quick Win — Core Insight
A spec doesn’t get better by getting longer. It gets better when it can stop a wrong implementation that looks correct at first glance. That’s discriminating power: for every clause in the spec, you can name a plausible wrong version of the code that the clause won’t let through.
If I can’t point to such a version after an honest attempt, the clause is more of a review cost than a control — to be sharpened, moved, or removed. Sometimes it holds a rationale that belongs in an ADR (a short record of one decision: context, decision, consequences), not in the acceptance criteria. I check this without writing implementations by hand: I ask an agent that sees only the spec for a few convincing but wrong versions, then mark which clause stops each one. A realistic counterexample with no clause is a gap to close; a clause with no counterexample is a candidate for removal.
The second tool is spec weight, which I pick from a risk × ambiguity matrix. A label change needs no separate spec, a low-risk change with an unclear goal needs a paragraph, a risky fix with a clear goal needs a page, and a high-risk data migration with an unclear solution needs a full specification. I don’t set the weight by how much text a tool is happy to generate. The smallest spec is the sufficient one, not the shortest.
Let’s start with why the intuitive measures of spec quality measure something else entirely.
Length, Sections, and Criteria Count Make a Bad Thermometer
A well-documented case of spec inflation is small, which is exactly why it teaches so well. Birgitta Böckeler of Thoughtworks asked Kiro, one of the SDD (spec-driven development) tools, to fix a small bug, and its requirements document turned it into 4 user stories with 16 acceptance criteria in total (martinfowler.com, 2025). She herself compared the workflow to using a sledgehammer to crack a nut. In fairness, she tested the tools in September 2025, and Kiro now has a separate path for bug fixes — I’ll come back to it in the third section.
One of those four user stories demanded that the transformation function handle edge cases “gracefully” and that the system remain “robust”. That wording rejects no specific implementation, because any implementation can be called graceful and robust. This is specification theater: a document that looks like a control but stops nothing. The reviewer reads sixteen points, nods, and with wording like that has no concrete behavior to base a rejection of the diff on.
Three Thermometers That Measure Volume
Three popular thermometers of spec quality share the same flaw:
- Length — the number of Markdown lines grows with the tool’s verbosity, not with the risk of the change.
- Section count — a template filled in to the end looks diligent, even when half the sections repeat the ticket.
- Criteria count — sixteen looks more serious than three, though three good ones will stop more.
Each one is easy to inflate just by generating text, and none says whether the spec can tell a good fix from a bad one. A thermometer that shows the patient’s weight instead of the fever also gives you a number, just not the one you need. In the cases described, spec volume grew with the tool’s verbosity, and nothing suggests it came from an assessment of the change’s risk. That inverts the logic: the changes that got the most text there were the ones that needed it least.
Too Many Instructions Have a Cost
Excess instructions aren’t neutral, either. In the same text, Böckeler described an agent that went far too far because it followed instructions too eagerly. An overloaded spec can therefore push an agent toward unnecessary changes and surplus code, which I’ll return to when we get to pruning. I’ve covered the rules for writing specs and the formal metrics of their quality separately (seven rules, two layers of quality) — here the criterion is functional.
If length isn’t the measure, we need one you can test on your own spec.
A Spec Is Only as Good as the Wrong Code It Stops
Quality control has an instrument that captures this idea well: the go/no-go gauge. It has a go side and a no-go side, and its value lies in the second: a good part can’t fit into it, so when a part does, it’s out of tolerance — even if it looks fine to the naked eye — and goes to the reject bin. A spec works the same way: its no-go side is what counts, meaning the clauses where a plausible wrong implementation gets stopped. Karl Popper considered a theory that no possible event could refute to be unscientific — in the same sense, a clause that no possible implementation breaks forbids nothing.
Test Oracles and Mutants
The testing literature has a name for this. A test oracle is a mechanism that decides whether a result is correct. In SDD, the spec is the source of expectations for such an oracle, and during review the oracle is mostly a human comparing the code against the spec.
An oracle’s strength is measured with mutants: a mutant is a small, deliberately injected bug, and the mutation score is the share of such bugs that make the tests fail. The mutation score thus answers whether the tests can tell a program from its deliberately broken versions.
A weak oracle lets wrong code through, and you can measure it. When researchers expanded the tests of a popular code benchmark 80-fold, the share of tasks counted as solved dropped by as much as 19.3–28.9%, depending on the metric variant — code that had previously “passed” turned out to be wrong. Additional checks stopped the wrong code, not additional text. A clause adds discriminating power only when it introduces a new, verifiable distinction, while prose alone usually just enlarges the surface of instructions.
The Counterexample Test With an Agent
I check my own spec’s discriminating power without writing implementations by hand — with a single prompt to an agent. One prompt yields a list of counterexample candidates, not a measurement: I judge each one myself, and for a risky change it’s worth repeating the test on a different model. The agent doesn’t get the code, because once it sees the code, it easily describes what the code does instead of what it should do:
<button data-code="Role: spec reviewer. You see only the spec below, not the code.
Task: write 5–10 implementations that look correct
but break the intent of the spec.
# each must pass a cursory review and the reported case
# each must break a different intent, not the same one five ways
For each implementation, state:
– which intent it breaks (one sentence),
– which spec clause it violates, or "none".
At the end, list the clauses that no implementation violates.
…
” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
Role: spec reviewer. You see only the spec below, not the code.
Task: write 5–10 implementations that look correct
but break the intent of the spec.
# each must pass a cursory review and the reported case
# each must break a different intent, not the same one five ways
For each implementation, state:
- which intent it breaks (one sentence),
- which spec clause it violates, or "none".
At the end, list the clauses that no implementation violates.
<spec>
...
</spec>
Role: spec reviewer. You see only the spec below, not the code.
Task: write 5–10 implementations that look correct
but break the intent of the spec.
# each must pass a cursory review and the reported case
# each must break a different intent, not the same one five ways
For each implementation, state:
- which intent it breaks (one sentence),
- which spec clause it violates, or "none".
At the end, list the clauses that no implementation violates.
<spec>
...
</spec>
I read the output as a clause–counterexample map. A realistic counterexample with no clause is a gap: I add a clause or consciously accept the risk. A clause with no counterexample is a candidate for dead text: I sharpen it, remove it, or move it to an ADR.
The Same Move at Meta
This isn’t a thought experiment, because a very similar move has already been tried in industry. You describe the bug you fear, an LLM writes mutant candidates, filters drop the ones that don’t build, are equivalent, or are already caught by tests, and new tests are generated for the rest and go through human review. That’s how ACH works at Meta (Foster, Gulati, Harman et al., FSE Companion 2025), where 9,095 mutants produced 571 privacy-hardening tests.
In test-a-thons on Messenger and WhatsApp, engineers accepted 73% of the tests ACH generated and judged 36% relevant to privacy. Meta targeted code tests, while I carry the same idea over to spec review — but the takeaway is shared: LLM-generated plausible bugs are already being tested in industry, not just in theory — though ACH doesn’t validate the spec-review method itself.
Three Limits of the Test
The test has three limits worth knowing:
- The blind spot. A 2014 study of 357 real bugs found that mutants from typical operators correspond to 73% of them, and roughly one bug in six (17%) has no counterpart in any mutant. That concerned syntactic mutants in Java programs, not LLM-generated mutants, so I carry the conclusion over cautiously: an agent won’t think of everything you fear.
- The equivalent mutant. Some of the “wrong” versions will turn out to be correct, because the change doesn’t alter behavior, so no clause should stop it. Such a result is noise, not a gap.
- Visibility. I keep the counterexamples out of the implementing agent’s context. In a benchmark where tests deliberately contradict the specification, agents that could see the tests were able to modify them or hardcode results for specific inputs.
The criterion sounds good in theory, so let’s run three versions of the same spec through it.
One Spec in Three Versions and Three Wrong Fixes
Three Wrong Fixes
Back to the function from the start. map_categories takes a list of product categories from the vendor and returns a list of internal ones, where the first on the list is the main category and the navigation on the product page depends on it. For the test, I take three plausible wrong fixes, each from a class well known from review:
- (a) The hardcoded fix, or special-casing — a fix baked in for the specific input from the ticket:
if r == "Electronics/Audio": return "Audio". The ticket goes away, while “Electronics/Phones” still lands in “Other”. - (b) The overzealous fix — fix B from the start of the article: it fixes the ticket and silently changes the fate of every unknown category.
- © The fix that loses order: after normalizing the separator, the same categories can end up duplicated, so the agent removes duplicates through
set(). The list loses its order, and a product can change its main category.
One caveat: this is a clause-by-clause analysis, not a measurement. I didn’t generate hundreds of implementations. I only decide whether a given clause logically admits a given fix.
The Generic and the Overloaded Version
The generic version fits in one sentence:
The function correctly maps vendor categories
and handles edge cases.
The function correctly maps vendor categories
and handles edge cases.
It lets all three fixes through. Each one is defensible, because the reported case works, and no clause names a specific behavior the reviewer could rely on.
The overloaded version looks serious:
User story 1: As a catalog manager, I want categories
in the new format to be mapped correctly...
AC 1.3: The system handles all category separators.
AC 2.4: The function handles edge cases gracefully
and stays robust against new formats.
...
Design: Data Flow · Error Handling · Migration Strategy
User story 1: As a catalog manager, I want categories
in the new format to be mapped correctly...
AC 1.3: The system handles all category separators.
AC 2.4: The function handles edge cases gracefully
and stays robust against new formats.
...
Design: Data Flow · Error Handling · Migration Strategy
It stops (a), because one criterion demands handling all separators. It lets (b) and © through, because the rest is aspiration: “gracefully” doesn’t say where an unknown category should go or whether order matters. On top of that, it invites a fourth class of problems — defensive checks, meaning extra checks nobody needed, added because the spec talks about robustness everywhere.
The Sufficient Version
The sufficient version has four clauses:
" spelling.
Unchanged behavior: # stops (b)
WHEN a category isn't in the map under either spelling,
THEN the function STILL returns "Other".
Unchanged behavior: # stops (c)
The function STILL returns categories in input order,
and the first one remains the main category.” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
Current behavior (bug):
WHEN a category uses the "/" separator, THEN it lands in "Other".
Expected behavior: # stops (a)
WHEN a category with "/" exists in the map after the separator swap,
THEN the result is the same as for the " > " spelling.
Unchanged behavior: # stops (b)
WHEN a category isn't in the map under either spelling,
THEN the function STILL returns "Other".
Unchanged behavior: # stops (c)
The function STILL returns categories in input order,
and the first one remains the main category.
Current behavior (bug):
WHEN a category uses the "/" separator, THEN it lands in "Other".
Expected behavior: # stops (a)
WHEN a category with "/" exists in the map after the separator swap,
THEN the result is the same as for the " > " spelling.
Unchanged behavior: # stops (b)
WHEN a category isn't in the map under either spelling,
THEN the function STILL returns "Other".
Unchanged behavior: # stops (c)
The function STILL returns categories in input order,
and the first one remains the main category.
It stops (a), (b), and ©, and lets through an implementation that’s ugly but correct — as it should, because a spec isn’t a code beauty contest. It has four clauses, while the overloaded version has more than a dozen criteria and three design sections.
Where This Format Comes From and Where to Stop
This format isn’t mine. A three-part bugfix spec — current, expected, and unchanged behavior — is now a separate path in Kiro, the same tool that in September 2025 turned a small bug into sixteen criteria. In my view, the vendor arrived at the same distinction on its own, though its full workflow is still heavier than the four clauses in this example. The “unchanged” clause, meaning behavior that should stay as it was before the change, stops one of the typical plausible wrong fixes: the overzealous one.
Rejecting more doesn’t mean better, though. If I had added to the last clause that duplicates must disappear, I’d have rejected fix A from the start of the article, which doesn’t remove them — even though nobody asked for that. Every clause needs a counterexample, not just good wording.
Four clauses are enough for this fix, but not for a data migration — the matrix tells you how much spec a change needs.
The Risk × Ambiguity Matrix Sets the Spec Weight
In a workshop, nobody holds a bookshelf screw to the tolerance of a car suspension component. Tolerance is chosen according to the consequences of the part failing, not how precise a caliper the inspector has at hand. Software engineering has done this for a long time where errors cost the most: DO-178C scales the number of required software life-cycle objectives and the independence of their verification with the failure condition category, and ITIL 4’s Change Enablement practice assesses the risk of a standard change once and then lets it through without separate approval at each deployment, as long as it stays within the approved procedure.
The second axis comes from design doc practice. Malte Ubl writes in his description of that practice at Google that if the solution isn’t ambiguous, writing a document adds little. Combining the two axes is my own framework, not a standard — built from axes that mature fields have used for a long time, but separately.
Reading the Matrix
The matrix is simple to read:
- Low risk × low ambiguity → none. A label change: five lines in the PR description, no separate spec file.
- Low risk × high ambiguity → note. A paragraph with the expected behavior and one “doesn’t change” clause.
- High risk × low ambiguity → light. Up to a page: current behavior plus 2–4 clauses of expected and unchanged behavior, each with a counterexample. The category-mapping fix lands here, because it touches every imported product and its goal is clear.
- High risk × high ambiguity → full. Requirements, design, invariants, and a migration and recovery plan.
When a Long Spec Is Justified
Risk weighs more with me than ambiguity, because the cost of letting a wrong implementation through grows with the stakes. Ambiguity at low risk is cheaply settled by iteration — these are two-way doors, meaning decisions that can be reversed cheaply. One-way doors, which can’t be undone, demand more work before the agent starts — a spec, a prototype, or a recovery plan.
A sufficient spec for a risky data migration is usually long, and that’s correct: when an error is expensive, it pays to stop more kinds of wrong implementations, so the spec needs explicit invariants and a migration and recovery plan. The strongest example I know comes from Amazon (Newcombe et al., CACM 2015). A formal model — a mathematical description of a system that a tool searches for a counterexample — found a bug in DynamoDB that could lead to data loss, and its shortest trace was 35 steps long.
One of the authors was convinced that additional work in design review, code review, and testing wouldn’t have caught it. The example is about a formal model, not long Markdown, but in this quadrant a precise specification is armor, not theater.
The same logic settles the dispute over review time. A spec whose review takes longer than the code review is a warning sign in the none and note quadrants, and in the full quadrant, an expected cost. One rule, different quadrants, different conclusions.
Weight as Tool Input
I choose the weight before opening the SDD tool, not after the documents have been generated. Some projects have already formalized this: in the contribution rules of OpenSpec, a bug or documentation fix is a single PR with no changes to specs, and a new feature is two PRs: first the proposal, then the implementation. The tool gets the weight as an input, not as an output.
The weight says how much spec you need, but tools will generate more anyway — you need to know how to prune it.
Pruning a Generated Spec Without Losing Guarantees
The problem of excess has already reached an industry technology radar. Teams experimenting with a specification generator, mostly in existing systems, reported in April 2026 unnecessary defensive checks and verbose Markdown that raised cognitive load. Cutting the number of generated files and reworking the templates helped, in part. In another entry, the same radar noted that some tools generate long specification files that are hard to review.
Four Buckets
I run every section of a generated spec through one fill-in-the-blank sentence: “this section stops counterexample X”. The answer sorts it into one of four buckets:
- Acceptance criteria — the section stops a counterexample, so it stays.
- ADR — the section explains why something was chosen. The rationale has value for a future team, just not as a criterion.
- Constitution — the section repeats a rule that applies to every spec, so it goes into the project’s standing set of rules, which the SDD tool attaches to every spec.
- Trash — the section rewrites the ticket, the tech stack, or details the agent gets right on its own.
The four buckets are a default heuristic, not a closed taxonomy: I keep compliance requirements and recovery plans in critical systems separate.
What Qualified for the Trash
In publicly described cases, the items that qualified for the trash included: the generic wording “gracefully” and “robust” (Böckeler), the “Migration Strategy” section in Kiro’s design document (Böckeler), and a repeated description of the tech stack in the plan (Eberhardt). In one of them, a “research” document ran to more than 400 lines and justified the choice of a UI library the app was already using. These are examples, not a frequency ranking.
The Guarantee While Pruning
I remove a section only once I know what guarantee it carried. If it carried a clause with a counterexample, the clause moves to the criteria before the section disappears. You lose a guarantee when you delete by eye — and you gain one by eye in exactly the same way, which is to say not at all.
At first, I pruned finished specs one by one, and that was the wrong level. A template that forces sections with no clauses and no other purpose produces specification theater on every change, so the biggest gain comes from pruning the template, not a single document.
A pruned spec is shorter, but we still need to check whether the team actually saved time.
Measure Spec Overhead on Your Own Changes, Not in a Benchmark
Spec overhead is a narrow measure in this text: the time a spec costs compared with the time it saves in review. The full balance also includes rework and post-deployment defects. I haven’t found a universal threshold in any source, so what’s left is measuring on your own changes.
The Best-Documented Case
The best-documented case I know breaks the times down. Colin Eberhardt (Scott Logic, 2025) rebuilt a feature in his app with the help of a specification generator, which produced 2,577 lines of Markdown for 689 lines of code.
The agent worked for 33.5 minutes, and the total review took 3.5 hours. That’s the whole review — spec, plan, and code — not just the code review, done by one developer on an app he already knew.
With his usual iterative approach, without the generator (about 1,000 lines of code), the code review took him 15 minutes. The comparison isn’t randomized, and the author already knew the feature, so part of the difference is a learning effect. I treat it as an illustration of scale, not a norm.
The reference point is the reviewer’s attention budget. A large code review study at Cisco pointed to limits on the order of an hour and a few hundred lines per session. It’s a vendor study (SmartBear) and concerns code, not specs, but spec Markdown competes for exactly the same attention.
Measuring on Your Own Changes
A pilot needs only a spreadsheet kept for two weeks, on 5–10 changes, with five columns. That’s too small a sample for proof, but enough to see where the weight is off:
- quadrant of the matrix,
- spec writing time,
- spec review time,
- code review time,
- counterexamples stopped and let through.
Spec review that takes longer than code review in the none or note quadrant is a signal that the weight is too high or the change was misclassified. In the full quadrant, it’s an expected cost, provided the spec stops counterexamples that code review wouldn’t catch. It’s a team’s self-assessment, not a metrics program.
The criterion, the weight, the pruning, and the measurement fit together on a single sheet.
The Matrix and Four Templates to Copy
The matrix picks the weight, and discriminating power decides what goes into it. The templates below are skeletons: every normative field has a clause or a counterexample that justifies it, and the rest serve as a trail of decisions and verification.
"Your cart"
Why: link to the ticket
Not touching: cart logic and translations
How I checked: snapshot of the cart view
Ticket: link
# NOTE — 1 paragraph
Expected: WHEN … THEN …
Doesn't change: WHEN … THEN STILL …
Counterexample: the version this clause stops
# LIGHT — up to 1 page
Current (bug): WHEN … THEN …
Expected: WHEN … THEN … # counterexample + how to check
Unchanged: WHEN … THEN STILL … # counterexample + how to check
Total: 2–4 clauses, expected and unchanged
# FULL
Requirements: clauses with counterexamples
Design: invariants and module boundaries
Migration: migration and recovery plan
Decisions: references to ADRs, and at the highest risk a formal model” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
# NONE — 5 lines in the PR description
What I change: label "Cart" -> "Your cart"
Why: link to the ticket
Not touching: cart logic and translations
How I checked: snapshot of the cart view
Ticket: link
# NOTE — 1 paragraph
Expected: WHEN ... THEN ...
Doesn't change: WHEN ... THEN STILL ...
Counterexample: the version this clause stops
# LIGHT — up to 1 page
Current (bug): WHEN ... THEN ...
Expected: WHEN ... THEN ... # counterexample + how to check
Unchanged: WHEN ... THEN STILL ... # counterexample + how to check
Total: 2–4 clauses, expected and unchanged
# FULL
Requirements: clauses with counterexamples
Design: invariants and module boundaries
Migration: migration and recovery plan
Decisions: references to ADRs, and at the highest risk a formal model
# NONE — 5 lines in the PR description
What I change: label "Cart" -> "Your cart"
Why: link to the ticket
Not touching: cart logic and translations
How I checked: snapshot of the cart view
Ticket: link
# NOTE — 1 paragraph
Expected: WHEN ... THEN ...
Doesn't change: WHEN ... THEN STILL ...
Counterexample: the version this clause stops
# LIGHT — up to 1 page
Current (bug): WHEN ... THEN ...
Expected: WHEN ... THEN ... # counterexample + how to check
Unchanged: WHEN ... THEN STILL ... # counterexample + how to check
Total: 2–4 clauses, expected and unchanged
# FULL
Requirements: clauses with counterexamples
Design: invariants and module boundaries
Migration: migration and recovery plan
Decisions: references to ADRs, and at the highest risk a formal model
What to Take Into Your Next Review
What to take into your next spec review:
- A clause earns its place when you can name the wrong code it stops.
- You check discriminating power with counterexamples from an agent that sees only the spec.
- You pick the spec weight from the matrix before you open the tool.
- You prune by the clause–counterexample map: criteria, ADR, constitution, or trash.
- You measure spec overhead on your own changes and read it against the quadrant.
A spec for a risky data migration can be long without guilt, and a label change can do without a separate spec file. Both can be the smallest, as long as both are sufficient.
An Invitation to Test
Thank you for the time you’ve spent on two green diffs and one matrix. I have a practical request: run the prompt from the second section on one spec from your current sprint. Write in a comment how many clauses stopped no counterexample and which gap showed up first. I’m most interested in cases where the agent found a bug that no clause anticipated, because those will show where this method falls short.
If you want to see why part of a spec can be replaced with automatically verified facts, I wrote about that separately.


