How to Review AI-Generated Code Before It Reaches Production
Acceptance gates, targeted security scanning, and a review workflow built for volume, not vibes.
- 0145% of AI-generated code samples failed basic security tests in a recent Veracode study.
- 02AI-assisted developers commit code up to four times faster, drastically increasing security findings.
- 03AI-authored pull requests contain 2.74 times more security issues than human-only code.
- 04Nearly 20% of AI-generated code samples reference hallucinated software packages.

The short answer
Review AI-generated code by treating it as untrusted input, not a finished draft: run it through automated security gates before a human ever looks at it, then have a human review only the categories AI reliably gets wrong, like authentication, authorization, and cryptography. Skipping either half of that pipeline is how vulnerable code reaches production.
This isn't a theoretical risk. Veracode tested more than 100 large language models across 80 coding tasks and found that 45% of AI-generated samples failed basic security tests, with pass rates flat at roughly 55% for two straight testing cycles even as raw coding benchmarks kept improving.1 Bigger, newer models did not do better on security.1 That gap between capability and safety is exactly what a review workflow has to close.
Why this got urgent
The volume problem is real. Apiiro's analysis of tens of thousands of Fortune 50 repositories found AI-assisted developers committing code three to four times faster than their peers, while monthly security findings rose from about 1,000 to more than 10,000 over six months.1 Syntax errors and logic bugs actually dropped. What went up were the flaws that need contextual judgment to catch: privilege escalation paths rose 322%, and architectural design flaws rose 153%.1 That's the pattern to plan around. AI cleans up the obvious mistakes and quietly introduces the expensive ones.
CodeRabbit's analysis of 470 open-source pull requests backs this up from a different angle. AI-co-authored PRs contained about 1.7 times more issues overall than human-only PRs, and security issues specifically ran up to 2.74 times higher, concentrated in password handling and insecure object references.2 Readability problems tripled and error-handling gaps nearly doubled, which matters because sloppy, inconsistent code is exactly what makes a real security flaw easy to miss in review.2
There's also a supply chain angle unique to AI output. Researchers analyzing 576,000 AI-generated code samples across 16 models found that roughly 20% referenced software packages that don't exist, and 43% of those hallucinated names were reproduced consistently across similar prompts.1 Attackers now register those exact names, a technique called slopsquatting, so a hallucinated import can become a real malicious dependency before anyone notices.1 One such fake package accumulated over 30,000 downloads in three months with no code and no README.1
None of this is helped by how confident developers feel about AI output. Nearly 80% believe AI tools generate more secure code than humans write, a belief that runs directly against the measured evidence.1 That overconfidence is the real governance problem. Tools you don't trust get checked. Tools you do trust get waved through, which is precisely backward here.
Build the review pipeline in four layers
1. Acceptance gates before merge, not after
The fix that scales with volume is automated, not manual. Static application security testing, dependency scanning, and secret detection should run on every AI-assisted commit, with results returned before code merges, not discovered in a later audit.1 Set explicit acceptance criteria per pull request: what must pass, what evidence proves it passed, and what happens when it doesn't. This is the same discipline that structured AI-agent workflows have started building directly into the coding process itself, treating "done" as something that has to be proven with a runnable check rather than asserted by the agent. Tools like Unlazy work in this space, forcing an agent to write an explicit ledger of checks and re-verify them before a task is reported complete, rather than trusting the agent's own account of its work. The point isn't the specific tool. It's the pattern: don't let an agent grade its own homework.
2. Route by risk category, not by developer
Not all AI-written code carries the same risk. Based on where failures concentrate, treat authentication flows, authorization logic, cryptographic implementations, input validation, and anything touching sensitive data as mandatory human-review categories, regardless of who or what wrote the code.1 Routine boilerplate, test scaffolding, and refactors can move faster through automated gates alone. This routing decision should be a written policy, not left to individual judgment, because judgment is exactly what erodes under deadline pressure.
3. Scan dependencies as if they might not exist
Given the hallucinated-package problem, run software composition analysis on every AI-suggested import and flag anything inconsistent with your existing dependency graph before it's installed.1 This is a five-minute gate that closes a real supply chain hole.
4. Use AI code review as a force multiplier, not a substitute
AI-assisted review tools can absorb the volume problem: standardizing checks across whatever coding tool produced the diff, and freeing human reviewers to focus on the complex, high-risk sections rather than reading every line.2 But don't treat this as equivalent to a security gate. Research on GitHub Copilot's own built-in review feature found it frequently misses critical issues like SQL injection and insecure deserialization while flagging low-severity formatting noise.1 An AI reviewer catching stylistic problems is not the same as a security control catching a privilege escalation path.
Write the policy down
Security gaps compound fastest where there's no written boundary between what an employee can generate with an AI tool and what requires sign-off before shipping. If your organization hasn't formalized that boundary yet, the governance groundwork is covered in more depth in Securing the Code Your AI Wrote: 5 Rules for the Copilot Era, and the broader problem of ungoverned tool sprawl is the subject of The 'Free Claude' Problem: Why Shadow AI Is Your Next Governance Nightmare. The review workflow described here is the enforcement mechanism for whatever policy you write. A policy without gates is a memo. Gates without a policy are noise nobody can prioritize.
The uncomfortable truth is that AI coding tools accelerate everything, including your mistakes. Treat every AI-generated diff the way you'd treat a contribution from a contractor you've never met: useful, probably fine, but not trusted until it's checked.
Run automated security gates, SAST, dependency scanning, and secret detection on every commit before merge, then route high-risk categories like authentication, authorization, and cryptography to mandatory human review. Automated checks alone catch the volume; human review catches the architectural flaws AI tools miss.
Testing shows AI-generated code fails basic security checks about 45% of the time across major models, and separate research found security issues appear up to 2.74 times more often in AI-authored pull requests compared to human-only ones.
An acceptance gate is a written, runnable check that AI-generated work must pass before it's considered done, rather than relying on the agent's own claim of completion. Tools like Unlazy formalize this by requiring an explicit ledger of checks and re-verification.
Slopsquatting is an attack where bad actors register software package names that AI coding tools commonly hallucinate, so when a developer installs the AI-suggested dependency, they pull in malicious code instead.
Not necessarily at the same depth. Route routine code like boilerplate and test scaffolding through automated gates, and reserve mandatory human review for security-sensitive categories: authentication, authorization, cryptography, and anything touching sensitive data.
- 1Vibe Coding's Security Debt: The AI-Generated CVE SurgeCloud Security Alliance
- 2Our new report: AI code creates 1.7x more problemsCodeRabbit



