Essay

Every review rule must be provable from the diff

Our automated AI code reviewer got useful the day we stopped letting it guess. The rules, the evidence requirement, and the filter that enforces it.

We run an AI reviewer on every pull request. The first version was noisy enough that people learned to scroll past it, which is worse than having no reviewer at all. The version we run now is quiet, specific, and mostly right. The difference was not a better model. It was one rule about evidence.

The problem with “please verify”

A reviewer that only sees a diff cannot see the method being called, the service being injected, or the class defined in another file. Left alone, a model fills that gap with caution: “Please verify that this endpoint checks permissions.” “Ensure the cancellation token is passed through.”

Every one of those comments asks the author to do the reviewer’s job. Multiply by twenty per PR and the signal is gone.

The evidence rules

The system prompt now opens with constraints on what counts as a finding:

  1. You can only see the diff. Flag a violation only when the violating code is visible and you can quote the exact added line that proves it.
  2. If proving it would require code outside the diff, do not flag it. Treat out-of-diff code as correct; it was reviewed when it was written.
  3. Never write a comment asking the author to verify, ensure, confirm or check something. If you cannot verify it yourself, say nothing.
  4. Only flag added or modified lines, never context lines.

Each finding comes back as JSON with a severity, a confidence, and a verbatim quote of the offending line. An error requires high confidence. Medium or low confidence gets downgraded to a suggestion or dropped.

Trust, then check

The model mostly follows those rules. Mostly is not good enough for something that can fail a build, so the script checks the output before posting anything:

  • If the quote does not actually appear in the diff, the finding is dropped. A model that cannot quote its evidence does not have evidence.
  • If the message contains the forbidden phrasing (“verify,” “make sure”), it is dropped. By definition it is an unproven finding.
  • A short list of rules can never fail the pipeline, no matter how the model phrases them. Those are downgraded to warnings before posting.

Writing rules a diff can prove

The other half of the work was rewriting our standards so that each rule is checkable from a diff at all. “Protect customer data” is a value, not a rule. The reviewable version is precise about scope:

Every endpoint that returns customer data must declare an access policy on the endpoint itself. Private helpers it calls inherit that policy and do not need their own.

That one clarification removed a whole class of false positives, because the model stopped flagging every helper method in the call chain.

The same pass made us honest about which rules are really errors and which are taste. Logging a raw request body can capture personal data, so it is an error. Preferring early returns over nested conditionals is taste, so it is a warning. Labeling severity forces the argument to happen once, in the rules file, instead of in every PR thread.

The general lesson

Agents are not careless; they are agreeable. Give one an open-ended mandate like “review this for problems” and it will find problems, real or not, because that is what you asked for. Constrain what counts as proof, then verify the proof mechanically. That pattern works far beyond code review.

All writing