LLM Code Generation: Capability Evaluation and Effective Usage Practices

    Short-term subjective impressions are a poor basis for judging an LLM’s coding ability. This article presents a reproducible engineering approach to evaluating and using LLM code generation: separate model capability from usage patterns, build small reproducible task sets, write structured prompts that capture engineering constraints, generate in steps with test-driven validation, supply minimal and traceable context, and enforce code review and regression checks. It also includes a troubleshooting checklist for common failure modes.

    Drawing conclusions about an LLM’s coding ability from only a few days of subjective experience can easily misattribute problems in task definition, context supply, acceptance method, and iteration strategy to model capability. A result that seems to show the model is “bad at everything” may actually reflect requirements that are too coarse-grained, missing critical context, no clear acceptance criteria, or multiple changes mixed into a single generation. Conversely, a so-called “basically one-shot pass” often does not happen simply because the model is stronger; it happens because the user decomposed the problem more reasonably, supplied more complete constraints, and validated the result more promptly. To evaluate objectively and obtain high-quality code generation consistently, subjective impressions need to be converted into a reproducible engineering method.

    1. First Distinguish “Model Capability” from “Usage Pattern”

    LLM code generation is a typical context-sensitive task. The same model can produce very different output quality under different prompts, codebase contexts, and acceptance criteria. When evaluating it, at least four categories of factors should be separated:

    1. Task factors: Whether the requirement is a single function, a single file, or a cross-module change; whether it includes implicit constraints such as compatibility, performance, and security.
    2. Context factors: Whether relevant interface signatures, data structures, dependency versions, error stacks, existing tests, and minimal reproductions are provided.
    3. Acceptance factors: Whether there are clear inputs and outputs, boundary conditions, regression scope, and “must not change” constraints.
    4. Iteration factors: Whether the process allows an interface draft first, then implementation, then tests, instead of generating the final version in one pass.

    If these variables are ignored and a conclusion is drawn directly from “it did not work well for a few days,” the conclusion has low reliability. A better approach is to build a small, reproducible task set: select several representative tasks, fix the context and acceptance criteria, record the one-pass success rate, rework count, regression defect count, and manual correction cost, and then compare results. Evaluation dimensions should not be limited to “whether the code runs.” They should also cover readability, maintainability, boundary handling, test coverage, and consistency with the existing architecture.

    2. Use Structured Prompts to Fill In Engineering Constraints

    A high-quality prompt is not “help me implement a feature.” It writes the requirement as a lightweight technical plan. It should include the following elements:

    • Goal: What problem to solve and what the success criteria are.
    • Context: Relevant files, interface signatures, data structures, dependency constraints, and existing behavior.
    • Constraints: Interfaces that must not be modified, compatibility requirements, exception handling, performance boundaries, and coding conventions.
    • Output form: A patch, a complete file, an interface draft, test cases, or risk notes.
    • Acceptance method: Example inputs and outputs, boundary conditions, and regression points.

    For example, a relatively robust prompt skeleton can be written as:

    1. Goal: Add pagination to the existing list query without changing the meaning of existing returned fields.
    2. Context: Existing interface signature, data structures, caller examples, and existing failing tests are provided below.
    3. Constraints: Maintain backward compatibility for old callers; default pagination parameters must not change existing behavior; error responses must follow the existing error structure.
    4. Output: Minimal-change patch + new tests + regression risk notes.
    5. Acceptance: Cover four scenarios: empty result, boundary page, out-of-range page, and regression of old callers.

    The value of this style is that it makes implicit requirements explicit. Many reworks are not caused by the model being unable to write code, but by the model not knowing which behaviors must not change, which exceptions must be preserved, and which callers must not be broken. The closer the prompt is to executable acceptance instructions, the more stable the generated result will be.

    3. Use Stepwise Generation and Test-Driven Development to Reduce One-Shot Risks

    For complex requirements, it is not advisable to ask for “add the feature and fix all historical defects along the way” in one pass. A more controllable approach is small-step iteration:

    1. First ask the model to restate the requirement and impact scope, and confirm that understanding is aligned.
    2. Then generate an interface draft or pseudocode, and manually confirm the boundaries.
    3. Then generate the minimal implementation and corresponding tests.
    4. Finally require regression checks and risk notes.

    For iterative requirements, you can ask the model to “fix related defects along the way,” but the scope must be limited: only fix regression issues directly related to this change, and output a change description. Otherwise, unrelated changes are easy to introduce and increase review cost.

    Test-driven development is critical here. Rather than asking the model to “guarantee there are no problems,” require it to provide verifiable assertions first. For example:

    1. def test_pagination_regression():
    2. page = list_items(offset=0, limit=10)
    3. assert len(page.items) <= 10
    4. assert page.total >= len(page.items)
    5. assert legacy_sort_order(page.items) == expected_order
    6. def test_empty_result():
    7. page = list_items(offset=0, limit=10)
    8. assert page.items == []
    9. assert page.total == 0

    Tests do not need to pursue complete coverage from the beginning, but they should cover core paths, boundary conditions, exception paths, and regression of old behavior. Only then does a “one-pass pass” have a verifiable basis rather than being a subjective impression.

    4. Context Supply Should Be “Relevant, Minimal, and Traceable”

    More context is not always better. Putting the entire codebase in at once may introduce noise and cause the model to focus on the wrong things. A more effective approach is to provide a minimal relevant set: interface definitions, callers, data models, error handling conventions, existing tests, and failure logs. For defect repair, provide minimal reproduction steps and a complete error stack, not just “it reports an error here.”

    At the same time, preserve change boundaries. Each generation should focus on one goal as much as possible, separating refactoring, formatting, dependency upgrades, and feature development. This makes problems easier to locate and roll back. For teams, common prompt templates, acceptance checklists, and evaluation tasks can be turned into internal assets so that different members achieve more consistent generation quality.

    5. Make Code Review and Regression Verification Mandatory

    LLM-generated code still requires human responsibility. Review should focus on interface compatibility, boundary conditions, exception handling, resource release, concurrency safety, logging and monitoring, test effectiveness, and whether there are issues that “appear to pass but do not cover the real path.” In particular, be wary of “self-proving correctness” caused by generated tests and implementation coming from the same source; add independent cases or manually constructed counterexamples.

    For engineering adoption, static checks, unit tests, integration tests, and regression verification should be included in a unified process. Generated code is only a candidate patch and must pass the same quality gates as human-written code. For scenarios that “fix historical defects along the way,” also require a change impact description and keep small commits in version management, avoiding a single commit that mixes multiple purposes.

    6. Common Pitfalls and Troubleshooting Checklist

    When the experience is poor, use the following checklist:

    • Are multiple requirements mixed into one generation?
    • Are interface signatures, data structures, or error stacks missing?
    • Is there no explicit compatibility constraint on what “must not change”?
    • Does the prompt only describe symptoms without providing minimal reproduction and acceptance examples?
    • Are regression of old features and boundary conditions ignored?
    • Is a single failed sample extrapolated into an overall capability conclusion?

    The conclusion is that evaluation of LLM coding ability should be based on reproducible tasks, structured prompts, test-driven development, and engineering review. The closer the usage pattern is to real engineering constraints, the more stable the generated results tend to be. Conversely, handing vague requirements, missing context, and mixed changes to the model and then drawing conclusions from short-term subjective experience is neither fair nor useful for guiding practice. Upgrading from “how did it feel after a few days” to “how can it deliver consistently on a fixed task set” is the technical path more worth adopting for developers and teams.