Topic 3 of 4 · 4 min read
A review checklist for AI-written code
Goal: Apply a short checklist to an AI-written change and find the defect classes agents produce most often.
A checklist turns review from "does this look right?" into a set of questions with yes or no answers. It matters more with AI code, because the code always looks right. Keep the list short enough to use on every change.
Check yourself · 1 of 3
Which checklist item should you review first on an AI-written change?
The checklist
- Intent. Does the change do what the task asked, and nothing else? (See scope creep.)
- Edges. Empty, null, zero, one, many, maximum. Off-by-one in ranges and pagination. Time zones and dates.
- Errors. What happens when each external call fails? Look for swallowed exceptions, missing retries or timeouts, and errors logged but not handled.
- Security. Untrusted input reaching SQL, shell commands, file paths, HTML or templates. Missing authorisation checks on new endpoints. Secrets in code or logs. Over-broad defaults such as
Access-Control-Allow-Origin: *with credentials. - Dependencies and APIs. Does every imported package and every called function actually exist in the version you use? Agents invent plausible names and use old APIs.
- Tests. Do they fail without the fix? Do they cover the edge and error cases? Were existing tests weakened?
- Fit. Does it reuse the project's helpers, error types and conventions, or does it add a second way of doing the same thing?
How to use it
Run the list in that order. Intent first, because a change that does the wrong thing does not need a style review. Security and tests before naming and style, because those are where the cost is. Tools catch some items: type checkers, linters, SAST scanners and dependency scanners handle parts of 3 to 5 cheaply. Run them in CI so your attention goes to what they miss: intent, edges and design.
Before and after
# Agent: "Added an endpoint to download a user's invoice."
@app.get("/invoices/{name}")
def download(name: str):
return FileResponse(f"/data/invoices/{name}")
Checklist pass: security fails twice. There is no check that the caller owns the invoice, and name can be ../../etc/passwd. The reviewed version looks the invoice up by id for the current user and serves only the stored path:
@app.get("/invoices/{invoice_id}")
def download(invoice_id: int, user: User = Depends(current_user)):
inv = invoices.get_for_user(invoice_id, user.id) # 404 if not theirs
return FileResponse(inv.stored_path)
What goes wrong
- A checklist too long to use. Twenty items get skipped. Seven get done.
- Letting tools replace the list. A scanner will not tell you the endpoint is missing an ownership check that your framework does not know about.
- Checking style first. Comments about names on a change with a path traversal waste the review.
Examples
Checking that an API exists
The diff calls response.json(strict=True). The HTTP client in requirements.txt has no strict parameter on json(). The agent mixed it up with another library. A quick look at the installed version's docs, or one run of the code, catches it.
Does the test fail without the fix?
Revert the fix locally and run the new test. If it still passes, it is not testing the bug. This takes a minute and is the fastest check on an AI-written test.
Key points
- Use a short checklist: intent, edges, errors, security, dependencies and APIs, tests, fit.
- Check intent first; a change that does the wrong thing does not need a style review.
- Agents often invent packages or call APIs that do not exist in your version: verify them.
- Tests must fail without the fix and cover edge and error cases.
- Let CI tools cover what they can, and spend human attention on intent, edges and design.
Common mistakes
- Starting with style and naming before intent and security.
- Assuming every imported package and called method exists because the code looks idiomatic.
- Not checking that the new test fails without the fix.
- Using a long checklist that nobody finishes.
Check yourself · 2 of 3
An AI-written test passes. What is the quickest way to check it actually tests the fix?
Check yourself · 3 of 3
An AI-written endpoint returns a file using a name taken from the URL. Which checklist item does it most likely fail?
Practice items, not counted towards your mastery.
Start here
- What to look for in a code review (Google Engineering Practices) (opens in a new tab)ArticleFree
Design, functionality, complexity, tests and naming: the baseline every AI diff still has to meet.
- Small CLs (Google Engineering Practices) (opens in a new tab)ArticleFree
Why small changes get better reviews, and how to split large ones; applies directly to agent output.
- Secure Code Review Cheat Sheet (OWASP) (opens in a new tab)ArticleFree
A security checklist for input handling, auth, secrets and error handling during review.