LLM Code Generation Evaluation: Dimensions, Model Selection, and Workflow

    This article presents a practical framework for evaluating large language models for code generation using team-owned tasks and repositories. It covers four core dimensions—correctness and executability, long-context and cross-file consistency, structured task decomposition, and style fit and maintainability—along with measurement methods, model selection trade-offs, everyday workflows, common pitfalls, and code review and security checks.

    As large language models become part of daily programming work, developers often ask: which model writes code best? That question is hard to answer in one sentence. A good demo does not mean the model can pass the team’s tests, and one successful generation does not mean it can stay consistent across a project with dozens of files. This article does not rank specific products. Instead, it provides an evaluation method you can run yourself and summarizes a workflow for daily use, so teams can refer to it during model selection and adoption.

    Why Demo Results Are Not Enough

    Demos usually pick the smoothest tasks, refine prompts repeatedly, and then screenshot and share the results. In real work, requirements are often vague, context is long, and new code must align with existing interfaces. Therefore, evaluation should use the team’s own tasks and codebase and record the full process, including the number of failures, repair rounds, and manual changes.

    Four Core Evaluation Dimensions and Measurement Methods

    1. Code Correctness and Executability

    This is the most basic dimension. Prepare 50 to 100 tasks, each with a set of unit tests. Use the same prompt to call different models and record the following metrics:

    • Compile or interpret execution pass rate: whether the code runs without errors;
    • First-time unit test pass rate: the proportion of tasks where all tests pass without any modification;
    • Post-repair pass rate: the proportion of tasks that eventually pass after the model is allowed to repair the code for three rounds based on test errors;
    • Boundary case coverage: whether scenarios such as empty input, zero values, negative numbers, and very long strings are handled correctly.

    2. Long-Context Understanding and Cross-File Consistency

    In real projects, functions, types, and configuration are often spread across multiple files. You can build a small project containing 5 to 10 files and ask the model to call existing interfaces when adding a new module. Track the following metrics:

    • Reference consistency rate: the proportion of generated code where called function names, parameter names, and field names exactly match the original definitions;
    • Number of hallucinated references: the number of times the model calls functions or library APIs that do not exist in the project;
    • Effective context length: record the actual number of input tokens and compare it with the model’s claimed context window to find the point where performance drops noticeably.

    3. Structured Task Decomposition

    For complex requirements, a model needs to divide modules first and then design call relationships. During evaluation, give the same requirements document to the model and ask it to output module division and interface definitions. Two engineers independently score the result from 1 to 5 and check whether dependency relationships are complete.

    Take an order system as an example. A reasonable decomposition usually includes three modules: ordering, inventory, and payment. After an order request enters, inventory is reserved first; after payment succeeds, the deduction is confirmed; if payment times out or fails, the inventory is released. Order states include pending payment, paid, canceled, and completed. Every state transition must have corresponding checks and handling in the code. If there are circular dependencies between modules, or a state has no exit, the solution is considered unqualified.

    4. Style Fit and Maintainability

    Teams have different coding conventions, and models should follow them. You can use the team’s existing lint tools, such as flake8 for Python or ESLint for JavaScript, to count warnings in generated code. Also track comment coverage and compliance with logging conventions. Reviewers can score maintainability based on naming clarity, function length, and module cohesion.

    What to Weigh During Model Selection

    Models differ in reasoning depth, context length, response latency, cost per call, deployment method (cloud or local), and data usage terms. During selection, put these factors in the same table and compare them using the same evaluation set. Record model version numbers and test dates in the table because models are updated frequently and conclusions have a limited shelf life.

    Latency and cost matter as well. A model that produces correct results but takes tens of seconds per response may be less practical in interactive development than a faster model with slightly lower accuracy. When generating test cases or boilerplate in batches, unit cost becomes more important.

    Daily Workflow

    1. Split Tasks Before Generation

    Do not expect to generate an entire module in one pass. First ask the model to output class structures and interface definitions. After confirming they are correct, implement methods one by one. Run tests immediately after each function is completed.

    2. Use Structured Prompts

    You can refer to the following prompt template:

    Task: (describe the function to implement in one sentence)
    Language and version: (e.g., Python 3.11)
    Input: (field names, types, value ranges)
    Output: (structure and format of the return value)
    Exception handling: (errors to catch and how to handle them)
    Constraints: (allowed dependencies, performance requirements, prohibited patterns)
    Existing interfaces: (paste relevant function signatures or type definitions)

    The more complete the information, the higher the first-pass usability usually is.

    3. Close the Test Feedback Loop

    • Run unit tests immediately after generation;
    • Paste failure messages back to the model as-is and explain the expected behavior;
    • After each repair round, check whether functions unrelated to the problem were changed;
    • If three consecutive rounds still fail, rewrite that part manually instead of continuing to stack patches.

    4. Common Error Checklist

    During review, focus on the following issues:

    • Boundary errors: empty lists, zero, negative numbers, and date calculations across time zones;
    • Unreleased resources: file handles, database connections, and network sessions not closed;
    • Concurrency issues: multiple threads or coroutines sharing mutable state without locking;
    • Hallucinated APIs: calls to nonexistent library functions or parameters;
    • Log leakage: passwords, tokens, or user privacy written to logs.

    5. Code Review and Security Checks

    Model-generated code must not go online without review. Review should cover the following risks:

    • Injection vulnerabilities: whether SQL concatenation, system command concatenation, and template rendering use parameterization or escaping;
    • Path traversal: whether file paths from user input are normalized and checked against a whitelist;
    • Unauthorized access: whether interfaces verify the caller’s identity and operation permissions;
    • Dependency risk: whether newly added third-party packages have known vulnerabilities, which can be checked with dependency scanning tools;
    • Licenses: generated code may resemble code in public repositories, so confirm whether it complies with the team’s license policy;
    • Data leakage: whether prompts contain keys, customer data, or internal confidential information, and whether they comply with the company’s data usage rules.

    Common Questions

    How should LLM code generation be evaluated?
    Build an evaluation set according to the four dimensions in Section 2, fix the prompts and runtime environment, record pass rates, repair rounds, latency, and cost, and then compare the results.

    What should be considered during model selection?
    First identify the most common task types for the team, then compare model performance on those tasks. At the same time, confirm whether data policies, deployment methods, and costs meet requirements, and avoid relying on a single metric.

    How should generated code be code-reviewed?
    Run tests and static checks first, then manually verify boundary conditions, security risks, and dependency changes. Pay special attention to the model-generated parts.