AI Coding

How to Review AI-Generated Code: A Practical Checklist

AI-written code has a specific way of being wrong. It compiles. It’s neatly formatted, with sensible names and a comment on top. It passes the tests that came with it. And somewhere in the middle there’s a query built with string formatting, a package that doesn’t exist, or a test that checks the bug against itself.

That polish is the problem. Reviewers relax when code looks tidy. This guide shows how to review AI generated code with a checklist built for those failure modes, backed by official guidance from GitHub and OWASP. We also ran three small Python demos on Python 3.12.4 to show what each bug looks like when it slips through, and the scripts are saved with this post.

Quick answer: To review AI generated code, first confirm it solves the real task, then run tests, linters and security scans, then read the risky parts by hand: inputs, queries, auth, error paths and new dependencies. Check that every package and API actually exists, and that tests use known answers instead of copying the code’s logic.

  • GitHub’s own docs say Copilot can make mistakes and you should always validate the code it suggests.
  • Copilot code review isn’t guaranteed to catch every problem, so it supplements human review.
  • A USENIX Security 2025 study found at least 5.2% of packages suggested by commercial models didn’t exist.
  • Tests written by the same AI can pass while the code is wrong. Check one by hand.

Why AI code needs a different review

A human junior developer’s mistakes usually look like mistakes: odd naming, messy structure, a missing case you can spot. AI mistakes hide inside confident, clean code. The review habits that catch human errors, like skimming for style and trusting green tests, miss a lot of them.

GitHub is blunt about this. Its Copilot best practices page says Copilot can make mistakes and tells you to understand suggested code before you use it, to check readability and maintainability as well as function and security, and to add tools like linting, code scanning and IP scanning. Its page on Copilot code review adds that Copilot isn’t guaranteed to spot every problem in a pull request, and that its reviews don’t count toward required approvals by default.

The vendor of the tool is telling you to review its output. Take the hint.

Five-step order to review AI generated code before merging

Step 1: Check it solves the real task

Before reading a single line, reread the ticket or your prompt. AI tools are very good at solving a slightly different problem than the one you had, especially when the request was vague.

  • Does the change do what was asked, and nothing extra? Unrequested “improvements” are where surprise bugs live.
  • Is the diff the size you’d expect? A two-line fix that arrives as 400 lines across nine files needs a reason.
  • Did it change files it shouldn’t touch, like config, migrations, CI or lock files?
  • Did it delete or weaken anything, such as a validation check, a test or an error message?

If the scope is wrong, stop here and send it back. Line-by-line review of the wrong change is wasted time.

Step 2: Run the machines first

Let tools catch the boring problems so your attention goes to logic. Run the full test suite (not just the new tests), your linter and type checker, and any security scanning you have. On GitHub that can mean code scanning and secret scanning; elsewhere, whatever static analysis your team already uses.

An AI reviewer can help here too. Copilot code review, Claude Code and Codex can all comment on a diff. Treat their comments like a linter with opinions: worth reading, not worth trusting alone. GitHub’s docs say to always validate Copilot’s feedback and to supplement it with a human review.

Step 3: Verify every package and API

This is the most AI-specific check on the list. Models sometimes import libraries that don’t exist, or call functions and options a real library never had. The USENIX Security 2025 paper “We Have a Package for You!” tested 16 code-generating models on 576,000 code samples. It found the average share of hallucinated packages was at least 5.2% for commercial models and 21.7% for open-source models, with 205,474 unique fake package names.

Fake names are a security risk, not just an install error. Attackers can register a package under a name models tend to invent, and anyone who runs pip install without checking gets their code. OWASP lists this broader category as A03:2025 Software Supply Chain Failures in the OWASP Top 10:2025.

Checking is quick. We wrote a short script that asks PyPI’s JSON API whether each name exists. Two of the five names below are ones we made up to look like typical AI suggestions:

$ python check_packages.py
requests                     exists   (latest 2.34.2)
pydantic                     exists   (latest 2.14.3)
python-dateutil              exists   (latest 4.0.0)
fastapi-jwt-auth-helper      MISSING  (HTTP 404) do not pip install a look-alike
pandas-excel-cleaner-pro     MISSING  (HTTP 404) do not pip install a look-alike

A 404 today is the safe outcome. The dangerous case is a name that didn’t exist when the model learned it but does now, registered by someone else. So for any new dependency, also check who publishes it, when it first appeared and whether the project page links to a real repository. For function calls, open the library’s docs for the installed version and confirm the signature.

Step 4: Read the risky lines by hand

You don’t need to read every line with the same care. Spend your attention where a bug costs the most.

Input and queries

Look for any place user input meets a query, a shell command, a file path or HTML. Injection is A05:2025 in OWASP’s list, and AI code reproduces it because so much training code does. Our SQLite demo shows how it hides: the unsafe version works perfectly on normal input.

Unsafe f-string SQL query versus parameterized query when you review AI generated code
happy path, unsafe : [(1, 'ana@example.com')]
attack, unsafe     : [(1, 'ana@example.com'), (2, 'raj@example.com'), (3, 'li@example.com')]
attack, safe       : []

One crafted string and the f-string version returns every user. The parameterized version returns nothing. Python’s sqlite3 docs warn against building queries with string operations, and OWASP’s SQL injection prevention cheat sheet lists prepared statements with parameterized queries as the first defence.

Auth, secrets and error paths

  • Access control: Does every new endpoint check who’s calling? Broken access control is A01:2025, the top item on OWASP’s list.
  • Secrets: No API keys, passwords or tokens in code, tests or example config.
  • Errors: Look for except: pass, empty catch blocks and errors turned into a default value. OWASP added A10:2025 Mishandling of Exceptional Conditions for exactly this.
  • Edge cases: Empty lists, zero, None, very large input, timeouts, retries. Generated code is usually right on the happy path and shakier at the edges.
  • Logging: Is anything sensitive written to logs?

Step 5: Review the tests, not just the code

When the same assistant writes the code and the tests, the tests can quietly share the code’s mistake. Our third demo has a discount function with a real bug (it divides by 10 instead of 100) and two tests:

test_mirror        PASS
test_known_answer  FAIL  (apply_discount(80, 25) returned -120.0)

The first test recomputes the expected value using the same formula, so it passes no matter what. The second one uses a number worked out by hand (25% off 80 is 60), and it catches the bug at once. When you review AI tests, look for expected values copied from the implementation, mocks that replace the very thing being tested, and assertions so loose they can’t fail, like checking only that a result isn’t None.

A quick sanity check: break the code on purpose and rerun the tests. If nothing fails, the tests aren’t testing much.

What most checklists miss: the biggest risk isn’t bad code, it’s a tired reviewer. AI tools produce more code per hour than people can review carefully, and a diff that looks clean invites a rubber stamp. Keep AI changes small enough to read in one sitting, ask the tool to explain the riskiest part in plain words, and be willing to reject a change you can’t explain yourself. If you couldn’t defend it in a code review meeting, it shouldn’t merge.

The review AI generated code checklist

Copy this into your pull request template. It’s short on purpose.

  1. The change solves the actual task, with no unrequested extras.
  2. Diff size and touched files make sense; config, CI and lock files changed only on purpose.
  3. Full test suite, linter, type checker and security scans pass.
  4. Every new package exists, comes from a trusted publisher and is pinned.
  5. Every library call matches the docs for the version you use.
  6. User input never reaches SQL, shell, file paths or HTML unescaped.
  7. New endpoints check permissions; no secrets in code or logs.
  8. Errors are handled, not swallowed; edge cases are covered.
  9. Tests use known answers and fail when the code is broken on purpose.
  10. You can explain every changed line to a teammate.

Using an agent that edits many files at once? Our comparison of Claude Code vs Codex vs GitHub Copilot covers how each tool’s permission modes let you approve changes before they land. And if you’re setting Copilot up from scratch, the GitHub Copilot tutorial walks through the pull request flow where this checklist fits.

Our verdict

AI coding tools are worth using, and AI reviewers are worth running. Neither replaces a person who understands the change. Spend your review time in this order: scope, machines, dependencies, risky lines, tests. Most real problems in AI code turn up in the last three.

Skip the full checklist for a throwaway script on your own laptop. Don’t skip it for anything that touches user data, money or production.

Next: when a review does find a bug, our guide on how to fix bugs with AI without hiding the real bug shows how to get a fix that addresses the cause, not the symptom.

FAQ

How do you review AI-generated code effectively?

Check the scope against the task first, run automated checks second, then read by hand where risk is highest: inputs, queries, auth, error handling, dependencies and tests. Keep each AI change small enough to review properly in one go.

Is AI-generated code secure?

Not by default. It can contain the same flaws as human code, like injection and missing access checks, plus AI-specific ones such as invented packages. GitHub recommends linting, code scanning and human review on top.

Can AI review its own code?

It can catch real issues, and tools like Copilot code review are built for it. GitHub’s docs still say Copilot isn’t guaranteed to find every problem and its feedback should be validated and supplemented by a human.

How can I check if code is AI generated?

There’s no reliable way to tell from the code alone, and it matters less than whether the code is correct. Review every change to the same standard, and ask contributors to say in the pull request when AI wrote a large part of it.

Leave a Comment