Sub topic 13
Using AI as a Second Reviewer, with Limits
This chapter assumes you can read a Git diff, write unit tests, and have used an AI coding assistant. It also assumes you know the earlier steps of this tutorial: checking intent, reading the diff, and gathering evidence with tests and static analysis.
A second AI pass can find problems you missed. It cannot prove that the code is correct. This chapter covers how to use it and where it stops being useful.
What a second AI pass is good for
An AI reviewer reads fast and does not get tired. It is useful as a prompt for your own attention. It can:
- Point out suspicious lines you skimmed past.
- Suggest edge cases to test, such as empty input,
None, or very large values. - Flag patterns that often cause security bugs, such as string-built SQL.
- Explain unfamiliar code so you can judge it.
- Notice mismatches between a docstring and what the code does.
Treat every finding as a lead. A lead becomes a fact only after you confirm it by reading the code or running something.
Why it cannot be proof
The reviewer is a model, and it shares weaknesses with the model that wrote the code.
- Correlated blind spots. If the same model or a similar one wrote and reviewed the code, both may hold the same wrong belief about an API or a security rule. Agreement between them is weak evidence.
- Plausible approval. A model often finds the code reasonable because it resembles code the model would write. "Looks good" costs the reviewer nothing and tells you little.
- False positives. The reviewer may report bugs that do not exist, and may even invent a fix that introduces a real bug.
- Missing context. The reviewer sees only what you paste. It does not know your deployment, your data, your other services, or the requirement in your head.
- No execution. Unless it runs the code, it reasons about behavior without observing it.
A review that produced no complaints does not show the code is safe. It shows that one model, given limited context, found nothing.
Where it fits in the process
Run the AI review after your own first pass and after the cheap automated checks. That order keeps your judgment from being anchored by the model's opinion, and it keeps the model from wasting time on problems a linter would catch.
The loop matters. Each lead the AI raises should end in either a test, a code reading that settles it, or a decision to dismiss it with a reason.
Writing a useful review prompt
A vague prompt such as "Is this code OK?" invites a vague answer. Give the reviewer a role, the requirement, the diff, and a list of failure modes to check. Ask for evidence tied to line numbers.
You are reviewing a diff as a skeptical senior engineer.
Requirement:
The function must return the average of a list of numbers and reject
invalid input with a clear error.
Review the diff below for:
1. Behavior that does not match the requirement.
2. Edge cases: empty input, None, wrong types, very large inputs.
3. Imports or function calls that may not exist in the library version used.
4. Security problems: injection, hardcoded secrets, missing validation.
5. Anything outside the requirement that the diff changes.
For each finding, give the file and line, explain why it is a problem,
and give a concrete input that would trigger it. If you are unsure,
say so. Do not report style preferences.
Diff:
<paste output of git diff here>Three parts of this prompt do real work:
- The requirement lets the reviewer check intent. Without it, the reviewer can only judge whether the code is internally consistent.
- A concrete triggering input makes each claim testable. A finding with no input is hard to verify and often turns out to be wrong.
- Permission to be unsure reduces confident guessing.
Turning findings into evidence
Take a finding and convert it into something that runs. Suppose the reviewer says the average function fails on an empty list. Do not just accept the claim. Reproduce it.
def average(values):
return sum(values) / len(values)
try:
average([])
except ZeroDivisionError as exc:
print("Reproduced:", exc)Running this prints Reproduced: division by zero. Now the lead is a fact, and you can write the test that keeps it fixed.
import pytest
def average(values):
if not values:
raise ValueError("values must not be empty")
return sum(values) / len(values)
def test_average_of_empty_list_raises():
with pytest.raises(ValueError):
average([])The same step applies in the other direction. If the reviewer claims a bug and you cannot reproduce it, write down why, and move on. A claim you cannot reproduce is not a reason to change working code.
Handling a finding you cannot verify
Some findings are hard to check, such as "this may race under concurrent writes." Use a short decision rule.
| Situation | Action |
|---|---|
| You can reproduce it with a test | Fix the code and keep the test |
| You can show by reading that it is wrong | Fix the code and note the reasoning in the pull request |
| You can show it is impossible in your context | Dismiss it and note why |
| You cannot decide either way | Treat it as open risk: simplify the code, add a guard, or ask a colleague who knows the area |
Do not accept a change with an open high-severity lead just because the AI later said it was fine. Asking again until the answer changes is not verification.
Reducing correlated blind spots
You can make the second pass more independent.
- Use a different model or a fresh session. A fresh session has not seen the author's reasoning, so it cannot simply echo it.
- Do not paste the author's explanation. Give the reviewer the requirement and the diff, not the argument that the diff is correct.
- Review one concern at a time. One pass for security and another for edge cases often finds more than a single broad request.
- Ask for a failing input first. "Give me an input that breaks this" pushes the model toward attack, not approval.
Letting the AI review the tests too
Tests written by the same assistant that wrote the code can share its mistakes. If the code misreads the requirement, the tests may encode the same misreading and pass. Ask the reviewer to check the tests against the requirement, not against the code:
- Does each requirement have at least one test?
- Do the tests assert behavior, or do they only repeat the implementation?
- Would any test fail if the main logic were deleted or reversed?
You can check the last point yourself. Break the code on purpose, for example by changing + to -, and confirm that a test fails. This is a small form of mutation testing, and it shows whether the tests would notice a real defect.
Common mistakes
- Treating "no issues found" as approval. Absence of findings is not evidence of correctness.
- Re-prompting until the answer is favorable. If you ask five times and keep the one that approves, you have measured your own persistence.
- Applying suggested fixes without a diff. A reviewer's patch is new AI-generated code. It needs the same review as the original.
- Skipping your own read. If you do not read the diff first, you cannot tell a good finding from a bad one.
- Letting the review grow the change. Reviewers often suggest refactors. Accept only what the requirement needs, and put the rest in a separate change.
What to record
When you accept a change after an AI review, leave a short note in the pull request: what you asked the reviewer, which findings you verified, which you dismissed and why, and which tests you added. This lets the next person see what evidence exists and what rests on judgment.
Exercise
An AI reviewer examines a diff and replies, "The code looks correct and follows best practices." Your tests pass. Can you accept the change on that basis? What would you do next?
Show answer
Not yet. The reply is a weak signal because it names no requirement, no edge case, and no line. Passing tests only cover the cases someone thought to write. Next, re-run the review with the requirement and a list of failure modes, ask for a concrete failing input, and use a fresh session or a different model. Then check that the tests cover each requirement and fail when you break the logic on purpose, and read the diff yourself for dependency, security, and scope problems. Accept only when your own checks support the decision.
Exercise
A reviewer reports: "parse_config crashes when the file is empty." You cannot tell whether that is true by reading. List the steps you take before changing any code.
Show answer
Write a small test that calls parse_config with an empty file, using the reviewer's described input, and run it. If it fails, you have reproduced the bug, so fix the code and keep the test. If it passes, the claim was a false positive, so record that and leave the code alone. Do not edit the code first and then decide whether the problem was real.