
Engineering8 min read1,724 words
A Code Review Checklist for AI-Generated Code
AI-generated code fails in predictable ways: invented packages, missed edge cases, insecure defaults, tests that mirror bugs. A checklist to review it by area.
Jishu Labs
AI-generated code usually reads well and compiles. When it is wrong, it tends to be wrong in a small number of predictable ways: packages and APIs that do not exist, edge cases nobody asked about, insecure defaults, tests that confirm whatever the code already does, and helpers that duplicate ones the codebase already has. A review aimed at those failures catches more than a general read.
Below is the evidence behind each failure class, a copyable checklist grouped by area, guidance on sizing reviews, and the order in which to automate the checks. It complements the post on what to automate and what to keep human in AI code review, which covers how to split the work.
What goes wrong more often in AI-generated code?
Research on generated code points to six recurring failure classes: invented packages and APIs, missing edge cases, inconsistent error handling, insecure defaults, tests that assert current behaviour instead of intended behaviour, and duplicated helpers. Each is easy to miss in a quick read, because the code around the mistake looks fluent and idiomatic.
Invented packages and APIs
A USENIX Security 2025 study generated 576,000 code samples with 16 models and found that, on average, at least 5.2% of packages suggested by commercial models and 21.7% of those suggested by open-source models did not exist, with 205,474 unique invented names. The authors describe it as a new form of package confusion attack: a package published under a commonly invented name would be installed by anyone who trusts the generated import.
Inside the code, the same failure appears as calls to functions and attributes that do not exist. A 2024 study of 333 bugs from three code models (CodeGen, PanGu-Coder and Codex) lists Hallucinated Object and Wrong Attribute among its ten bug patterns.
Missing edge cases
The same study names Missing Corner Case as a pattern of its own: code that handles the example in the prompt and fails on empty input, a boundary value or a repeated call. A generator solves the problem as stated, and a prompt rarely states its edge cases.
Inconsistent error handling
Each generation picks its own way to fail: one function throws, the next returns null, a third logs and carries on. None of the studies cited here measures this directly, but it has the same cause as duplication: locally plausible code written without the codebase's conventions in view.
Insecure defaults
Veracode's October 2026 tests of 18 models found that roughly 4 in 10 generation tasks still produced code with a known vulnerability, although syntax was correct almost every time. Results varied by weakness: generated code passed the SQL injection checks about 84% of the time, but cross-site scripting only about 18% and log injection about 13%. Veracode sells security testing, so treat this as one vendor's benchmark.
Tests that assert the implementation
A study of LLM-generated unit tests across 24 Java repositories found that they mainly capture the program's actual behaviour rather than its expected behaviour, which makes bugs hard to detect. When the code is wrong, a generated test can confirm the wrong answer. The question to ask of every assertion is where its expected value came from.
Duplicated helpers
GitClear, which sells code analytics, analysed 211 million changed lines written from 2020 to 2024. Between 2021 and 2024, copy-pasted lines rose from 8.3% to 12.3% of changes, while moved lines, its proxy for refactoring and reuse, fell from 25% to under 10%. A generator that cannot see an existing helper writes a new one, and two copies that must change together are the dangerous kind of duplicated code.
The code review checklist for AI-generated code
Use the checklist below on any pull request where a meaningful share of the code was generated. It is grouped by area so reviewers can divide it, and every item is a check with a yes or no answer. Items marked (automate) belong in CI once tooling exists; until then, a person checks them by hand.
Intent and scope
- The pull request says what it is meant to do, and the diff does only that.
- No unrelated refactoring rides along with the change.
- The reviewer can explain every changed function without running it.
Dependencies and APIs
- Every new package exists in the official registry, is spelled as intended and is the one the team meant to add. (automate)
- Every called function, method and attribute exists in the installed version of its library. (automate: type checker or compiler)
- New versions are pinned, and the lockfile change matches the manifest change. (automate)
Correctness and edge cases
- Empty, null, zero, maximum and duplicate inputs are handled or rejected explicitly.
- Boundaries are right: off-by-one, inclusive or exclusive ranges, time zones, rounding of money.
- Retries, concurrent calls and partial failures leave data consistent.
Error handling
- Errors follow the project's one agreed pattern rather than a new one.
- No error is swallowed: every catch handles, rethrows or logs with context.
- Error messages and logs contain no secrets or personal data.
Security
- Input that reaches a query, a shell, a file path, HTML or a log line is validated or encoded. (automate: static analysis)
- Authorization is checked on every new endpoint, handler and background job.
- No keys, tokens or passwords appear in code, configuration or tests. (automate: secret scanning)
- Cryptography, randomness and TLS settings use the project's approved defaults.
Tests
- Each expected value comes from the requirement, not from running the code.
- At least one test fails if the change is reverted.
- The edge cases above are tested, not only the happy path.
- Assertions are specific; a test that only checks that nothing threw is not enough. (automate: mutation testing)
Fit with the codebase
- No new helper duplicates an existing one; search for the purpose, not the name. (automate: duplicate detection)
- Names, structure and patterns match the surrounding code.
- Comments explain why, and none describes behaviour the code does not have.
A short version for a pull request template:
## Review checklist (generated code)
- [ ] Scope: the diff does only what the description says
- [ ] Dependencies: every new package exists, is the intended one, and is pinned
- [ ] APIs: every called function and attribute exists in the installed version
- [ ] Edge cases: empty, null, zero, maximum, duplicate and concurrent inputs
- [ ] Errors: the project's one error pattern; nothing swallowed; no secrets in logs
- [ ] Security: input encoded or validated before queries, shells, paths, HTML, logs
- [ ] Auth: authorization checked on every new endpoint or handler
- [ ] Tests: expected values come from the requirement, not from running the code
- [ ] Tests: at least one test fails if this change is reverted
- [ ] Reuse: no new helper duplicates an existing one
Conventions the generator can read cause fewer of these findings in the first place; an AGENTS.md file is where coding agents look for them.
How big should a pull request of generated code be?
A pull request of generated code should be small enough for a reviewer to check every line against the checklist in one sitting. Google's engineering practices call 100 changed lines usually reasonable and 1,000 usually too large, and ask for one self-contained change per review. Generation makes large diffs cheap, so the limit matters more.
In practice: split generated work by behaviour, keep refactoring in its own pull request (Google's guide recommends the same), review the interface and the tests before the implementation, and send back a diff too large to reason about instead of approving it after a skim. An agent can regenerate a change in smaller steps at little cost.
What should you automate first?
Automate the checks that are cheap, deterministic and aimed at failures people miss: dependency existence and pinning first, then type checking and linting, then tests with coverage of changed lines, then static security analysis and secret scanning, then duplicate detection. Leave intent, design fit and the source of test expectations to people.
- Dependency checks. Fail the build when a new package is not on an allowlist or has no release history. An invented name costs nothing to catch here.
- Type checking and linting. In typed code, a type checker or compiler catches calls to functions and attributes that do not exist.
- Tests with coverage of changed lines. Not a target for the whole codebase; a check that new code actually runs under test.
- Static security analysis and secret scanning. Make sure the rules cover the weaknesses generated code failed most often in Veracode's tests, cross-site scripting and log injection.
- Duplicate detection. Flag new blocks that closely match existing ones, so the reviewer can ask for reuse.
- Mutation testing on critical modules. It shows whether the tests fail when the code changes, which exposes weak assertions.
Sensei, the AI Code Review & Comprehension tool from Jishu Labs, can act as a second reader on generated changes: "Sensei reviews and explains any codebase with AI — instant explanations, health scoring, security findings, and concrete fixes in seconds." Treat its findings as input to this checklist, not a substitute for it.
Frequently Asked Questions
Should AI-generated code be reviewed differently from human-written code?
The standard is the same; the emphasis moves. Spend more of the review on dependencies, edge cases, error paths and where test expectations come from, and less on style, which formatters and linters should already enforce before a person looks.
Can an AI model review AI-generated code?
It can take the first pass on mechanical checks and point to risky areas. It may share blind spots with the model that wrote the code, so a person should still judge intent, design fit and whether the tests encode the requirement.
How do I check that a package suggested by an AI tool is real?
Look it up in the official registry before installing it: confirm the exact name, the publisher, the release history and that its documentation matches how the code uses it. Then pin it in the lockfile. Never install a package only because generated code imports it.
Should generated tests count toward test coverage?
Only after review. A generated test counts once a person has confirmed that its expected values come from the requirement. Until then it proves only that the code does what it currently does, which may be the bug.
References
- We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs — Spracklen et al., USENIX Security 2025 (arXiv)
- Bugs in Large Language Models Generated Code: An Empirical Study — Tambon et al. (arXiv)
- Can we find bugs using LLM-generated oracles? — Konstantinou, Degiovanni and Papadakis (arXiv)
- GenAI Code Security Fall 2026: The Ceiling Moves, But on the Low-Hanging Fruit — Veracode
- AI Copilot Code Quality: 2025 Look Back at 12 Months of Data — GitClear
- Small CLs — Google Engineering Practices
About Jishu Labs
Jishu Labs is a software development company founded in 2016. We build custom software, AI/ML systems, and full-stack web and mobile applications for clients, and we make eight AI tools for software teams.




