Why can't AI-generated pull requests detect their own unsafe code?
The central issue is that AI code generators are trained to produce code that looks plausible, not code that is provably safe. A 2025 study of security-related AI-generated pull requests found that these PRs frequently introduce vulnerabilities detectable by static analysis tools like Semgrep [1]. The study's methodology—filtering PRs from high-star GitHub repos and manually validating security relevance—shows that AI-generated code changes are a real source of security risks, not a hypothetical concern.
Furthermore, a 2023 study of 21,000 pull requests from 25 popular Java projects found that code smells (indicators of poor design that often lead to faults) were present in 37% of accepted PRs and 44% of rejected PRs [2]. The most common smells were 'god classes' (classes that do too much) and 'long methods'—both of which make code harder to understand and more error-prone. The study also found that smelly PRs were more complex, had longer review times, and were submitted by less experienced contributors [2]. This suggests that AI-generated code, which lacks human judgment, is especially prone to these quality issues.
What AI review tools can and cannot catch
AI-powered code review assistants, like the one described in a 2024 study using the Falcon40-B model on the WatsonX platform, can provide initial feedback on code formatting, best practices, and minor issues [4]. They can also automate reviewer assignment and notification. However, the authors explicitly state that the goal is to evolve the bot into an 'intelligent reviewer capable of assessing code from a functional standpoint'—meaning it currently does not perform deep security or correctness analysis [4]. This tool is designed to streamline the review process, not to catch unsafe code changes.
Similarly, a 2024 study of GitHub's Copilot for Pull Requests found that while AI-generated descriptions reduced review time and increased merge likelihood, developers frequently had to manually edit the AI's output [3]. The study analyzed 18,256 PRs and found that developers 'often complement the automated descriptions with their manual input' [3]. This indicates that the AI's output is not trusted or accurate enough to stand alone, especially for safety-critical aspects. The AI can speed up routine tasks but cannot be relied upon to detect its own errors.
The bottom line: AI-generated code requires human validation
All four studies converge on the same conclusion from different angles: AI-generated pull requests are not self-validating. The security study [1] shows that AI code contains real vulnerabilities. The code smell study [2] shows that AI-like code (from less experienced contributors) is more likely to have quality issues. The Copilot study [3] shows that developers must manually correct AI outputs. And the AI review assistant study [4] shows that current AI tools are limited to surface-level checks.
There is no evidence in any of these studies that AI can detect its own unsafe code changes. In fact, the opposite is true: the tools that exist are designed to assist human reviewers, not replace them. If you are using AI to generate pull requests, you should plan for thorough human review, especially for security and design quality. The AI can help with speed and formatting, but the safety net must be human.
About These Sources
This answer is built on 4 studies (3 peer-reviewed, 1 preprint) — published from 2023 to 2025, 3 from 2024 or later, 1 in Q1–Q2 journals — selected as the most relevant from 4 studies that passed quality screening, drawn from 28 papers retrieved from a database of over 500 million.
Sources used in this answer
Replication Package: "Insights into Security-Related AI-Generated Pull Requests"
A 2025 study of security-related AI-generated pull requests from high-star GitHub repos used static analysis (Semgrep) to detect vulnerabilities, confirming that AI code changes frequently introduce security risks [1].
Code smells in pull requests: An exploratory study
A 2023 study of 21,000 pull requests from 25 Java projects found that 37% of accepted and 44% of rejected PRs contained code smells (god classes, long methods), and that smelly PRs were more complex and had longer review times [2].
Generative AI for Pull Request Descriptions: Adoption, Impact, and Developer Interventions
A 2024 study of 18,256 PRs using GitHub's Copilot for PRs found that AI-generated descriptions reduced review time and increased merge likelihood, but developers frequently had to manually edit the AI's output [3].
AI-Powered Code Review Assistant for Streamlining Pull Request Merging
A 2024 study introduced an AI bot using the Falcon40-B model on WatsonX for initial PR review, focusing on formatting and best practices, but noted it was not yet capable of functional or security assessment [4].
