Sub topic 14
A Reusable Review Checklist
This chapter assumes you can read a Git diff, write and run unit tests, and have used an AI coding assistant. It also assumes you know the failure modes from earlier chapters: hallucinated APIs, missed edge cases, outdated patterns, and insecure defaults. Here you combine them into one checklist you can run on every change.
Why use a checklist
Reviewers of AI-generated code tend to skip steps. The code is fluent and the tests may already pass, so the review turns into a quick skim. A checklist counters that in three ways:
- It makes the order of checks explicit, so you do not start with style and run out of attention before reaching security.
- It separates checks a tool can do from checks that need your judgment.
- It leaves a record. When something breaks later, you can see which check was skipped.
A checklist does not replace thinking. It stops you from forgetting to think about a particular area.
The checklist
Each item is a question you can answer yes, no, or not applicable. A "no" is not automatically a rejection, but you must be able to explain it.
| Area | Question | Evidence |
|---|---|---|
| Intent | Does the change do what the requirement says, and nothing more? | Requirement text next to the diff |
| Scope | Is the diff small enough to read fully? | `git diff --stat` |
| Dependencies | Does every new import and package exist, at a version you intend to use? | Package index page, lockfile diff |
| APIs | Does every called function exist with the signature used? | Official docs, type checker |
| Correctness | Are empty, null, boundary, and error inputs handled? | Tests you can name |
| Security | Is input validated, are queries parameterized, are secrets kept out of code? | Code reading, scanner output |
| Tests | Do the tests fail when the code is wrong? | A deliberate break, or a test that failed before the fix |
| Static checks | Do the linter and type checker pass with no new suppressions? | Tool output |
| Fit | Does it follow existing naming, error handling, and structure? | Comparison with neighboring code |
| Resources | Does it avoid unbounded loops, memory growth, and per-item network or database calls? | Reading, a quick measurement |
| Leftovers | Are there stray debug prints, commented-out code, or unrelated edits? | Hunk-by-hunk reading |
Keep the "Evidence" column in mind. A "yes" without evidence is a guess.
The order matters
Run the checks from cheapest and most decisive to most expensive. A change that fails the intent check should not get a detailed security review, because you may discard it anyway.
Let a script do the cheap part
The tool-based items need no judgment, so automate them. This script assumes your project uses ruff, mypy, and pytest. Substitute your own tools.
#!/usr/bin/env bash
set -euo pipefail
echo "== Files changed =="
git diff --stat
echo "== Lint =="
ruff check .
echo "== Types =="
mypy .
echo "== Tests =="
pytest -q
echo "Automated checks passed. Now read the diff."With set -e, the script stops at the first failing command, which is what you want. The last line is a reminder: passing tools is necessary, not sufficient.
For the human part, stage the change in pieces so each hunk gets a decision:
git diff
git add -pgit add -p shows one hunk at a time and asks whether to stage it. If you cannot explain a hunk, do not stage it.
A worked pass
Suppose the requirement says: "Add a function that returns the average of a list of order totals." The assistant produces this:
def average(values):
return sum(values) / len(values)Running the checklist:
- Intent. It computes an average. The requirement does not say what happens with no orders, so that is a gap to resolve, not an assumption to make.
- Scope. Three lines. Easy to read.
- Dependencies and APIs. Only built-ins. Nothing to verify.
- Correctness.
average([])raisesZeroDivisionError. That is an accident, not a decision. - Tests. None were provided.
You decide an empty list is a caller error and ask for a revision. The revised version pins that behavior:
import pytest
def average(values):
if not values:
raise ValueError("values must not be empty")
return sum(values) / len(values)
def test_average_of_numbers():
assert average([2, 4, 6]) == 4
def test_average_of_empty_list_raises():
with pytest.raises(ValueError):
average([])Now the "tests" item has evidence. To check that the tests can fail, temporarily remove the if not values guard and confirm that test_average_of_empty_list_raises fails. A test you have never seen fail is weak evidence.
The security item works the same way. When a diff builds SQL by string formatting, the checklist question "are queries parameterized?" gets a "no", and the fix is concrete:
import sqlite3
def find_user(conn: sqlite3.Connection, name: str):
# The driver treats name as data, not SQL.
return conn.execute(
"SELECT id, name FROM users WHERE name = ?", (name,)
).fetchall()Edge cases of the checklist itself
Tests written by the same assistant. If the assistant wrote both code and tests, they can share the same wrong assumption. Check that the tests encode the requirement, not just the current behavior. Write at least one test yourself from the requirement text.
Green tools, wrong change. Linters and type checkers do not know your intent. A change can pass everything and still implement the wrong feature. That is why the intent check comes first.
New suppressions. Look for added # noqa, # type: ignore, @pytest.mark.skip, or loosened config. Assistants sometimes make a failing check pass by silencing it. Treat each suppression as a hunk that needs a reason.
Lockfile changes. A one-line import can bring a large lockfile diff. Read the list of added packages, not just the source files.
Large diffs. If you cannot finish the checklist in one sitting, the change is too big. Ask for it to be split rather than relaxing the checks.
AI as a second reviewer. You can ask another model pass to review the diff against this checklist. Use its findings as leads to verify. An "all clear" from it is not evidence.
Recording the outcome
Write the result in the pull request description or commit message. A short record is enough:
- Requirement or ticket it was checked against.
- Which checklist items had "no" or "not applicable" answers, and why.
- What you changed or asked to change.
- What you verified yourself, such as "confirmed
ruffandmypyclean, confirmed the empty-input test fails without the guard."
This also helps the next reviewer see which parts were generated and how they were checked.
From checklist to decision
The checklist feeds the accept, revise, or reject decision:
- Accept when every item has an answer with evidence and the remaining "no" items are deliberate, documented choices.
- Revise when the intent is right but specific items fail, such as a missing edge case, unsafe query, or weak test. Give the assistant precise feedback tied to the failing item.
- Reject when the intent is wrong, the diff is too large to review, or core dependencies or APIs do not exist. Restart with a clearer prompt or a smaller task.
Exercise
An assistant adds a feature, and the diff includes a new # type: ignore comment and a new dependency you have never heard of. The tests and linter pass. Which checklist items do you still need to answer, and what evidence would you gather?
Show answer
Dependencies: confirm the package exists on the official index, check that its name is not a misspelling of a well-known package, and check its maintenance and license, then read the lockfile diff for transitive additions. Static checks: read the line the # type: ignore hides and decide whether the type error is real. Remove the comment and fix the type, or record why the suppression is justified. Passing tools do not settle either item, because the suppression can hide a real error and the linter does not judge whether a dependency is appropriate.
Exercise
Why should the intent and scope checks come before the security review in the review order?
Show answer
They are the cheapest checks, and they can reject the whole change. If the change does the wrong thing or is too large to read, a detailed security review would be wasted effort on code you will discard or ask to be split.