How to Review AI-Generated Code: A 5-Step Checklist
AI writes code that passes tests yet hides bugs. Use this five-step review order: run it, check intent, boundaries, dependencies, then AI-specific mistakes. You can catch what the models miss.
Say an agent hands you a pull request (PR), which is a proposed code change, that adds a cache to a product catalog. The tests pass. You load the page once and it works, so it looks done. But two bugs are hiding in a few lines of Python: the cache lifetime is set in the wrong unit, and renaming a product never clears its cached copy. "It ran once" will never find either of them.
Review AI-generated code in a fixed order: run it, check it matches your intent, check boundaries, check dependencies, then look for AI-specific mistakes. Each step catches a different kind of bug. The diff is the list of lines a pull request adds and removes, and it is the thing you review. Doing them in this order means the cheap checks run first and your attention is saved for the hard ones.
Run the code and its tests first
Functional checks come first because code that fails to run or fails its tests is not worth reading closely. This is also step one in GitHub's official guide to reviewing AI-generated code, and it costs you a few minutes.
- Run the code on your machine. Reading it in the browser is not running it.
- Run the full existing test suite, not only the tests the agent added.
- Try one normal input and one bad input, like an empty string or an ID that does not exist.
Passing this step only proves the code does something. In the catalog example, the agent's diff runs and every test is green. Two bugs are still inside, and the remaining steps are how you find them.
Here are the five review steps, plus a sixth step to automate them afterwards. Keep the list next to your editor until it becomes a habit.
Run
Execute the code and the whole test suite. Try a bad input.
Intent
Compare the diff with what you asked for.
Boundaries
Read units, shared state and destructive operations line by line.
Dependencies
Confirm every new package is real and needed.
AI pitfalls
Look for invented APIs, ignored rules and removed tests.
Automate
Let CI and scanners handle the mechanical checks.
If you want to see an agent work through a real fix first, read this walkthrough of using Claude Code to fix a backend bug.
Check the code against your intent
Working code can still solve the wrong problem, so compare the diff with what you actually asked for, a step GitHub's Copilot code review write-up shows depends on context.
Reread your original request word by word. Then ask one question: what did this diff change that I did not ask for? Look at the list of files touched. Check for renamed functions, moved code and extra features nobody requested. Extra changes you did not ask for are common in an AI diff, because the model tries to be helpful.
Here is what a failed intent check looks like. You asked for a cache on get_product and nothing else. The diff also renames two functions, moves a helper into a new file and adds a config file for cache settings. Each change may be fine alone, but you did not ask for any of them, so send the diff back or split them into a separate PR. In the catalog example, the diff touches only the two functions, so it passes this step.
Passing the intent check does not mean the code is right. It only means the diff has the size and shape you asked for, so the next steps look inside it for the bugs that a quick read would miss.
Read the diff for units, state and boundaries
Humans should own the places where code meets the outside world: units, shared state, and operations that cannot be undone. That split comes from Nicolas Fränkel's post on reviewing AI-generated code: people own intent and irreversible operations, and they also own the boundaries, while tools own the mechanical work.
The catalog example comes from GitHub's Copilot review blog, where independent AI reviewers caught both bugs. A cache is a fast store that keeps recent answers so the code does not ask the database again. TTL (time to live) is how long an entry is kept; here it is counted in milliseconds. Below is a simplified sketch of the pattern in src/catalog/service.py, not the exact original code.
# src/catalog/service.py (simplified sketch)
from catalog.settings import CACHE_TTL_SECONDS
def get_product(product_id):
cached = cache.get(product_id)
if cached is not None:
return cached
product = db.fetch_product(product_id)
cache.put(product_id, product, ttl_ms=CACHE_TTL_SECONDS) # bug 1
return product
def rename_product(product_id, new_name):
db.update_product_name(product_id, new_name)
# bug 2: the cached copy still has the old name
Walk the diff against each boundary.
- Units. The parameter is named
ttl_ms, but the constant is in seconds. Every entry expires a thousand times too soon. No test fails, because a cache miss still returns correct data from the database. The cache almost never helps, so the site is as slow as before. - Shared state.
rename_product()updates the database but leaves the cached snapshot alone. Readers keep seeing the old name until that entry expires. - Irreversible operations. This diff has none. In other diffs, stop at any delete, migration or table drop. Our guide to DELETE vs TRUNCATE vs DROP explains which ones you cannot take back.
The fix for both bugs fits in two lines.
cache.put(product_id, product, ttl_ms=CACHE_TTL_SECONDS * 1000)
def rename_product(product_id, new_name):
db.update_product_name(product_id, new_name)
cache.delete(product_id) # next read reloads fresh data
Deleting the cache entry is simpler than updating it in place. The next read fetches the new row and caches it again.
Fränkel also warns that defect detection drops sharply once you review more than a few hundred lines per hour. If an agent hands you a huge diff, ask it to split the work into smaller pull requests.
Verify every new dependency exists
AI tools can suggest packages that do not exist, and attackers register those fake names, a trick called slopsquatting that GitHub's review guide tells you to watch for. Slopsquatting means publishing a malicious package under a name an AI model tends to invent, so anyone who installs it runs the attacker's code.
Open the package page on the official registry, PyPI for Python or npm for JavaScript, before you run any install command. Then check four things:
- Does it exist on the official registry, spelled exactly as the diff spells it?
- Who maintains it? Look for a real repository, recent releases and a history longer than a few days.
- Is it needed? The standard library or an existing dependency often does the same job.
- Does the version make sense? A version that does not appear on the registry page is a warning sign.
Hunt for hallucinated APIs and deleted tests
AI code fails in its own ways: it calls functions that do not exist and makes tests pass by removing them, as this senior developer's 2026 workflow playbook also stresses. These mistakes look fluent, which is why they slip past a quick read.
For every library call you do not recognise, open the official docs and find that exact function. Models predict text that looks right, and a plausible method name is easy to predict.
Accept
- Calls you found in the official docs
- A failing test fixed by changing the code
- Changes that respect the limits you stated
Reject
- A method you cannot find in any docs
- Tests deleted, skipped or marked "expected to fail"
- Ignored constraints, like a library you said not to use
- Quiet edits to login, permissions or secrets code
The same playbook gives a stop rule worth copying. After two or three failed correction loops, or any unexplained security-sensitive change, stop prompting. Read the code yourself.
This matters more each year. In a Sonar survey cited there, developers said 42% of their committed code in 2026 was AI-generated or significantly AI-assisted, up from 6% in 2023 (source).
Automate the mechanical checks
Tools should catch the mechanical problems, like formatting and known vulnerabilities, so your attention goes to judgment, and GitHub's Copilot review results show AI review can act as one more reader on top.
| Check | Tool | What it catches |
|---|---|---|
| Tests on every push | CI (a server that runs your tests on every push), such as GitHub Actions | Broken behaviour and removed tests |
| Static security scan | CodeQL | Known vulnerability patterns like injection |
| Dependency updates | Dependabot | Outdated packages with known security issues |
| Style and simple errors | Linters like Ruff or ESLint | Unused imports, formatting, typos in names |
| Second opinion | AI code review | Logic bugs a tired human skims past |
GitHub tested using two different AI models as reviewers on pull requests. Together they caught 66.2% of critical bugs, up from 61.3% with one model, a gain of about 5 points in bugs found before merge (source). That is a real gain, and it still leaves bugs uncaught. Treat AI review as one extra reader, never as a replacement for you.
How to review an AI-generated pull request as a beginner
If you are new, review in short passes and ask a person to check intent and boundaries while you learn, because 47% of developers in the Sonar survey named reviewing and validating AI-generated code the top skill of the AI era.
Say you have a college project, or your first internship PR in Bengaluru or Boston. Here is a twenty-minute routine that works for both:
- Make one pass per checklist step, a few minutes each.
- On each pass, write down one question, such as "Why did this file change?"
- Send your questions to a teammate or mentor before you approve.
Effective review is slow, ordered and written down. If you are deciding whether an agent is worth paying for while you learn, read whether Claude Code is worth it for students.
Common mistakes when reviewing AI code
Most review failures come from trusting fluent code, reviewing too much at once, or skipping the order, and Fränkel's post is a good reminder of how easily each one happens.
- Approving because it looks neat. Clean formatting says nothing about correct units.
- Reviewing a thousand-line diff in one sitting.
- Asking the same model to check its own work with no new context. It tends to repeat its own reasoning.
- Skipping the dependency check because the install command "just worked."
- Accepting a finding without verifying it. In GitHub's write-up, an AI reviewer flagged "missing products crash," but an existing 404 guard in
src/api/products.pyalready handled it. Open the surrounding code before you accept any comment, human or AI.
Open your last AI-written pull request or project file, run the five checks in order, and write down one bug you would have missed with a single run. Then add one automated check, such as a test or CodeQL, to your repository this week.