how to review AI-generated code
How to review AI-generated code before merging
How to review AI-generated code: a nine-point checklist for invented packages, deprecated APIs, missing access checks and tests that freeze the bug.
- By Azziz ERRIME
- 11 min read
Contents
- A green pipeline says nothing about what a change does
- Nine checks to review AI-generated code before it merges
- AI-generated code fails where a human reviewer is not looking
- The instruction to look for security outweighs the checklist
- The security instruction belongs in the pull request template
- After 1.84.0, I would start with the token and the template
- Frequently asked questions on how to review AI-generated code
- Sources
TL;DR
- Learning how to review AI-generated code starts with where it fails: invented packages, deprecated APIs, missing access checks and tests that freeze the bug.
- Veracode found a security flaw in 45% of cases across more than 100 models; another study found 19.7% of recommended packages do not exist.
- I would add one line to every pull request template asking reviewers to look for security, because that instruction outweighed a checklist in a study that measured both.
In July 2025, malicious code reached a published release of the Amazon Q Developer extension for VS Code. The case concerns a release pipeline, yet it raises the question every team merging AI-written pull requests should ask: what stands between a change and a release? My answer is a nine-point checklist for how to review AI-generated code, and one instruction to reviewers that weighs more than the list.
The number is 1.84.0. It is a version of the Amazon Q Developer extension for VS Code, published in July 2025, and according to the CVE-2025-8217 record it contains malicious code. AWS security bulletin AWS-2025-015 sets out the response: AWS removes the code, revokes the credentials and publishes version 1.85.0. The cause it gives is a GitHub token with too broad a scope in the CodeBuild configuration. The bulletin does not describe a pull request that someone read and approved, and I will not add one. What it describes is plainer. Code entered the project, a release went out with it inside, and the steps in between let it through.
A green pipeline says nothing about what a change does
I read the bulletin as a story about the path a change takes. Every step between the repository and the release trusted the step before it: if the code was in the repository, it was meant to be there. A build that succeeds and a version number that increments prove that a process ran. Neither can say what the code will do on the machine that installs it.
Pull requests written with AI travel the same path, and they arrive looking finished. The code compiles, the names read well, the tests pass and the description is tidy. That polish makes them easy to approve on a skim. A reviewer reading a colleague’s change looks for human mistakes: a reversed condition, a forgotten edge case, a shortcut taken under deadline.
Code from a model makes other mistakes, and plenty of them. Veracode’s GenAI Code Security Report tested more than 100 large language models on coding tasks and found that the generated code introduced a security flaw in 45% of cases. I have written about what shifts in code review when AI writes the pull request. This guide is the practical part: what to check, and in what order, before you press merge.
Nine checks to review AI-generated code before it merges
If you came looking for how to check AI-generated code quickly, here is the list I would pin above the merge button. It runs from the cheapest checks to the ones that need thought, and each item answers a failure measured in model output or the gap the Amazon Q bulletin describes.
- Confirm that every new dependency exists and is the one you meant. Open its registry page, look at the publisher, the age and the release history, then pin the version.
- Compare each library call with the documentation of the version you actually run. Deprecated functions still compile, so the compiler will not warn you.
- Follow every input to the place where it lands. A web page needs output encoding, a log line needs its line breaks neutralised, a database query needs parameters.
- Find the access check, or notice that it is missing. Ask who may call this code and on whose data, then look for the line that enforces the answer.
- Break the code and watch the tests. Revert the fix or flip a condition: a test that stays green was written to agree with the code as it stands.
- Look for credentials and the scope they carry. A token in a config file, a key in a test fixture, a permission wider than the task needs.
- Read the files the task did not mention. Build scripts, CI configuration, lockfiles and permission manifests can change quietly inside a large generated pull request.
- Walk the failure paths. Feed the code empty input, a timeout and a missing file, and read what it does in each case.
- Ask the author to explain the change in their own words. A line nobody on the team can explain does not merge.
The first two take minutes and little judgement. The third, fourth and fifth take real attention, and that is where I would spend most of the review. Why these nine, and not the list a team already applies to code written by people? Because each one targets a failure that researchers have measured in what models write.
AI-generated code fails where a human reviewer is not looking
Behind Veracode’s 45% sit specific patterns. The models in that study failed to prevent cross-site scripting in 86% of cases, and they did worse still on log injection. Both flaws live in the gap between where data enters and where it comes out, which is why the third check follows each input to its destination.
The first check comes from a USENIX Security 2025 paper by Spracklen and colleagues. In their tests, 19.7% of the packages the models recommended did not exist, and the invented names added up to more than 205,000. The mechanism that turns this into an attack is short. A model suggests a plausible name that nobody has published. An attacker who spots that name registers it on the public registry and fills it with code of their choosing. The next developer who accepts the suggestion runs the install, and the dependency now exists, written by a stranger.
The second check answers LLMs Meet Library Evolution, an ICSE 2025 study that found frequent use of deprecated APIs in code completion. A deprecated call compiles and runs, so it slips past a reviewer who reads for logic. It breaks later, when the library removes it, or it keeps alive the very behaviour the maintainers wanted gone.
The fifth check is the one I find most unsettling. A 2026 study of misguided tests shows that tests generated by a model can pass on buggy code and fail on the corrected version. Such a test protects nothing. It freezes the bug in place, and the next person who fixes it will see a red build and assume they broke something. A sceptical reader will answer that the tooling already catches all of this.
The instruction to look for security outweighs the checklist
The objection is fair, and most teams already run the tools it names: a dependency scanner, a static analyser, sometimes a model that comments on every pull request. I have gone through what security scanners for AI coding tools miss in a separate piece. A scanner matches patterns, and it cannot know that this endpoint was supposed to check who owns the record, or that a test was written to agree with the bug.
A model reviewing another model’s code raises the same worry. The misguided tests above came from a model, and they passed on code that was wrong. A generated check can approve a generated mistake.
The result that changed how I use this list comes from Braz and colleagues at ICSE 2022. Reviewers who were asked to focus on security were eight times more likely to detect a vulnerability. Giving them a checklist added nothing significant on top. That finding undercuts every AI code review checklist, the one above included, and I take it at face value.
What moved the result was the instruction. It changes what the reviewer reads for, and the nine checks then give that attention somewhere to land. The practical question becomes one of organisation: how does a team make sure the instruction is given every time?
The security instruction belongs in the pull request template
The cheapest place to give the instruction is the template every pull request opens with. One line at the top is enough: review this change for security, starting with dependencies, inputs, access and secrets. It reaches the reviewer at the moment of review, which training cannot promise. I have argued that a secure coding training score is no measure of vigilance, and the template puts vigilance in front of the reviewer on the day it counts.
Size comes next. A model produces a large change as easily as a small one, and nobody follows inputs through a change they cannot hold in their head. I would ask authors to split AI-written work into pieces a reviewer can read in one sitting, and send the rest back.
Then decide who reads what. The person who prompted the model owns the explanation in the ninth check, and answers for every line whoever typed it. When build scripts, CI configuration or permission files change, a second reviewer reads those files on their own, as a secure code review of the release path. Picking the model is a separate choice, covered in which AI to choose for secure coding; whichever you pick, this part of the work stays with people. That second reviewer is the one I keep thinking about when I reread the AWS bulletin.
After 1.84.0, I would start with the token and the template
Go back to version 1.84.0. The bulletin names a GitHub token whose scope was too broad, sitting in a CodeBuild configuration. That is a file outside any feature, the kind of file my seventh check sends a reviewer to read. AWS removed the code, revoked the credentials and published 1.85.0; what I take from the case is where the cause sat, far from the code anyone would think to review first.
On Monday, I would add the security line to the pull request template before anything else. I would run checks one, five and seven on every AI-written pull request that week, because they are cheap, they catch invented packages and frozen bugs, and they cover the files nobody opened. For each build or permission change, I would also ask which person can explain it.
My doubt concerns the eightfold result. Braz and colleagues measured it in 2022, on changes written by people, and I do not know whether the instruction weighs as much when code arrives polished and in volume. I would still give it first. It costs one sentence.
Frequently asked questions on how to review AI-generated code
Why is it important to review AI-generated code?
Because it fails often, and in places that clean formatting hides. Veracode’s GenAI Code Security Report tested more than 100 large language models and found a security flaw in 45% of cases; cross-site scripting went unprevented 86% of the time. Passing tests do not reveal those flaws. A reviewer explicitly asked to look for security has a far better chance of finding them.
Should developers review AI-generated code even with good prompts?
Yes. A careful prompt shapes the code, yet it cannot tell the model which packages exist. In the USENIX Security 2025 study by Spracklen and colleagues, 19.7% of packages recommended by 16 models did not exist, and open source models invented names about four times as often as commercial ones. Every new dependency still needs a look at the registry before it merges.
How do you check AI-generated code?
Start with the cheap checks: confirm each new dependency exists, compare library calls with current documentation and search for credentials. Then spend attention on inputs, access checks and tests, reverting a fix to see whether a test goes red. The ICSE 2025 study LLMs Meet Library Evolution found frequent use of deprecated APIs in code completion, so the documentation check earns its place.
Can AI review AI-generated code?
It can add comments, but it should not be the last reader. A 2026 study of misguided tests found that tests generated by a model passed on buggy code and failed on the corrected version, so a generated check can approve a generated bug. I cover the wider question in code review when AI writes the pull request.
Sources
- Malicious code published in version 1.84.0 of the Amazon Q Developer extension for VS Code: CVE-2025-8217, SentinelOne vulnerability database, July 2025. sentinelone.com
- AWS removes the code, revokes the credentials, publishes 1.85.0; stated cause, a GitHub token with too broad a scope in the CodeBuild configuration: AWS Security Bulletin AWS-2025-015, July 2025. aws.amazon.com
- Security flaw in 45% of cases across more than 100 LLMs; cross-site scripting (CWE-80) unprevented in 86% of cases, log injection (CWE-117) in 88%: Veracode, GenAI Code Security Report, 30 July 2025. veracode.com
- 19.7% of packages recommended by 16 LLMs do not exist, more than 205,000 unique invented names, open source models about four times more often than commercial ones: Spracklen et al., “We Have a Package for You!”, USENIX Security 2025 (arXiv, June 2024). arxiv.org
- Frequent use of deprecated APIs in LLM code completion: “LLMs Meet Library Evolution”, ICSE 2025. arxiv.org
- LLM-generated tests that pass on buggy code and fail on the corrected version: “Misguided tests”, 2026. arxiv.org
- Asking reviewers to focus on security multiplies the probability of detecting a vulnerability by eight; a checklist adds nothing significant: Braz et al., ICSE 2022. arxiv.org