Building Trustworthy Evals for AI Code Review

Over the last couple of months, I have been working on building evals for an AI code reviewer at work. It’s a complex multi-agent system. It reads a pull request and hands it to a set of expert sub-agents (security, performance, UI and so on). Then it fact-checks what they raise, merges duplicates and posts comments on the PR. One review takes around ten minutes and a few hundred model calls.

This post is about the learning experience I have had along the way, hoping it will help others when they try to build Evals for Agents at work. It covers how to build your own benchmark for an LLM system and how to keep it honest as the system and the data change. The examples here come from a code reviewer, but most of it applies to any agent that produces open-ended text.

Note: I used AI to help with parts of this post. I rounded all numbers and left out anything specific to my employer.

Evaluating a code reviewer

A few things make a code reviewer harder to evaluate than a simpler system like a classifier.

First of all, there is no single right answer. Two (good :p) human reviewers will leave different comments on the same PR, and both can be useful. Deciding whether a comment “caught” a bug needs judgement. The agent is nondeterministic, so two reviews of the same PR give two different sets of comments.

A reviewer that flags every line would find every bug and still be useless, because nobody reads it. Classic “If everything is an issue, you have 100% recall but high noise since an author now has 20 comments to look at.” You need to take all of the above into account while writing evals for a code reviewer.

Part 1: Building your own benchmark

Here is one eval run from start to finish. The rest of the post breaks it down piece by piece.

One illustrative eval run. The harness builds the agent at a commit and gives every benchmark PR its own container. Review C times out and counts as a miss. The gate reruns C on the branch and on main before it reports red. Names and values are examples.

Starting from a decision

We started with about a dozen handpicked PRs, each with expected issues to be found in the PR. For every change, we were running them on our machine whenever we had changes that could potentially impact the review quality. It worked well until we started expanding the agent to multiple repos and then needed more confidence before shipping.

I knew we needed different suites which were diverse in size, language, repos, issues to comprehensively cover the scenarios. One thing that helped curating those suites (called benchmarks), is asking what decision the benchmark will help us make, and what result would change that decision. Different decisions need different suites:

DecisionWhat the suite needs
Did this change make the reviewer worse?Cheap, repeatable, runs on every change
Is a cheaper model good enough?Real PRs, several trials, a pass bar written down beforehand
Can the reviewer approve PRs on its own?Clean PRs as well as buggy ones, and scoring for the final verdict

Choosing test data

We ended up with two kinds of benchmarks, used for different jobs.

Planted bugs. We had AI sub-agents write PRs against real repositories with bugs planted on purpose. Each PR also had decoys, code that looks wrong but is correct. Without decoys, “If everything is an issue…” blah blah blah. :D Planted bugs give you an exact answer key, and they are cheap to make and run.

Real PRs. Merged pull requests from our own repositories, with an answer key built from what people actually found (more on that below). These are slow and expensive to build, and much closer to the work the reviewer really does.

Planted bugs turned out to be easier than real ones. On the same model, the agent found around 64% of planted bugs and around 52% of real ones (that share of known bugs found is the agent’s recall).

Bar chart: the same agent found about 64% of planted bugs and about 52% of bugs in real PRs. Same agent, same default model: share of known bugs found. Approximate.

Building an answer key from real PRs

For real PRs we followed the ReviewBench methodology closely, and I highly recommend reading it if you are doing anything similar. The pipeline we built looks like this:

  1. Pick PRs by rule, before looking at any agent output.
  2. Snapshot what the reviewers saw. We used the PR iteration with the most comment threads, and judged every finding against the code at that commit. Then we replayed the PR as a fresh one, so the agent reviews the same diff without seeing the human comments.
  3. Collect findings from several sources:
    • human review threads
    • issues inferred from the author’s later fixes to the lines under review
    • two frontier models given a plain “review this PR” prompt
    • our own agent
  4. Merge duplicates and label. An LLM matched duplicates, then a fixed classifier prompt labelled each finding as real or not, with a severity. A human reviewed every disagreement plus a random 10% sample, and a human label always won.
  5. Keep only must-finds. A must-find is real, of medium or high severity, and covered by a review rule that the agent should apply. We left out findings that only our agent raised, so we didn’t grade it on its own answers.

A funnel: about 440 findings collected, about 280 after merging duplicates, about 200 judged real, about 95 of medium or high severity, about 80 must-finds. How one real-PR answer key shrank. Counts rounded.

Human reviewers found half of all real issues, but only about half of their comments were real issues (the rest were questions, nits and discussion). The author’s later fixes were the most precise source, about 9 in 10 real, but they covered just under a quarter of the issues. Each source missed things the others caught, and no single one found most of them. Which is where having five different issue finders helped us have enough coverage.

Bar chart of five sources. Human reviewers: 50% of real issues, 55% precise. AI reviewer 1: 45% of issues, 85% precise. Author's later fixes: 25% of issues, 90% precise. AI reviewer 2: 20% of issues, 75% precise. The agent itself: 5% of issues, 55% precise. Share of all real issues each source found, and how often its findings were real. From an earlier, larger answer key. Rounded to 5.

Public benchmarks for code review

A few public benchmarks for code review agents are worth knowing, both to compare against and to borrow methods from:

  • ReviewBench builds a human-validated answer key from real PRs and reports grounded and augmented precision and recall. The augmented scores give credit for valid issues the answer key didn’t have. Our real-PR pipeline borrows heavily from it.
  • Code Review Bench from Martian is a versioned “living” benchmark. It has an offline set of fixed PRs with curated golden comments, and an online arm built from public PRs. Its methodology document has a good survey of what makes benchmarking reviewers hard.
  • SWR-Bench is an academic benchmark of 1,000 manually verified GitHub PRs with full project context. An LLM grades each review by checking if it covers each known issue. It also includes PRs with no issues, so you can count false alarms.

Public leaderboards are a useful reference point. A score on one describes a single tool configuration, on one date, against one answer key and one judge. Compare two scores only when all four match. No public benchmark tells you how your agent does on your code with your review rules, so we built our own as well.

Freezing the environment

Every eval test case is run in a sandbox using the code reviewer agent and an image pinned to the PR commit. We use an agent image tagged with the commit it came from, so we can compare any two builds later, even after someone deletes the branch.

Grading with an LLM judge

For each PR, the judge reads every known bug and decoy, plus everything the agent posted. Then it decides, for each bug, if a comment raised it. We started with three votes per bug. A five-vote check showed the judge was almost always unanimous, so we moved to a single call per PR. When we re-graded hundreds of old reviews this way, the set of found bugs changed in about 3 to 4% of them.

A few rules made the judge trustworthy enough to gate on:

  • If the judge fails, the PR scores zero and the report marks it as failed. A broken judge must never raise a score.
  • Save the judge’s reason for every bug. Then, when someone asks why a bug counted as missed, the answer is already there.
  • Rewrite reference descriptions as one clear claim. A raw human comment like “Iteration 1 suggestion: hmm, what if this is null?” is a poor reference for a judge.
  • Test the judge on its own, with frozen positive and negative cases, before trusting it with a new model or prompt.

Results table

Every comparison we share uses the same table: one row per metric, one column per version, and the best value in each row highlighted. There are no deltas and no confidence intervals in this table. The statistics go underneath, for people who want them.

MetricVersion AVersion B
Recall (known bugs found)32%🟢 50%
Mean time per review🟢 10 min20 min
p90 time per review🟢 15 min35 min
Cost per review (index)100🟢 95
LLM calls per review100🟢 90
Comments posted per review🟢 4.14.6
Critical and high comments per review1.21.2
Words per sentence in comments🟢 1519

Illustrative values, not real results.

Part 2: Catching regressions

Measuring run-to-run noise

Measure this before you build a gate. We ran the same main-branch code on the same 20 planted-bug PRs eight times. Recall ranged from about 63% to 77%. Two of those runs happened on the same day and scored 72% and 63%.

Strip plot of eight runs of the same code on the same 20 PRs, with recall between 63% and 77%. Two runs from the same day are highlighted at 72% and 63%. Dashed vertical lines mark a first floor at 70% and the floor we derived from history at 60%. Recall of eight runs of the same main-branch code on the same 20 planted-bug PRs. Rounded.

Then we looked at individual bugs. Two runs of the same build disagreed on roughly 1 in 5 known bugs: one run found the bug and the other missed it. Two different versions disagreed about as often.

Grouped bars from two experiments. In the first, two runs of the same build disagreed on about 17% of bugs, and two different versions also disagreed on about 17%. In the second, about 20% for the same build and about 19% for two versions. Share of known bugs where two runs disagreed (found in one, missed in the other). Rounded.

So most version-to-version differences in a single run are noise. With one run against one baseline, we could only reliably detect a drop of about 10 points. With three trials per PR, compared PR by PR against pooled main-branch runs, we could detect about 5.

Our comparisons now default to real PRs with three trials. We get the confidence interval from a paired bootstrap over PRs. You resample the PRs many times, compare both versions on each resample, and read the interval off the spread. A difference counts only when that interval excludes zero.

Cheat sheet

Build

  • Write down the decision an eval serves, and the result that would change it.
  • Use planted bugs with decoys for cheap checks, and real PRs for decisions.
  • Build real answer keys from several sources, and leave your own agent out.
  • Run one container per review, and pin everything to commits.
  • Make the judge fail closed, save its reasons, and test it on its own.
  • Use one fixed results table for every comparison.

Catch regressions

  • Measure run-to-run noise before building a gate.
  • Run three trials per PR, and count a difference only when its interval excludes zero.

If you’re building evals for an agent of your own, I’d love to hear what’s worked for you. Feel free to share your experiences or tag me on X: @niketansrane.