Evaluating LLM Code Generation: Dimensions and Practical Methods

    This article explains why a successful one-shot demo does not guarantee usable code from large language models, and presents four evaluation dimensions: functional completeness and runnability, common-sense and physical consistency, instruction adherence and output consistency, and interaction with clarification. It includes practical scoring criteria, executable assertion examples, a reusable implementation plan template, and a reproducible evaluation workflow for selecting models that are ready for real engineering use.

    1. Background: Why “One-Shot Success” Does Not Mean “Usable”

    Over the past year, demos of AI coding tools have become increasingly impressive: interfaces with lighting, particles, fluids, and ink-wash styles can be generated in seconds with strong visual impact. However, when the same requirements document is given to multiple models, the results often contradict the demo. Once the code enters a real engineering workflow, problems tend to fall into three categories: missing physical and geometric common sense, inconsistency between the reasoning process and the generated output, and a lack of clarification for ambiguous requirements.

    Two typical observations can be generalized into evaluation conclusions. In the first, a bowling scene places the pins too far apart, making it impossible to knock down all pins in one throw. This is not a rendering issue but a missing common-sense constraint about the sport of bowling. In the second, an ink-wash scene claims in its reasoning to produce an ink-wash effect, but the final output has no related visual characteristics at all—a typical case of “reasoning disconnected from implementation.”

    2. Dimension 1: Functional Completeness and Engineering Runnability

    Functional completeness is the most basic layer. It is better to split it into three sub-items and score them separately, avoiding the coarse judgment that “it runs, so it passes”:

    • Runnability: whether dependencies are fully declared, whether there is a single startup command, and whether missing resources cause a blank screen.
    • Requirement coverage: check off requirement items one by one, such as scoring rules, turn switching, and end-game conditions.
    • Code quality: module separation, naming consistency, proportion of duplicated code, and obvious hardcoding.

    The practical recommendation is to prepare the same codebase and the same requirement plan, control variables, and compare multiple models side by side. Only then can differences be attributed to the model rather than the prompt. When multiple models pass on the first attempt, functional completeness often loses its discriminating power, and stricter dimensions are needed.

    3. Dimension 2: Common Sense and Physical Consistency

    This is currently the area where models most easily lose points and where demos most easily hide problems. You can build a “common-sense constraint checklist” that turns domain axioms into automatically verifiable assertions:

    1. // Example: express common sense as executable assertions
    2. const pins = generatePins({ rows: 4 });
    3. const gap = distance(pins[0], pins[1]);
    4. assert(gap < BALL_DIAMETER * 1.2, 'Pin spacing is too large for a single-strike clear');
    5. assert(totalPins === 10, 'There must be exactly 10 pins');

    Similar checklists can cover gravity and collisions, card counts and suit constraints, board row and column alignment, time and time zones, currency precision, and pagination boundaries. Using the assertion pass rate as a hard metric is more stable than manually watching demos.

    4. Dimension 3: Instruction Adherence and Output Consistency

    Inconsistency between the chain of thought and the output is a risk that should be addressed at the process level. There are two approaches. First, require the model to output a structured implementation plan (file list, key parameters, acceptance criteria) before generating code, and then perform item-by-item self-checking. Second, explicitly mark “style requirements that cannot be fully implemented” as risk items. For example, ink-wash brushstrokes and negative space are difficult to reproduce faithfully with pure geometric rendering; they should be downgraded to a deliverable approximation rather than promised in the reasoning and absent from the output.

    A reusable plan template:

    1. Goal: <one sentence>
    2. Files: <path + responsibility>
    3. Key parameters: <physical constants, rule constants>
    4. Acceptance: <list of executable assertions>
    5. Risks: <parts that cannot be fully implemented and fallback plans>

    5. Dimension 4: Interaction and Clarification

    Models behave noticeably differently when facing ambiguous requirements: some start coding immediately, while others ask several clarifying questions first. Clarification is not a defect but an effective way to reduce rework. During evaluation, you can track three metrics: number of questions, question hit rate, and number of rework rounds. In engineering practice, a three-stage collaboration of “clarify first, plan second, implement third” is preferable, keeping uncertainty out of the coding phase.

    6. A Reproducible Evaluation Workflow

    1. Fix the requirements and codebase, and unify prompts and parameters.
    2. Run each model several times, recording the first-pass rate and assertion pass rate.
    3. Classify failure samples by cause: missing common sense, instruction deviation, dependency errors, and insufficient interaction.
    4. Produce a radar chart and a failure sample library as a basis for subsequent model selection.

    For enterprise adoption, the test set and assertions can be hosted in a code repository, with a container platform providing isolated execution, logging and monitoring services collecting runtime data, and object storage saving output snapshots to form a closed loop.

    7. Conclusion

    Visual expressiveness has become a common capability across the industry; the real dividing line lies in common-sense consistency, instruction adherence, and collaboration style. Shifting evaluation from “watching demos” to “running assertions” is the way to select models that are usable in engineering. In related practices at Baidu AI Cloud, it is likewise recommended to drive model selection and effectiveness evaluation with executable acceptance criteria.