Same pull request, two verdicts: "flag bad code" is not a criterion

Owen Brandt runs his team's CI reviewer on the same pull request twice, as a test. Nothing about the code changes. Nothing about the prompt changes. Run one comes back: "Block. Unsafe code." Run two comes back: "Approve."

The prompt only said: "Flag bad code."

The same split shows up in invoice extraction. One run takes the due date as the invoice date, the next takes the issue date. Nadia Okafor, the head of support, states the cost plainly: a tool that disagrees with itself gets ignored. Developers mute the reviewer, finance rechecks every invoice by hand. The model is not the problem. The prompt is.

"Flag bad code" is a wish, not an instruction

A vague instruction forces the model to invent its own standard on every run. One run counts style as bad. The next does not. One run treats a test file like production code. The next ignores it. The model is guessing, because you gave it nothing to check against.

Think of a referee's rulebook. "Play fair" gives a different match every week, because every referee's idea of fair differs. "A tackle from behind is a foul" gives the same call most weeks. The rule names the act, and anyone can check whether it happened.

Criteria are the law. Examples are past rulings. Together they make verdicts predictable.

Three parts to a real criterion

Explicit criteria name three things.

First, defect classes. The exact problems to flag: SQL built by string concatenation, secrets in code, missing error handling on a payment call. The named thing, not "security problems".

Second, a severity threshold. Which classes block a merge, and which only earn a comment. A missing error handler on a payment call blocks. The same gap on a logging call gets a comment.

Third, an ignore list. What never to flag: naming style, fake data in test files. Without the ignore list, the reviewer invents one, differently each time.

Then make each criterion checkable: a yes or no test per line or per field. "Watch out for security problems" has no test and no boundary. "Block if a password, token or API key appears as a literal string. Ignore values from environment variables" has one. The invoice extractor needs the same treatment. "Extract the date" becomes: "Return the issue date labelled Invoice Date. Never return the due date. If none appears, return null instead of guessing."

Measure before you celebrate

A fix counts only if it is measured. Take a fixed set of past pull requests where humans agreed the right verdict. Run the old prompt, count false positives. Change the prompt, run the same set, count again. Without the before number, "better" is a feeling.

The chapter's worked example does exactly this, on 200 past pull requests with 26 real blocking defects. The counts are made up; the shape of the result is the point. Round one, the vague prompt, flags 68 pull requests: 24 real defects, 44 false positives. Precision is about 35 percent. Two of every three flags are noise.

Round two adds explicit criteria. Same 200 pull requests, 34 flags: the same 24 real defects, 10 false positives. Precision: about 71 percent.

Round three adds three few-shot examples. The reviewer flags 29: 24 real, 5 false positives, precision about 83 percent. The examples removed 5 more, mostly fake secrets in test files. Missed real defects stayed at 2 in every round, so the fix cut noise without hiding real problems.

Examples pin down what rules describe badly

A few-shot prompt includes a few input and output pairs before the real input. The model copies the pattern: output shape, labels, level of detail, and how borderline cases were decided. Some decisions are easier to show than describe.

One example showing "Verdict: BLOCK, Class: secret in code, Line: 42" teaches the exact shape faster than a paragraph on formatting. A fake password in a test file, shown as "Verdict: IGNORE", settles a case rules argue about. An invoice example pairing two dates with the issue date teaches which date wins.

It works like showing a new hire three past invoices and how each was filed: the pattern lands faster than the manual. But the examples have one hard rule: they must agree with the criteria and with each other. If criteria say test files are ignored, no example may block on one. Two similar inputs with opposite verdicts teach that either answer is fine. A contradictory example teaches the contradiction; the model cannot tell which signal was the typo.

Spend examples on hard cases, not easy ones: the fake secret, the two-date invoice, the payment call with partial error handling. A few sharp examples beat twenty mixed ones, and cost fewer tokens per run. Before shipping, read the examples against the criteria one by one. Any clash means fix one of them, never ship both.

The traps to avoid

More rules instead of clear rules. A page of vague rules is still vague. Fewer criteria, each with a yes or no test, beats a long list of wishes.

Examples that contradict the criteria. The model learns the clash. Audit every example against every criterion first.

Easy examples. They teach what the model already knows. Spend them on borderline calls.

Declaring victory without counts. "It feels better" is not evidence. Same test set, before and after numbers.

One honest limit: examples guide, they do not guarantee format. For guaranteed structure, use schemas.

In production, teams keep a small labelled test set for each prompt, a few dozen past cases with agreed answers, and rerun it after every prompt edit. A change that helps one case and breaks two others shows up in the counts first. The prompt is a product, the test set is its spec, and the false positive count is the scoreboard. "Flag bad code" never had a scoreboard, which is why it could say block on Monday and approve on Tuesday and nobody could prove it wrong.

The full interactive chapter is free at https://deployedlab.dev/lessons/cca-17-explicit-criteria-few-shot, with a hands-on lab where you rewrite the vague CI reviewer prompt yourself. 79 chapters are free with no signup, and the full bundle is $5 a month or $39 a year at deployedlab.dev.