Building a Quality Evaluation Framework for AI-Generated Code
This article explains why a high pass rate on individual tests does not mean AI-generated code is ready to merge, using a comparison where full delivery rates fell below 10% despite strong new-behavior and regression results. It proposes a three-layer evaluation framework covering generation quality, engineering efficiency, and security compliance, along with a single decision metric called the full delivery rate. Readers will find a weighted scoring model, end-to-end efficiency metrics, mandatory security gates, and a step-by-step rollout path from pilot to scale.
1. The Problem: Why “It Runs” Does Not Mean “It Can Ship”
As more code is produced by AI coding tools, the first practical question teams face is not whether AI can write code, but how to decide whether a piece of generated code can be merged into the main branch. The source material provides a representative set of comparison figures: on new-behavior tests for algorithm tasks, two models achieved pass rates of 63.84% and 62.91%, a gap of less than one percentage point; on regression pass rates aggregated by test node, the figures were 93.24% and 89.15%; but once the measurement switched to a full delivery rate counted per task with all conditions satisfied at the same time, the numbers dropped sharply to 6.93% (7/101) and 7.92% (8/101).
These figures reveal a key engineering fact: high local metrics do not guarantee overall deliverability. A high new-behavior pass rate shows that the models can generate code that looks correct; a regression pass rate close to 90% shows that the changes cause relatively limited damage to existing functionality; but a full delivery rate below 10% shows that, on real task chains, requirements understanding, boundary conditions, exception handling, dependency constraints, style conventions, and security all have to hold simultaneously, and any missing link causes the task to fail.
The evaluation framework must therefore shift its goal from single-point accuracy to a joint satisfaction rate across all conditions, and break quality, efficiency, and security into dimensions that can be measured independently and also adjudicated together.
2. Overall Framework: Three Metric Layers and One Decision Rule
The recommended structure is “three metric layers plus one decision rule.”
The first layer is generation quality, which focuses on whether the code itself is correct, readable, and maintainable, including functional correctness, boundary condition coverage, clarity of naming and structure, and completeness of comments and documentation.
The second layer is engineering efficiency, which focuses on how the generation process and its output affect development efficiency, including first-pass rate, number of rework rounds, share of lines modified manually, build and test time, and context window utilization.
The third layer is security and compliance, which focuses on issues such as injection risk, unauthorized access, hardcoded sensitive information, insecure dependencies, and the introduction of non-compliant licenses.
The single decision rule is the full delivery rate: a task counts as successfully delivered only when all four gates — functionality, regression, security, and conventions — pass. This rule effectively avoids the illusion of “inflated metrics with no real delivery.”
3. Quality: How to Score AI-Generated Code
Quality scoring should use a weighted deduction model rather than simple accumulation. The base score is 100, and deductions are applied by severity: blocker issues (logic errors, null pointers, resource leaks) deduct 30 points; critical issues (missing boundaries, swallowed exceptions) deduct 15 points; major issues (messy naming, duplicated code) deduct 5 points; minor issues (insufficient comments) deduct 1 point. A final score below the threshold leads to direct rejection of the merge.
Example scoring logic:
def score_code(issues):weights = {"blocker": 30, "critical": 15, "major": 5, "minor": 1}score = 100for item in issues:score -= weights.get(item.severity, 0)return max(score, 0)
It is important to note that static rules can only cover part of the problem space. They must be combined with unit test coverage, mutation testing results, and sampled human review to form a dual-track mechanism of “machine pre-screening plus human verification.”
4. Efficiency: Look Beyond Generation Speed
A common mistake in efficiency evaluation is treating generation time as the core metric. What really affects delivery is the end-to-end cycle: the total time from requirements input to code merge. Four types of data are worth collecting: first-pass rate, average number of rework rounds, the share of manually modified lines out of all generated lines, and build and test pipeline time.
If the share of manual modifications stays above 50% over time, the generated output has low usability, and the apparent speedup actually slows things down; if rework rounds exceed 2, the requirements clarification step is missing and should be reinforced in the prompt templates and task breakdown stage. Efficiency metrics should be read together with quality metrics, since optimizing either one in isolation distorts the picture.
5. Security: Mandatory Gates That Must Come First
Security cannot be a post-hoc fix; it should be a mandatory gate before merge. At a minimum, this includes static application security testing to scan for injection and cross-site risks, dependency composition analysis to identify known vulnerabilities and license conflicts, detection of hardcoded keys and tokens, and review of permission and unauthorized access patterns.
In engineering terms, security scans can be packaged as a separate stage in the pipeline that blocks progress on failure:
stages:- lint- unit_test- sast- dependency_check- secret_scan- gate
It is also advisable to introduce “provenance tagging” for AI-generated code to support later auditing and accountability tracing, but the tag itself does not change how strict the quality gates are.
6. Implementation: From Pilot to Scale
Step one, run a pilot on low-risk modules and establish baseline data. Step two, make the full delivery rate the single north star metric, with other metrics serving as diagnostic indicators. Step three, harden the gates into the pipeline so that nothing merges without meeting the bar. Step four, review failed samples weekly and feed high-frequency failure patterns back into task templates and the knowledge base. Step five, gradually expand to more business lines while keeping metric definitions consistent.
If an organization already uses common cloud capabilities such as container platforms, logging services, and monitoring and alerting, evaluation results can be collected into the logging and monitoring system to build a visualization dashboard, making cross-team comparison and continuous improvement easier.
7. Conclusion
Evaluating AI-generated code is essentially about turning “it feels reliable” into “it can be measured.” When the full delivery rate is only a single digit, the problem usually lies not in the model’s single-point capability but in the evaluation criteria and the gate system. Building three-dimensional scoring across quality, efficiency, and security, and using joint satisfaction of all conditions as the decision standard, is the practical path to getting AI-generated code into production.
