Choosing Low-Cost Code Review Models and Controlling Hallucinations
This article explains how to evaluate low-cost models for auxiliary code review and keep hallucinations out of the review pipeline. It covers why secondary models need different evaluation criteria than frontier models, common failure modes such as misread version semantics, misinterpreted tool output, and confident factual fabrication, and a practical three-dimension scoring approach built on instruction following, tool-call correctness, and factual consistency. It also includes a fixed sample set design, an automated grounding score script, regression gating in CI, and engineering controls like stronger context injection, structured output, dual-model confidence gating, and observability. The goal is to assign a compliant but less capable model to retrieval, formatting, and first-pass screening while reserving high-quality reasoning for real decision points.
1. The Problem: Once Cheap Models Enter the Review Pipeline, the Evaluation Criteria Must Change
Over the past year, many teams have noticed fluctuations in the service quality of their primary coding models: with the same prompts and the same repository, output quality can vary more across time periods than it does when switching models. A natural response is to introduce lower-cost models to handle part of the parallelizable auxiliary work, such as self-checking a changeset, suggesting naming and readability improvements, and flagging test coverage gaps, while the primary model makes the final call.
But the evaluation logic for these “second-tier models” is completely different from that of the primary model. The primary model is judged by its ceiling: can it generate a cross-module refactor in one pass? An auxiliary model is judged by the stability of its floor: will it fabricate information, ignore instructions, or misread tool output? In a review pipeline, a mediocre model that strictly follows constraints often produces more useful output than one that is occasionally impressive but frequently invents facts.
When evaluating this kind of model, the focus should therefore shift from “how smart it is” to three observable metrics:
- Instruction following: whether it works within the specified role, output format, and review scope, and whether it expands the change surface without authorization.
- Tool-call correctness: whether arguments are valid and whether it correctly parses structured results returned by commands.
- Factual consistency: whether the version numbers, file paths, and symbol names it cites can be verified against the current repository state.
2. Real Pain Points: Low-Grade Mistakes and Unacceptable Hallucination
2.1 Basic Factual Errors: Reading Version Semantics Backward
A typical failure scenario is this: the model reads a release version number from the project documentation, then suggests “upgrading” to the snapshot version in the build script, with no understanding that a snapshot version represents an unreleased development state. This kind of error exposes not a knowledge gap but a lack of symbolic semantic reasoning: the model has not built the basic common-sense model that release and development versions are irreversible in the lifecycle.
In a review setting, the damage is amplified: reviewers default to assuming “the model at least read the text correctly,” so a single wrong suggestion directly consumes manual verification time and contaminates the context of subsequent conversation.
2.2 Misread Tool Output: Structured Results Treated as Natural Language
Auxiliary review relies heavily on data returned by command-line tools and platform APIs, such as diff summaries, commit history, and continuous integration results. Common failures include treating a non-zero exit status as success, treating the first page of paginated results as the full set, and treating warning messages as the root cause of an error. Once the tool layer is misread, all downstream reasoning rests on false premises, and the model usually does not doubt itself.
2.3 High-Confidence Hallucination: The Real Cost in the Review Pipeline
Insufficient intelligence is tolerable; confidently asserted fabrication is not. The value of a review task comes from signal-to-noise ratio: if two or three out of ten comments are invented method calls or nonexistent configuration items, the reviewer must verify each one, and the cost ends up higher than reading the code directly. The correct role for such a model is not “reviewer” but “retrieval and formatting assistant.”
3. A Practical Model Selection and Evaluation Plan
3.1 Build a Fixed Sample Set
Draw 30–50 completed historical changes from your own repositories, covering four scenarios: purely new features, defect fixes, dependency upgrades, and configuration or build script changes. Pre-label the “real existing issues” in each sample as the denominator for recall.
3.2 Three-Dimension Scorecard
| Dimension | How to observe | Suggested weight |
|---|---|---|
| Instruction following | Whether it modifies beyond scope, whether it follows the output format | 30% |
| Tool calling | Argument validity rate, output parsing accuracy | 30% |
| Factual consistency | Proportion of cited entities that can be found in the repository | 40% |
Factual consistency can be measured automatically, which makes it the highest-value part of the whole approach:
import redef grounding_score(review_text: str, repo_index: set[str]) -> tuple[float, list[str]]:# Extract the paths and symbols cited by the model and check whether they actually existrefs = set(re.findall(r'[\w./-]+\.(?:java|kt|py|ts|gradle|kts)', review_text))refs |= set(re.findall(r'\b[A-Z][A-Za-z0-9]{3,}\b', review_text))missing = sorted(r for r in refs if r not in repo_index)total = max(len(refs), 1)return 1 - len(missing) / total, missing
A model whose score falls below the threshold should not enter the automated review stage, regardless of how it performs on the other dimensions.
3.3 Regression-Based Evaluation
Connect the sample set and scoring script to continuous integration to form a regression gate for model changes. Updates on the model service side often come without announcements; only regression data can tell you why a model that worked yesterday starts talking nonsense today.
4. Engineering Controls for Hallucination Suppression
4.1 Make Context Supply Solid
Most factual errors come from missing context rather than model defects. Before review, explicitly inject the change diff, the full text of affected files, the dependency list, and the project’s version and branch conventions. When context is insufficient, require the model to output “insufficient information” instead of guessing.
4.2 Use Structured Output to Compress Room for Free Play
{"findings": [{"file": "src/main/java/.../Cache.java","line_hint": "L42-L58","issue_type": "concurrency | nullability | resource_leak | readability","evidence": "must cite a code snippet that actually exists in the repository","confidence": "high | medium | low"}]}
Requiring the evidence field to be searchable is the key to turning “confidence” into “verifiability”; entries that cannot provide evidence are discarded outright.
4.3 Dual-Model Cross-Check and Confidence Gating
Have the low-cost model produce candidate comments, and pass only high-confidence entries that pass the grounding check to the primary model for review; low-confidence entries go into a manual pool. This controls cost while preventing wrong comments from contaminating the primary model’s context.
4.4 Observability Support
Write prompt versions, model identifiers, scoring results, and human adoption rates into a unified logging service, and set quality-drop thresholds with monitoring and alerting. If your organization uses a cloud platform’s container service to run evaluation jobs and object storage to keep sample sets and reports, isolate evaluation artifacts from the online inference pipeline so they do not interfere with each other.
5. Conclusion
Low-cost models are not necessarily “the cheaper, the less worthwhile”; the key is to place them in a stage that matches their capabilities. Quantitative evaluation centered on instruction following, tool calling, and factual consistency, combined with context completion, structured constraints, and confidence gating, allows a model that is “not smart but obedient” to reliably handle retrieval, formatting, and first-pass screening, leaving scarce high-quality reasoning compute for the decision points that truly require judgment.
