LLM Coding Evaluation: Quality, Visual Tasks, and Cost
This article presents a practical engineering approach to evaluating coding-focused large language models. It explains why ad hoc “write a few examples” selection is unreliable, then describes task layering, executable assertions, sandboxed testing, quantitative metrics, visual and 3D acceptance checks, effective cost modeling, model routing, and continuous regression pipelines. The goal is to turn LLM model selection from a one-time judgment into a repeatable, measurable, and auditable engineering process.
1. Why ad hoc “write a few examples” model selection fails
Many teams evaluate coding-oriented large language models by asking engineers to write a few familiar problems, comparing the answers, and then choosing a model. The problem is not a lack of seriousness; the problem is that this process is systematically unreliable:
- Single-sample evaluation has high noise. Generative models may produce different results across repeated samples of the same prompt. One output may pass, while another may fail. A single observation cannot distinguish “strong capability” from “good luck.”
- Prompt sensitivity is often underestimated. The same requirement may have very different pass rates depending on wording, ordering, or the presence of constraints. Comparing models with casually written prompts often measures prompt quality rather than model capability.
- Public problems may be contaminated by training data. Algorithm problems and interview questions found online are likely to have appeared in pretraining corpora. Scores based on such problems reflect memorization rather than reasoning ability.
- Metrics may be disconnected from business needs. “Fast output” or “complete comments” does not mean “production-ready.” The real determinants of delivery cost are first-run success rate, amount of rework, and density of security defects.
- Cost is often compared only on the price list. A model that is several times cheaper per unit may still be more expensive overall if its first-pass success rate is only half that of the alternative. Repeated retries and manual fixes can quickly erase the price advantage.
Therefore, the goal of evaluation is not to produce a leaderboard of “which model is strongest.” The goal is to build a repeatable, regression-friendly measurement system that is structurally similar to actual business tasks.
2. Task layering: replace a single overall score with a capability profile
Coding tasks are not a flat surface. Mixing tasks of different difficulty and different nature into one average score produces conclusions with little decision-making value. It is better to organize the evaluation set into the following five layers, measure them separately, and make decisions by layer:
- L1 Snippet completion: logical completion within a single function, type annotations, and comment generation. This layer is most sensitive to latency.
- L2 Single-file function-level generation: algorithm implementation, data transformation, scripting tools, regular expressions, and configuration handling. Correctness can be fully and objectively determined with assertions.
- L3 Repository-level modification: multi-file changes, interface contract adjustments, dependency migrations, and legacy code refactoring. This layer tests long-context understanding and global consistency.
- L4 Visual generation tasks: generating frontend pages, charts, and programmatic code for 3D scenes and models from descriptions or screenshots. Evaluation must include rendering and screenshot comparison.
- L5 Diagnosis and repair: given error stacks, log snippets, and failing test cases, locate the root cause and provide a minimal fix. This layer is the most valuable in production and the hardest to evaluate.
The purpose of layering is to configure routing strategies, budget allocation, and fallback rules by layer rather than applying one model globally.
3. Building the evaluation set: executable assertions are better than subjective scoring
Recommended data sources. Evaluation data should combine three sources: de-identified samples from the organization’s own codebase, which are most representative of real business work; synthetic cases designed for boundary conditions, where coverage is controllable; and historical online tickets or incident reviews, which provide the strongest sense of real pain. Synthetic cases should deliberately include scenarios that easily expose defects, such as null values, overly long inputs, concurrency, and exception branches.
Leakage prevention must be institutionalized. Reserve a private holdout set that is run only during version upgrade reviews. At other times, use only the development set for prompt tuning. Otherwise, the evaluation set will unconsciously turn into a “prompt-tuning set.”
Assertion design principles. Wherever possible, convert “how good is it” into “does it pass.” Examples include: it compiles, it runs, assertions pass, there are no high-risk calls, no plaintext credentials, and no timeouts. Subjective items such as readability, naming, and design reasonableness may remain in human review, but only on a small sample, and they should be treated as reference signals rather than admission gates.
Below is a language-neutral illustrative execution framework showing key fields and statistical definitions:
# Illustrative pseudocode: evaluation executorcases = load_cases("private_holdout") # Private set; not used for prompt tuningresults = []for case in cases:prompt = render_prompt(case) # Fixed template, temperature, and maximum output lengthraw = call_model(route(case), prompt, # Routing decides which model tier to usebudget_ms = case.sla)patch = extract_code(raw) # Extract code blocks only; ignore explanatory wording differencesbox = new_sandbox(timeout = case.sla) # Isolated execution: no network, limited disk writes, limited CPUbuild = box.run("compile_or_parse", patch)tests = box.run("run_assertions", patch, case.tests)results.append({"case_id" : case.id,"level" : case.level, # L1..L5; used for layered statistics"pass" : build.ok and tests.all_passed,"first_runnable": build.ok, # Must compile or parse on the first attempt"edit_distance": diff_distance(patch, case.reference),"in_tokens" : raw.usage.input,"out_tokens" : raw.usage.output,"latency_ms" : raw.latency,"security" : scan(patch, rule_set) # Dangerous calls, injection patterns, plaintext credentials})report = aggregate(results) # Aggregate by layer; never merge into a single score
Sandboxing is a key engineering investment. Without isolated execution, generated code cannot be run safely, and evaluation degrades into manual code reading.
4. Metrics: decompose “usable” into measurable items
| Metric | Definition | Collection method | Primary use |
|---|---|---|---|
| First-pass success rate | Proportion of first outputs that pass all assertions | Automated sandbox | Core quality gate |
| First-runnable rate | Compiles or parses without manual modification | Automated sandbox | Measures grasp of syntax and interfaces |
| Assertion pass rate | Passed cases / total cases | Automated sandbox | Fine-grained defect distribution |
| Rework cost | Lines manually modified / lines generated | Diff comparison | Estimates hidden labor cost |
| Defect density | High-risk pattern hits / 1,000 lines | Static rule scanning | Security admission |
| Latency | Time to first token, total elapsed time | Gateway-side instrumentation | Completion and interaction experience |
| Cost per task | Input and output usage × unit price | Usage billing | Economic accounting |
It is important to note: a high pass@k but a low pass@1 indicates that capability exists but stability is poor. In that case, the right move is usually to add validation and retries, not to switch models immediately.
5. Visual and 3D tasks: executable acceptance is mandatory
Frontend restoration and 3D generation are the categories most easily deceived by “looks fine.” They are also the categories most suitable for objective acceptance, because the output itself can be rendered.
Frontend visual restoration. Render the generated result in a headless browser at multiple viewport sizes, capture screenshots, and compare them with reference images using structured checks: element count and hierarchy, position and spacing deviations, colors and font sizes, and whether overflow or misalignment occurs. Add accessibility checks such as semantic tags, contrast, and keyboard reachability, as well as responsive breakpoint checks. Human review is needed only when similarity falls into a gray area.
3D scene and model generation. Acceptance can be filtered in four stages:
- Loadability: can the scene be parsed by a headless renderer? Are there non-finite coordinates, invalid indices, or empty materials?
- Geometric plausibility: are bounding-box dimensions and units consistent? Are normals oriented correctly? Is the polygon count within budget?
- Visual correctness: render screenshots from multiple camera angles and check proportions, occlusion, lighting, and shadows.
- Runtime performance: measure frame time, draw calls, texture memory, and mesh memory usage.
This kind of acceptance depends on rendering compute. In engineering practice, it is suitable to use a container platform for one-off rendering jobs and store output screenshots in object storage for regression comparison.
6. The right cost model: effective cost, not unit price
The most common mistake in model selection is comparing only price per million tokens. A definition closer to real expenditure is:
Effective cost = (direct inference cost + human rework cost + operations and compliance cost) / passed tasks
Direct inference cost is calculated as:
Direct inference cost = average input/output usage × unit price × number of retries
Suppose two models differ in unit price by several times. Any numbers used for illustration are only to explain the method and do not represent any real product. If the lower-priced model has a significantly lower first-pass success rate, retries and manual fixes can easily make its effective cost higher than the alternative. When capability tiers are the same, a price difference is a net benefit. When capability tiers differ, the price difference can be consumed by rework.
Four cost-reduction measures can be implemented immediately:
- Prefix and semantic caching: system prompts, coding conventions, and common library snippets are stable prefixes and can reuse caching. Repeated questions can directly hit a semantic cache.
- Context slimming: use retrieval to fetch relevant file snippets instead of sending the entire repository. This reduces token usage and improves localization accuracy.
- Tiered invocation: route completion and formatting to low-latency, smaller models; route complex refactoring to high-capability models; route visual outputs through rendering validation.
- Prefer elasticity over permanent self-hosting: offline workloads such as evaluation and training can use batch processing and offline queues to stagger load. Online inference should prioritize cloud-hosted model services, while container platforms handle rendering and sandboxes. Logging and monitoring/alerting form cost dashboards and anomaly circuit breakers. The value of this combination is elasticity and faster model iteration, not being cheapest at a single point.
7. Model routing: turn evaluation results into runtime policy
If evaluation does not lead to routing, it has been done in vain. A reference implementation approach is:
def route(case):if case.level in (L1,): return cheap_fast_tier # Low-latency priorityif case.level in (L2, L5): return balanced_tier # Cost-performance priorityif case.level in (L3, L4): return strong_tier # Capability priorityreturn fallback_tier # Fallback for unknown task types
Runtime constraints are equally important: per-request timeout and token budget limits; retries and fallback after repeated failures; cost quotas and circuit breakers by project or tenant; and end-to-end tracing showing which model tiers a task passed through, how much it consumed, and its latency distribution. Without quotas and circuit breakers, a routing policy can fail instantly during an abnormal surge.
8. Continuous regression: turn evaluation into a pipeline
- Commit-level quick suite (a few minutes): run only core L1/L2 cases as a gatekeeper for prompt changes.
- Nightly full suite: run the complete layered evaluation and visual rendering comparison, producing trend curves.
- Upgrade review: when models or prompts change, use the private holdout for before-and-after comparison. Set guardrail metrics that must not regress, such as first-pass success rate, defect density, and latency. If any metric crosses the threshold, block release.
- Data governance: de-identify prompt and code samples before storing them. Define retention periods and access permissions. Use private access channels for cross-network calls and centralize secret management.
9. Common pitfalls checklist
- Drawing conclusions from public question banks—data contamination inflates scores.
- Testing only once—noise hides real differences.
- Averaging everything into one score—this hides key profiles such as “strong at completion but weak at refactoring.”
- Relying mainly on subjective evaluation—it cannot support regression or automation.
- Looking only at unit price—this ignores retries and rework.
- No sandbox—both evaluation safety and evaluation efficiency become uncontrolled.
- Evaluation disconnected from routing—conclusions cannot take effect.
10. Recommended implementation roadmap
In the first week, extract 100 to 200 samples from the organization’s own codebase and historical tickets, complete L1/L2 layering with executable assertions, and set up an isolated sandbox. In the second week, add usage and latency instrumentation, implement the effective cost model, and produce the first layered capability profile and cost profile. In the third week, deploy model routing, caching, quotas, and circuit breakers; integrate the evaluation quick suite into the commit pipeline; and bring up the nightly full suite and private holdout. After that, there is only one recurring action: make every model or prompt change leave behind comparable before-and-after curves in this system.
The value of the evaluation system is not to prove that one model is better than another. Its value is to turn model selection from a one-time intuitive judgment into a sustainable, auditable engineering capability that evolves with the business.
