how to review ai generated codeai code securityshadow ai governance

How to Review AI-Generated Code Before It Reaches Production

A practical workflow for reviewing AI-generated code: acceptance gates, risk-based routing, dependency scanning, and where human review still matters most.

Portrait of Luis Chavez-Mattos
Edited by Luis Chavez-Mattos, Director, Product··RSS
A sequence of unlabelled rectangular plates passing through an automated structural scanning archway, representing a targeted code review pipeline and acceptance gate.

How do you review AI-generated code before it reaches production?

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. Bigger, newer models did not do better on security. That gap between capability and safety is exactly what a review workflow has to close.

TL;DR

  • Treat AI-generated code as untrusted input and run it through automated security gates before a human reviews it.
  • Veracode found that 45% of AI-generated samples failed basic security tests, and newer, bigger models did not do better on security.
  • AI-assisted developers commit code three to four times faster, and monthly security findings rose from about 1,000 to more than 10,000 over six months.
  • AI-co-authored pull requests had security issues running up to 2.74 times higher than human-only pull requests.
  • Roughly 20% of AI-generated samples referenced hallucinated software packages, which attackers can register through slopsquatting.
  • Reserve human review for authentication, authorization, and cryptography, and write the policy down so the gates have something to enforce.

Why did AI code review become 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. 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%. That's the pattern to plan around. AI cleans up the obvious mistakes and quietly introduces the expensive ones.

Figure 1
The headline numbers on AI-generated code risk
45%
AI code samples that fail security tests
10×
Increase in security findings after AI adoption, Fortune 50 sample
20%
AI code samples referencing packages that don't exist
Figures from Veracode's GenAI Code Security testing and Apiiro's enterprise repository analysis, as reported by the Cloud Security Alliance.
Illustrative figure. Constructed for explanation, not a measured source.

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. 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.

Figure 2
How much more often issues appear in AI-authored pull requests
Readability issues3Security issues3Error handling gaps2Logic and correctness2Overall issues per PR2
Based on CodeRabbit's analysis of 470 open-source GitHub pull requests (320 AI-co-authored, 150 human-only).
Illustrative figure. Constructed for explanation, not a measured source.

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. Attackers now register those exact names, a technique called slopsquatting, so a hallucinated import can become a real malicious dependency before anyone notices. One such fake package accumulated over 30,000 downloads in three months with no code and no README.

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. 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. Instinct won't rescue reviewers either, since in one internal test people barely beat a coin flip at spotting AI-generated work.

How do you 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. 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. 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. 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. 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. An AI reviewer catching stylistic problems is not the same as a security control catching a privilege escalation path.

Why should you 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.

Frequently Asked Questions

5 questions

How do you review AI-generated code for security issues?

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.

Is AI-generated code less secure than human-written code?

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.

What is an acceptance gate for AI coding agents?

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.

What is slopsquatting?

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.

Should every AI-generated pull request get a human review?

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.

How we source, write, and correct our articles. Editorial standards

Related articles

Straight to your inbox.
New pieces as they publish. No noise.