AI-Assisted Code Review with LLMs: Practices and Limitations
This article explains how large language models can support code review, where they reliably add value, and why their findings often turn out to be false positives. It covers four tasks LLMs handle well, a practical review workflow with context preparation and prompt structure, guidance on deciding whether a paid plan is worthwhile based on actual usage intensity, and a list of common mistakes to avoid. The core takeaway: LLMs surface easily missed combination conditions, boundary cases, and contract drift earlier, but human confirmation and a test regression loop remain essential.
1. First, a correction: code that runs only proves “it didn’t crash on this one set of inputs”
Many teams treat “it starts and throws no errors” as a quality signal. This is one of the easiest ways to hide risk. Real defects often do not surface as exceptions; they silently return a result that looks reasonable.
Three scenarios are typical:
- Uncovered condition combinations: a coupon works correctly on its own, a spend-threshold discount works correctly on its own, but when the two are stacked, any mishandling of the discount base, allocation order, or upper limits shifts the final amount.
- Boundary and calendar issues: month-end, leap years, cross-timezone cases, and daylight saving transitions stay invisible most of the time and only surface on specific dates.
- Cross-module contract drift: one place renames a field or changes a data format while another still reads the old structure. Each file looks fine in isolation; the problem appears only after integration.
Illustrative code (the problem is not syntax, but rule precedence):
def calc payable(subtotal, coupon, full_reduction):amount = subtotal - coupon.amountif amount >= full_reduction.threshold:amount -= full_reduction.valuereturn max(amount, 0)
This code runs fine, but it never defines business rules such as “does the threshold discount apply before or after the coupon,” “does a discount change the threshold for the spend-based discount,” or “how is the discount allocated across multiple items.” The result therefore depends on implicit assumptions made by the caller.
2. Four tasks LLMs are genuinely good at in code review
Treat the model as a tireless second pair of eyes, not an authoritative judge. The clearest gains come from:
- Obvious defect scanning: misused variables, inverted conditions, unhandled nulls, swallowed exceptions, unreleased resources, abnormal values returned at boundaries.
- Context correlation: when given several related files, identifying field renames along the call chain, changed return structures, and inconsistent exception contracts.
- Intent restatement and back-inference: asking the model to explain in its own words what a function does and who a change affects. People often spot problems precisely where the restatement does not match.
- Test case suggestions: generating a list of cases to add for boundary conditions, condition combinations, idempotency, and concurrency.
One key limitation must be stated clearly: pasting a snippet into a chat window and having a tool read an entire repository are two different capabilities. Files the model cannot see, the runtime environment, configuration, production data distribution, and business rules cannot be filled in by guessing. When using an AI coding tool with project-level read access, first confirm the actual file scope it can reach and the scope of tests it can execute.
3. Why “the AI says there’s a problem” is often a false positive
The situation described in the original text is very common: the model flags that a function does not validate its input, when in fact the function only receives data already validated upstream. False positives usually trace back to four causes:
- Missing invariant information: upstream guarantees, database constraints, and framework validation are omitted.
- Missing business rules: discount stacking, tax calculation, and the order of inventory deduction are domain knowledge.
- Missing runtime context: framework version, middleware behavior, and configuration switches are unknown.
- Over-generalized advice: models tend to suggest “more defensive” code, which can introduce redundant validation and performance overhead.
So the division of labor should be: the AI proposes hypotheses; the human confirms or refutes them. Treat every finding as an issue to be verified, not as a change to apply directly.
4. A review workflow you can actually adopt
- Prepare a context package: relevant files, interface definitions, data models, key configuration, failure logs, and the requirement description.
- Ask in layers: first request a “behavior restatement,” then a “risk list (with trigger conditions),” and finally “minimal reproduction inputs and test cases.”
- Enforce an output format: require each issue to include location / trigger condition / impact / suggested verification, so items can be closed one by one.
- Wire in automation: put static analysis, type checking, unit tests, coverage, and contract tests in the pipeline; model output serves only as a supplementary clue.
- Close the regression loop: after a fix, add a test that reproduces the original problem to prevent silent defects from recurring.
Example prompt skeleton:
You are a code review assistant. Answer based only on the file contents I provide, and explicitly write "insufficient information" when information is missing.Output a table: Location | Trigger Condition | Possible Impact | Verification Method | Confidence (High/Medium/Low).Do not mention interface names or configuration items that were not provided.
5. Whether to pay for a subscription: decide by usage intensity, not hype
Suggested criteria:
- Frequency and session length: multiple times a day, long contexts, cross-file analysis — paid quotas and higher concurrency usually pay off; once a week occasionally — the free quota is enough.
- Context length and codebase size: when whole-repository understanding is needed, long context and project-level read access are what matter; first check whether the free quota hits its limit.
- Team compliance: in enterprise settings, prioritize manageable permissions, commitments that data is not leaked, and audit and logging capabilities. These can be assembled from general offerings such as the model service categories from cloud providers plus log services and monitoring/alerting.
- Cost comparison: convert the subscription cost into “review hours saved + production defects avoided.” If a deep analysis is not triggered even once in a month, there is no need to pay.
Practical advice: run the workflow on the free quota for two weeks first, count how often you hit the limit and what the real benefit is, then decide whether to upgrade. For teams, a combination of “a few paid seats + internal prompt guidelines + an automated pipeline” is more controllable than enabling everyone.
6. Common mistakes
- Treating model conclusions as final and skipping human confirmation;
- Pasting only a snippet yet expecting cross-module conclusions;
- Describing requirements in natural language without providing data structures and constraints;
- Letting the model change code directly without adding tests;
- Putting sensitive data, keys, or customer information into the context.
7. Conclusion
The value of large models is not replacing review, but surfacing “easily overlooked condition combinations, boundary cases, and contract drift” earlier. Making capability boundaries explicit, standardizing how context is supplied, insisting on human confirmation and a test regression loop, and then choosing a paid tier based on real usage intensity is the most reliable path for everyday developers.
