All posts

ComparisonDevfab Team10 min read

AI-generated code vs human-written code: quality, risk and review

AI-generated code vs human-written code: what 2025–2026 studies found on defects, security and complexity, when each fits, and how to review AI code safely.

AI-generated code vs human-written code: quality, risk and review

Short answer: Use AI-generated code for well-specified, testable work like CRUD screens, glue code and tests, where review is cheap and fast feedback matters. Keep humans writing, or closely owning, security-critical logic, unclear business rules and changes in large legacy code. Studies from 2025 and 2026 show AI code carries more defects and security issues.

AI-generated code and human-written code passing through the same review, test and security checks

You lead a team where half the pull requests now start with an agent. Some engineers say the code is fine. Others say they spend their days cleaning it up. Both groups are partly right, and the data is finally good enough to settle some of it. This page pulls together the main studies, then turns them into rules you can use in review.

In this guide, you'll learn:

Each claim below links to the study behind it.

Definitions

AI-generated code is code an AI model or agent writes, from a completion in your editor to a whole pull request opened by a cloud agent. A person may prompt, edit or approve it, but the first draft comes from the model.

Human-written code is code a developer writes, even if they look things up or copy patterns. In practice most teams now mix both, which is why studies have trouble labeling it. CodeRabbit, for example, had to infer AI co-authorship from signals in pull requests and said it "cannot guarantee" every PR labeled human was written only by humans (CodeRabbit, Dec 2025).

Vendors don't hide the risk. GitHub warns that Copilot "can produce incorrect or suboptimal code, including code that contains security vulnerabilities" (GitHub Docs). Lovable says its security scans "support secure development but do not guarantee it" (Lovable FAQ). Anthropic notes that a Claude Code review with no findings "doesn't mean your code is error-free or secure" (Claude Code Review).

What the studies found

QuestionAI-generated codeHuman-written codeSource
Issues per pull request10.83 on average (about 1.7x)6.45 on averageCodeRabbit, 470 PRs
Logic and correctness75% more commonBaselineCodeRabbit
Readability issuesMore than 3x higherBaselineCodeRabbit
Security issuesUp to 2.74x higher; "more high-risk security vulnerabilities"Fewer high-risk findings in Python and JavaCodeRabbit; Cotroneo et al., 2025
Typical defectsUnused constructs, hardcoded debugging artifacts, repeated boilerplateMaintainability issues typical of mature codeCotroneo et al., 2025; Improta et al., 2026
Size and complexitySmaller, simpler, "structurally compressed and stylistically templated"About 1.6x to 1.8x the cyclomatic complexityImprota et al., 2026
Security pass rate on test tasksAbout 56%, flat year over year; syntax passes almost alwaysNot measuredVeracode via SD Times, Jul 2026
Speed for experienced developers19% longer with AI tools in one trialBaselineMETR via InfoWorld, Jul 2025
Illustration: where AI-generated and human-written code tend to differ, and the checks that catch each

A few notes on reading this table:

  • The CodeRabbit study looked at 470 open-source GitHub pull requests: 320 AI co-authored and 150 human-only. It found more critical and major findings in AI PRs (roughly 1.4x to 1.7x), nearly twice the error-handling gaps, and excessive I/O about 8 times as often. No issue category was unique to AI. CodeRabbit sells an AI review tool, so read it as vendor research.
  • The academic studies come from the same research group. The 2025 paper compared over 500,000 Python and Java samples from three models. The 2026 follow-up compared 787,562 matched function pairs in Python, Java and C. It found that security results depend on language: models produced more and more severe findings in Python and Java, but in C humans had more high-severity memory-safety findings. AI code scored higher on a maintainability index, which the authors say mostly reflects its smaller size, not better quality.
  • Veracode's 2026 report found an average security pass rate of 56%, with the best model at 68% and Java the weakest language at 30%. In short: AI code compiles, but nearly half of security tasks fail.
  • METR's trial had 16 experienced developers do 246 real tasks on large, mature repositories. They expected AI to cut their time by 24%. They took 19% longer, and afterwards still believed AI had sped them up by 20%.

The pattern: AI code is shorter, more uniform and more often wrong in ways that pass a quick read. Human code is longer and more complex, and its problems look like the problems of an old codebase.

When to choose AI-generated code

  • The task is well specified and easy to test. Forms, CRUD screens, API clients, data migrations with clear rules and test scaffolding.
  • You have tests that would catch a wrong answer. AI code's main risk is logic that looks right. Tests that click through the user journey catch that.
  • The pattern already exists in your codebase. AI is good at repeating a pattern; give it a good one to copy.
  • You need a prototype to react to. A rough first version helps people agree on what they want before anyone polishes it.
  • The reviewer knows the area. Readability issues were more than three times as common in AI PRs, so review needs someone who can spot what is missing.

When to choose human-written code

  • Authentication, permissions and payments. CodeRabbit's most common AI security patterns were improper password handling and insecure object references.
  • Rules nobody has written down. If the spec lives in someone's head, a model will guess. A person should write it, or at least write the spec first.
  • Large, old codebases. The METR slowdown came from mature repos averaging over a million lines. Context matters more than typing speed there.
  • Performance-critical paths. Excessive I/O was about eight times as common in AI PRs.
  • Code you must defend in an audit. You need to explain why each line exists; that is easier when a person made the choices.

How to review AI-generated code

  1. Label it. Mark agent-authored commits or PRs so you can target review and track defect rates.
  2. Review the plan before the diff. A wrong approach is cheaper to reject than a wrong pull request.
  3. Check what the change touches. Ask which callers, APIs and screens depend on the code that changed.
  4. Run tests that act like a user. Unit tests miss broken journeys; end-to-end tests that click through the screens catch them.
  5. Scan for security issues every time, and treat a clean scan as a minimum, not a pass.
Illustration: a review flow for AI-generated code, from plan to user-journey tests

Where an AI software factory fits

The studies don't say "stop using AI." They say AI code needs a stricter process around it than a single agent in an editor provides. That is the job of an AI software factory.

Coding agents automate the developer. Devfab automates the development lifecycle. Three parts of Devfab map directly to the risks above:

  • Research and an approved plan before code. Devfab's Researcher maps the domain (key terms, best practices, competitors) before the Planner writes the plan, and a person approves the plan. For a school portal, that means rules about guardians, report access and term dates are written down before an agent guesses.
  • ChainFlow for impact. Devfab's code-intelligence layer maps which functions and APIs call each other and what is deployed, so dev agents see the effect of a change and don't break connected features.
  • A QA agent that acts like a user. It runs UI and flow tests (screens, buttons and user journeys clicked end to end) plus logic tests, the checks that catch code which looks right but isn't.

Code lives in your own GitHub account, and cost is logged after each run, per task and per project. Devfab is in Beta, has a smaller community and fewer integrations than mature tools, and is not an editor for hands-on coding. Read more in AI code review vs a QA agent and What is an AI software factory?.

FAQ

Is AI-generated code worse than human-written code?

On average it carries different and often more problems. A CodeRabbit study of 470 pull requests found about 1.7 times as many issues in AI co-authored PRs, and an academic study found more high-risk vulnerabilities in AI code. Human code showed more maintainability issues and more complexity.

Is AI-generated code secure?

Not by default. Veracode's 2026 report says models pass security checks on about 56% of tasks, while syntax passes almost always. That means the code compiles and runs but often still has security flaws. Treat every AI change as untrusted until it is scanned and reviewed.

Does AI make developers faster?

It depends on the task and the developer. In METR's 2025 randomized trial, 16 experienced open-source developers took 19% longer on real tasks with AI tools, yet believed AI had sped them up by 20%. Measure your own team rather than relying on how it feels.

Should we label AI-generated code in our repo?

It helps. Studies had to infer authorship from signals, which shows how hard it is to tell later. Recording which changes an agent made, in commit messages or PR labels, lets you target review and compare defect rates over time.

Who owns AI-generated code?

Ownership depends on your tool's terms and your contracts, so check both. Several vendors state they do not own the generated code; for example, Vercel says it does not own code generated by v0. Keep the code in a repository your organization controls.

Want AI-written code that comes with a plan, impact map and user-journey tests? Try Beta

Frequently asked questions

Is AI-generated code worse than human-written code?

On average it carries different and often more problems. A CodeRabbit study of 470 pull requests found about 1.7 times as many issues in AI co-authored PRs, and an academic study found more high-risk vulnerabilities in AI code. Human code showed more maintainability issues and more complexity.

Is AI-generated code secure?

Not by default. Veracode's 2026 report says models pass security checks on about 56% of tasks, while syntax passes almost always. That means the code compiles and runs but often still has security flaws. Treat every AI change as untrusted until it is scanned and reviewed.

Does AI make developers faster?

It depends on the task and the developer. In METR's 2025 randomized trial, 16 experienced open-source developers took 19% longer on real tasks with AI tools, yet believed AI had sped them up by 20%. Measure your own team rather than relying on how it feels.

Should we label AI-generated code in our repo?

It helps. Studies had to infer authorship from signals, which shows how hard it is to tell later. Recording which changes an agent made, in commit messages or PR labels, lets you target review and compare defect rates over time.

Who owns AI-generated code?

Ownership depends on your tool's terms and your contracts, so check both. Several vendors state they do not own the generated code; for example, Vercel says it does not own code generated by v0. Keep the code in a repository your organization controls.