Back to Coding

How Do You Use AI to Review a Diff?

How Do You Use AI to Review a Diff?
AI Tutorials Team 7 January 2026

Handing a diff to an assistant and asking what it thinks produces a predictable response: some observations about naming, a suggestion to add comments, a note about error handling, and a closing remark that the code looks good overall. None of that is a review.

Why is the default output so weak?

Because the request is open-ended and the safest response to it is a survey of general good practice. Nothing in a bare request tells the model what matters here, what the code is for, or what a serious problem would look like in this context.

It is also drawing on an enormous quantity of published review commentary, most of which is about style, because style is what people write about.

What does a useful request contain?

  • The purpose of the change. What it is meant to do.
  • What to look for. Named categories rather than a general request.
  • What to ignore. Style, formatting, naming, unless you want them.
  • The surrounding context. The functions being called, not only the changed lines.
  • What matters here. Correctness, performance, security, or all three.

What is the prompt?

This change is meant to [purpose]. Review it for correctness only: logic errors, incorrect conditions, unhandled cases, and anything that behaves differently from what the change is meant to do. Ignore style, naming and formatting entirely. For each finding, give the line, what is wrong, and what would happen at runtime. If you find nothing, say so rather than listing minor observations.

Why permit an empty result?

Because otherwise you always get findings. A model asked to review will produce a list regardless of whether anything is wrong, and once a review consistently contains three trivial items, people stop reading it.

Explicitly allowing nothing found is what makes the findings mean something.

Why does the diff alone fail?

Because a diff shows what changed and not what it interacts with. A changed line that now returns a different type is fine in isolation and breaks three callers you did not include, and the model cannot know that.

Supplying the whole file, and the definitions of anything the change calls, produces a substantially better review than the diff by itself.

Should you run it on the diff or the file?

Both, for different things. The diff focuses attention on what changed, which is where new bugs are. The full file catches consistency problems and cases where the change contradicts something elsewhere.

Where the change is small and the file is large, the diff plus the surrounding function is usually the right amount.

How many findings should you expect?

Few. A well-configured review on a small change should frequently return nothing, and a review returning eight items on twenty lines is producing noise rather than signal.

What should you do with the output?

Verify each finding before acting on it. Reviews contain confidently stated problems that are not problems, and a suggested fix that resolves an imaginary issue can introduce a real one.

Should the review see the commit message?

Yes, and it is the cheapest context available. A commit message stating what the change is meant to do supplies the intent that turns a general quality assessment into a check against a standard.

It also exposes a useful mismatch. Where the message describes one thing and the diff does another, that is a finding in itself, and it is one of the few requirement-level problems an automated review can actually catch, since both halves are in front of it. Teams that write thin commit messages lose this entirely, which is a small argument for writing better ones.

What is this actually for?

Catching the things a tired human reviewer skims past, before the human reviewer sees it. It is a first pass rather than a replacement, and treating it as the second opinion rather than the only one is what makes it worth having.