Evaluating LLM Code Review Reliability: A Reproducible Framework

    Code review is a high-risk use case for large language models because the model must understand the intent of a change, locate potential defects, and produce conclusions that developers can verify against the code. This article presents a practical framework for evaluating reliability across six dimensions: code understanding, instruction following, tool use and output interpretation, factual accuracy and hallucination, version and convention understanding, and confidence calibration. It explains how to build reproducible evaluation sets with planted defects and no-defect samples, how to define precision, recall, and hallucination rate, and how engineering controls can reduce false positives and fabricated conclusions. It also discusses cost trade-offs through cost per valid finding and layered review strategies.

    1. Why Code Review Is a High-Risk Scenario for Models

    Code review requires a model to do three things at the same time: understand the intent of a change, locate potential defects, and give conclusions that developers can verify. A failure at any stage creates cost. A missed defect can enter the main branch. A false positive consumes reviewer time. A fabricated conclusion is worse because it can lead developers to modify code that was already correct.

    Therefore, evaluating a code review model should not focus only on whether its answer is fluent or sounds expert-like. The key question is whether its conclusions can be verified by the code itself. A confident conclusion that contradicts the code is far more harmful than an answer that explicitly states that the model cannot determine the issue.

    2. Breaking Down the Evaluation Dimensions

    It is recommended to evaluate models across the following six dimensions.

    1. Code understanding. Can the model correctly describe a function’s inputs and outputs, control flow, and data flow? Ask the model to restate the change first, then compare that restatement with human annotations. Restatement errors usually mean that subsequent review conclusions are unreliable.

    2. Instruction following. Teams often set output formats, scope, and prohibitions for review tools, such as “only report security issues” or “do not modify files.” Whether the model strictly follows these constraints directly determines whether it can be used in automated workflows.

    3. Tool calling and output interpretation. Many review workflows ask the model to call version control, build, or query commands and then answer based on the returned results. Evaluation should check whether the model selects the right tool, passes the right arguments, and accurately interprets tool output. Typical failures include misreading a status code as success or ignoring warning fields in the output.

    4. Factual accuracy and hallucination. Hallucination means that the model states something inconsistent with the code or documentation, such as referencing a nonexistent function, inventing a configuration item, or misjudging version semantics. During evaluation, each conclusion should be broken into verifiable assertions and checked one by one.

    5. Version and convention understanding. Dependency version numbers, prerelease identifiers, and semantic versioning rules are common knowledge. If a model misjudges this type of content, it may give guidance in the wrong direction in scenarios such as “upgrade recommendations.” These errors may appear minor, but they strongly reflect how well the model understands engineering conventions.

    6. Confidence calibration. A good model states when evidence is insufficient and provides a verification method. A poor model is equally confident in wrong conclusions. Calibration can be measured by mixing no-defect samples into the evaluation set.

    3. Building a Reproducible Evaluation Set

    The evaluation set is the foundation of the entire framework. The following principles are recommended.

    • Use real historical changes and manually plant known defects into them, such as null pointer dereferences, unreleased resources, concurrency races, and out-of-bounds access. Record the category of each planted issue as the ground truth.
    • Keep a portion of no-defect samples to measure the false positive rate.
    • Cover multiple languages and frameworks so that the model does not perform well only in familiar scenarios.
    • Fix the context for each sample, including dependency versions, project convention documents, and tool return content, so that results from multiple runs are comparable.
    • Update samples regularly to prevent the evaluation set from losing discriminative power after being included in training data.

    4. Metric Definitions and Calculation

    The following example shows how to calculate precision and recall.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class ReviewCase:
    4. diff: str
    5. planted_issues: set[str] # Manually planted defect categories
    6. def score(findings: set[str], case: ReviewCase) -> tuple[float, float]:
    7. tp = len(findings & case.planted_issues)
    8. fp = len(findings - case.planted_issues)
    9. fn = len(case.planted_issues - findings)
    10. precision = tp / (tp + fp) if tp + fp else 0.0
    11. recall = tp / (tp + fn) if tp + fn else 0.0
    12. return precision, recall

    The hallucination rate can be defined as “the proportion of assertions that cannot be verified.” The following function checks whether symbols referenced by the model exist in the code repository.

    1. def unsupported_claims(claims: list[dict], repo_symbols: set[str]) -> list[dict]:
    2. """Return claims that reference symbols not present in the repository."""
    3. return [c for c in claims if c["symbol"] not in repo_symbols]
    4. def hallucination_rate(claims: list[dict], repo_symbols: set[str]) -> float:
    5. if not claims:
    6. return 0.0
    7. return len(unsupported_claims(claims, repo_symbols)) / len(claims)

    When interpreting the metrics, keep three points in mind. Low precision means many false positives, so the team must spend time screening them. Low recall means many missed defects, so automated review cannot replace human review. Hallucination rate should be considered together with confidence; a high hallucination rate combined with high confidence is the most dangerous combination.

    5. Engineering Practices to Reduce False Positives and Hallucinations

    Even after selecting an appropriate model, engineering-level constraints can significantly reduce risk.

    • Require each conclusion to include a file path and line number. Discard conclusions that cannot be located.
    • Run automated checks on verifiable assertions, such as whether a symbol exists, whether a path is valid, and whether a command actually returned the claimed result.
    • Restrict tool permissions. Review workflows should be read-only by default, and write operations must require human confirmation.
    • Explicitly allow “uncertain” as a valid output in the prompt, and require the model to list the assumptions that need human verification.
    • Perform secondary sampling on conclusions. Run the same change multiple times and keep only findings that are consistent across runs.

    6. Capability and Cost Trade-offs

    Model selection should not be based on unit price alone. A model with a low unit price but a high false positive rate will create higher costs in reviewer time. It is recommended to compare options using “total cost per valid finding,” calculated as model invocation cost plus the time cost of human screening for false positives, divided by the number of confirmed valid defects.

    In addition, a layered strategy can be used. Low-cost models handle broad initial screening, high-capability models process only the difficult samples that remain after screening, and humans make the final confirmation on high-risk changes.

    7. Conclusion

    The key to evaluating code review models is to turn subjective impressions into reproducible measurements. Only by using an evaluation set that covers multiple dimensions, clearly defining precision, recall, and hallucination rate, and combining these metrics with engineering constraints can you obtain trustworthy conclusions. A single experience can serve as a clue, but it should not be the basis for model selection.