Evaluating and Selecting LLMs for Code Generation: A Practical Framework

    This article presents a practical approach to evaluating and selecting large language models for code generation. It explains why "working code" is not the same as "deliverable code," introduces a four-dimension scoring framework, analyzes common defect patterns, and outlines a reproducible testing pipeline with enterprise adoption guidance.

    1. The Problem: Why “It Works” Is Not “It Ships”

    As AI coding tools iterate quickly, the real challenge for teams is no longer whether a model can write code, but whether the generated code can enter the delivery workflow directly. A comparison in the source material illustrates a common pattern: with reasoning effort maxed out, one type of model performs well on overall architecture and visual coherence, yet remains rough on details such as button spacing, element sizing, font size, and color choices. Another type follows a constraint checklist strictly, with only a few minor interaction oversights. The takeaway is that code generation quality is layered: macro-level design and micro-level details belong to different capability tiers and must be measured with different metrics.

    2. A Four-Dimension Evaluation Framework

    Break the evaluation into four orthogonal dimensions to avoid vague conclusions like “it looks good overall.”

    1. Functional completeness: whether every feature in the requirements document is implemented, with no missing fields or effects.
    2. Constraint adherence: the compliance rate for the tech stack, naming conventions, directory structure, and performance and compatibility constraints.
    3. Aesthetic and interaction quality: layout hierarchy, spacing rhythm, control sizing, color contrast, and accessibility.
    4. Cross-module consistency: whether the same property is implemented uniformly across pages and components, and whether contradictions cause defects.

    A sample scorecard structure:

    1. scorecard = {
    2. "completeness": {"weight": 0.35, "score": 0},
    3. "constraint": {"weight": 0.25, "score": 0},
    4. "aesthetics": {"weight": 0.20, "score": 0},
    5. "consistency": {"weight": 0.20, "score": 0},
    6. }
    7. def total(s):
    8. return sum(v["weight"] * v["score"] for v in s.values())

    The weights separate “rough details but complete features” from “missing features but consistent style.” The former is suitable for a polishing workflow; the latter needs to go back to requirements alignment.

    3. Pattern Analysis of Defect Types

    A useful observation from the source material is that omissions follow no fixed pattern but concentrate at the detail level, such as a specific UI effect or property field; whole-feature omissions are rare. Meanwhile, inconsistent implementations across the codebase cause defects that are hard to locate. This supports a defect taxonomy:

    • Detail omissions: affect experience but not the main flow; fixable in one pass of style and field completion.
    • Consistency defects: affect maintainability, are costly to fix, and require unified state management and component contracts.
    • Architecture-level gaps: low probability, but an automatic fail when they occur.

    Classifying defects this way makes the average number of fix rounds quantifiable, a key metric that reflects real delivery cost better than a single-pass rate.

    4. The Boundary Between One-Shot Delivery and Multi-Round Polishing

    Model output can be split into two tiers: one close to “passes once and ships,” and one needing one or more rounds of detail adjustment. The criterion is not subjective preference but the combination of fix rounds and fix types: style tweaks and field completion mean controllable polishing cost; interaction logic restructuring signals a misunderstanding of requirements. Teams can write this boundary into acceptance criteria to reduce review disputes.

    5. A Reproducible Testing Method

    Evaluation must be repeatable, which requires fixed inputs and criteria:

    1. Build a requirements document set covering three difficulty levels: simple pages, complex forms, and multi-module interactions.
    2. Fix the reasoning effort and prompt templates, and record versions and parameters to ensure comparability.
    3. Use double-blind review, scoring each of the four dimensions separately, with disputed items re-discussed.
    4. Run static checks and builds in a unified repository, using “does it compile” as a hard gate.
    1. # Generic pipeline example, independent of any vendor tooling
    2. lint && typecheck && build && test

    6. Enterprise Adoption Recommendations

    When running these practices on Baidu AI Cloud, a general capability combination can be used: object storage for test sets and artifacts, a container platform for batch evaluation jobs, and logging and monitoring with alerting to track failure rates and fix-round trends. Selection should not chase a single “strongest model” but route by scenario: high-risk, compliance-heavy scenarios prioritize constraint adherence, while innovation and showcase scenarios prioritize aesthetic and interaction quality, with human review retained. The result is a closed loop of “evaluation set, scorecard, pipeline, regression dashboard,” making model capability upgrades measurable and reproducible, and shifting delivery quality from individual experience to an engineering system.