{"slug": "how-to-evaluate-ai-generated-code", "title": "How to evaluate AI generated code?", "summary": "A developer argues that AI-generated code should be judged by functional correctness in a sandbox against tests stricter than the ones it already passes, not by how plausible it reads. Citing HumanEval, EvalPlus and a 2022 Perry et al. study in which 47 participants using codex-davinci-002 wrote less secure code while believing it more secure, the developer proposes one proportionate validation run plus one independent human review per pull request, treating AI reviewer comments as evidence to re-check rather than proof.", "body_md": "To evaluate AI generated code, judge it by what it does when it runs, not by how plausible it reads. HumanEval scores code models the same way, by functional correctness on unit tests, the way developers judge code. Its authors, [Chen et al.](https://arxiv.org/abs/2107.03374) (2021), also report evidence that BLEU, a fuzzy match against a reference solution, \"may not be a reliable indicator of functional correctness\".\n\nReading it, yours or a reviewer's, is not a check until the code has run in a sandbox against tests stricter than the ones it already passes.\n\nWhen something breaks in my repositories, I look before I guess: the logs first, then the source, and only after that a cause or a fix. \"Probably\" is not an answer when the data can be checked. Deciding that generated code works because it reads well is that kind of guess.\n\nYour own confidence does not count as data either. In a 2022 user study by [Perry et al.](https://arxiv.org/abs/2211.03622), 47 participants did five security-related programming tasks in Python, JavaScript and C, some with an AI assistant based on OpenAI's codex-davinci-002 and the rest without one. Those with the assistant wrote significantly less secure code than those without, and they \"were more likely to believe they wrote secure code than those without access to the AI assistant.\"\n\nMy rule for a pull request is one validation pass, proportionate to the change, and one independent review, with no reviews of reviews. Comments from an AI reviewer are not the validation pass; the run is. Asking a second model to re-check findings a reviewer has already posted is the kind of loop the rule keeps out.\n\nGitHub's [application card for Copilot agents](https://docs.github.com/en/copilot/responsible-use/agents) tells you to \"always review and verify the feedback generated by Copilot code review, and supplement Copilot's feedback with careful human review to ensure your code meets your requirements.\"\n\nSigma, a GitHub pull request reviewer, documents one template for every finding: the claim, why it matters, the evidence and a suggested change. Its [docs](https://sigma.mnemoverse.com/docs/reading-a-review?src=devto&utm_source=devto&utm_medium=article&utm_campaign=how-to-evaluate-ai-generated-code) say: \"How it was verified appears only when the finding carries a verification note and a verifier confirmed it.\" They also say: \"A verification label is agent-produced evidence, not proof that the code is correct.\" Anthropic's docs for its managed [Code Review](https://code.claude.com/docs/en/code-review) describe a verification step that \"checks findings against the code before they're reported\", and say its review \"works from reading the diff and the surrounding code, without building or running your code.\"\n\nAccept a finding only with evidence you can re-check. For a finding about what the code does, the re-check is a run: a test that fails before the fix and passes after it.\n\nRun it where you would run code from a stranger, somewhere it cannot do damage. Hugging Face's [code_eval](https://huggingface.co/spaces/evaluate-metric/code_eval/blob/main/README.md) metric is built to run untrusted code that models wrote, and its card strongly advises users against running it \"outside of a robust security sandbox\". It also quotes the warning in the metric's own code: \"model-generated code may act destructively due to a lack of model capability or alignment.\"\n\nThen doubt the tests it passed. HumanEval's original tests let wrong code through: [EvalPlus](https://arxiv.org/abs/2305.01210) (Liu et al., 2023) extended them by 80x into HumanEval+, and across 26 LLMs the stricter tests caught \"significant amounts of previously undetected wrong code synthesized by LLMs, reducing the pass@k by up-to 19.3-28.9%.\" Patches for real issues have the same problem. On SWE-bench Verified, the benchmark's validation \"causes 7.8% of all patches to count as correct while failing the developer-written test suite\", and 29.6% of plausible patches behave differently from the ground truth patches. Those numbers come from a 2025 study of patches from three issue-solving tools by [You Wang, Michael Pradel and Zhongxin Liu](https://arxiv.org/abs/2503.15223), whose manual inspection found 28.6% of the divergent patches to be certainly incorrect.\n\nWhen the suite is green, ask how strict the suite is. Make the tests stricter, with cases at the boundaries, and where a trusted implementation exists, run both versions on the same inputs and compare what they do; that is the idea behind Wang, Pradel and Liu's PatchDiff for differential patch testing. On an AI-written change, put your review time into these tests before you spend it on reading the diff line by line.\n\nSecurity is a separate question. The 2021 GitHub Copilot, given 89 scenarios relevant to high-risk CWEs, produced 1,689 programs, and [Pearce et al.](https://arxiv.org/abs/2108.09293) found approximately 40% of them vulnerable, using GitHub's CodeQL along with manual inspection. [BaxBench](https://arxiv.org/abs/2502.11844) (Vero et al., 2025) checks generated backend applications both ways, with functional test cases and with end-to-end exploits, across 392 tasks. In the paper's version of 30 May 2025, \"even the best model, OpenAI o1, achieves a mere 62% on code correctness\", and \"on average, we could successfully execute security exploits on around half of the correct programs generated by each LLM\". For security I would add a scanner such as CodeQL, which Pearce et al. used, and tests that try to abuse the code.\n\nCode models sometimes name packages that do not exist. With 16 popular LLMs for code generation and 576,000 code samples in two programming languages, [Spracklen et al.](https://arxiv.org/abs/2406.10279) (2024) found that \"the average percentage of hallucinated packages is at least 5.2% for commercial models and 21.7% for open-source models\", and they describe these hallucinations as a new form of package confusion attack. A made-up name can still resolve if someone has published a package under it, so finding the name in the registry settles nothing.\n\nThe [OpenSSF guide to AI code assistant instructions](https://best.openssf.org/Security-Focused-Guide-for-AI-Code-Assistant-Instructions) suggests telling the assistant \"Do not add dependencies that may be malicious or hallucinated.\" Add that line to your instructions, and check anyway, since it asks the model to catch its own mistake. Before anything installs a new package, look the package up in its registry and look at who publishes it.\n\nI read the papers and pages cited here on 19 November 2026. Papers get new versions and docs get edited, so this is how they stood that day, and each number belongs to the models, tools and dates its paper names.\n\nI build [Sigma](https://sigma.mnemoverse.com/?src=devto&utm_source=devto&utm_medium=article&utm_campaign=how-to-evaluate-ai-generated-code), the reviewer with the finding template above.", "url": "https://wpnews.pro/news/how-to-evaluate-ai-generated-code", "canonical_source": "https://dev.to/izgorodin/how-to-evaluate-ai-generated-code-3bm5", "published_at": "2026-11-28 10:34:00+00:00", "updated_at": "2026-11-28 10:43:30.972365+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "ai-safety", "developer-tools", "large-language-models"], "entities": ["GitHub", "Copilot", "Anthropic", "Claude Code Review", "Hugging Face", "OpenAI", "HumanEval", "EvalPlus"], "also_reported_by": [], "takeaway": "Validate AI-generated code by running it in a sandbox against tests stricter than those it already passes; EvalPlus's 80x-extended HumanEval+ tests cut pass@k by up to 19.3-28.9% across 26 LLMs by catching previously undetected wrong code.", "recommendation": {"advice": "Require a failing-then-passing test run in a security sandbox before accepting any AI code or review finding, and treat AI verification labels as evidence to re-check, not proof.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/how-to-evaluate-ai-generated-code", "markdown": "https://wpnews.pro/news/how-to-evaluate-ai-generated-code.md", "text": "https://wpnews.pro/news/how-to-evaluate-ai-generated-code.txt", "jsonld": "https://wpnews.pro/news/how-to-evaluate-ai-generated-code.jsonld"}}