How to Evaluate Code LLMs: Stability and Post-Training Capability
A practical guide to evaluating code generation models: six core capability dimensions, verifiable-reward post-training strategies, how to build an in-house reproducible evaluation pipeline, and key considerations for interpreting results and adopting AI-generated code in production.
From “Which Is Better” to “How to Measure”
When evaluating code generation models, many people rely on personal impressions or community reputation—watching a demo or two, or hearing that a model “writes smoother code.” This kind of judgment is intuitive but easily influenced by example selection, prompt phrasing, and timing. The same model can perform very differently across tasks, and a single result rarely represents overall capability.
A more reliable approach is to build a reproducible evaluation framework that breaks vague concepts like “stability” into measurable metrics. Evaluation conclusions should answer three questions: How accurate is the model on target tasks? Are results repeatable? And when it fails, are the errors manageable?
Six Core Dimensions of Code Capability
1. Functional correctness
Functional correctness is the most fundamental metric, usually measured by unit test pass rate. It’s important to distinguish between “passing on the first generation” and “passing at least once across multiple samples.” The latter is commonly expressed as pass@k, with the unbiased estimator:
pass@k = 1 − C(n−c, k) / C(n, k)
where n is the total number of samples per problem, c is the number that pass the tests, and k is the number of samples used in the calculation. This metric reflects a model’s potential upper bound, but in production, humans typically accept only the first output or a few attempts, so first-attempt pass rate should also be tracked separately.
2. Stability and consistency
Stability refers to whether results remain consistent across repeated sampling, rephrasing, or slight context changes on the same task. It can be measured from three angles:
- Sample the same problem 10 times and measure the variance or standard deviation of pass counts;
- Use three to five equivalent phrasings of the same requirement and observe the range of accuracy fluctuation;
- Gradually increase context length and check whether accuracy drops significantly beyond a certain length.
A model with poor stability may look impressive in demos but frequently produce basic errors in batch tasks—exactly the problem development teams need to catch early.
3. Engineering adaptability
Real-world development rarely means writing a function from scratch; it means modifying an existing codebase. Engineering adaptability includes understanding cross-file call relationships, following existing naming and layering conventions, modifying only the code relevant to the requirement, and not introducing unrelated formatting or refactoring. Evaluations can include “modify an existing repository” tasks and check whether the change scope exceeds the requirement.
4. Instruction following and tool calling
In automated workflows, model output often must conform to fixed formats—for example, returning only structured data or calling tools in a prescribed order. Evaluation should check output format compliance, parameter completeness, and whether the model can correctly read error messages and retry after tool failures.
5. Self-correction
Feed compiler output, test reports, or static analysis results back to the model and observe whether it can fix issues within a limited number of turns. Track two metrics: “fix success rate” and “average number of turns.” Strong self-correction reduces the need for human intervention, but if the correction process frequently touches unrelated code, that should count against the score.
6. Security and compliance
Generated code should be checked for common vulnerabilities, such as concatenated SQL strings, unvalidated user input, hardcoded secrets, or overly permissive file permissions. Generic static analysis tools can scan outputs, and the frequency of high-severity issues can be tallied.
Code-Focused Reinforcement in Post-Training
Post-training typically involves supervised fine-tuning, preference optimization, and feedback-based reinforcement learning. In code scenarios, the most valuable signal type is verifiable rewards: whether code compiles, whether it passes tests, and whether the output matches expectations can all be determined automatically by programs, without relying entirely on human labeling.
Here is an illustrative reward function to demonstrate the idea:
def code_reward(solution: str, tests: list, timeout: float = 5.0) -> float:"""Use unit test pass rate as a verifiable reward; execution should run in an isolated sandbox."""if not compiles(solution):return -1.0 # Negative reward for uncompilable output, discouraging invalid responsespassed = 0for case in tests:if run_in_sandbox(solution, case, timeout):passed += 1return passed / len(tests)
This code omits the implementations of compiles and run_in_sandbox; the point is the design principles: rewards must be independently verifiable by programs, execution must happen in an isolated environment, and timeouts must be set to prevent infinite loops.
This training approach also carries risks worth watching:
- Reward hacking: The model may learn to hardcode return values tailored to specific test cases. Use undisclosed hidden test sets and refresh them regularly.
- Data contamination: Overlap between training data and evaluation problems inflates scores. Perform deduplication checks before evaluation, especially for problems sourced from public code repositories.
- Capability skew: Reinforcing only one task type (such as algorithm problems) may degrade performance in others. Both training and evaluation sets should cover a variety of task types.
Building Your Own Evaluation Pipeline
For teams selecting a model, the reliable approach is to build an internal evaluation set rather than relying entirely on public leaderboards. Recommended steps:
- Build a task set: Extract requirements from real business scenarios, covering new feature development, bug fixes, refactoring, and test writing, stratified by difficulty.
- Fix evaluation parameters: Standardize prompt templates, temperature, max output length, and context content to ensure fair comparisons across models.
- Sample multiple times: Take at least 5–10 samples per problem and record full outputs for later analysis.
- Automate judgment: Use tests and static checks for most scoring to reduce subjective judgment.
- Manually spot-check: Randomly sample a proportion of passing cases to check for “tests pass but logic is wrong” situations.
- Compute confidence intervals: Sample size determines how trustworthy conclusions are. With 100 problems and accuracy near 50%, the standard error of a binomial distribution is roughly 5 percentage points; if the gap between two models is smaller than that, don’t draw conclusions directly.
Interpreting Results: Common Pitfalls
Evaluation results must be interpreted in context. Several points are often overlooked:
- A single demo or a handful of examples says nothing about stability—rely on statistical results.
- Models sensitive to prompts can yield entirely different conclusions with rephrased prompts, so report the prompt template alongside the results.
- Public leaderboards may suffer from training data overlap; treat them as a reference, not the sole basis for decisions.
- There’s a significant gap between “can write code” and “can ship to production.” The former is about accuracy; the latter also depends on maintainability, security, and compatibility with existing architecture.
Practical Recommendations for Development Teams
First, treat model output as a draft awaiting review, not something ready to deploy. Code still needs testing, code review, and any necessary security scanning.
Second, roll out AI-generated changes in small batches with gradual release strategies, and keep fast rollback available.
Third, continuously collect failure cases and organize them into a regression test set. After every model swap or prompt adjustment, rerun this regression set to confirm no new regressions have been introduced.
Fourth, factor cost into your evaluation. A useful metric is cost per successful task: total API spend divided by the number of tasks that pass tests. Suppose two models have identical per-call costs, but one succeeds 80% of the time and the other 60%—the former’s cost per success is roughly a quarter lower. In real selection decisions, this difference is often more informative than one-off impressions.
In short, judging whether a code model is reliable comes down to building a reproducible evaluation methodology, replacing impressions with statistics, and being clear about which tasks the model handles consistently and which require human oversight.
