Code Uncertainty Needs Code-Specific Signals, Not NL Ports
A three-axis uncertainty estimator tailored to code properties improves error detection AUROC from 0.696 to 0.776 across five LLMs — and a single-pass token entropy signal alone can match multi-pass baselines at one-third the cost.
- What they did — Built three complementary uncertainty signals for LLM code generation — token-level entropy focused on high-uncertainty positions, pseudo-code consistency across sampled solution plans, and test-case pass-rate from self-generated tests — and combined them into an ensemble evaluated across four benchmarks and five models.
- Key result — The three-axis ensemble achieves 0.776 average AUROC across five models, up from 0.696 for the strongest NL-derived baseline (+8.1 points); on Qwen3-14B, single-pass Top-K token entropy alone matches the best multi-pass baseline at over 3× lower cost.
- Why it matters — Teams using NL-derived uncertainty methods for code generation are likely missing code-specific signals that could meaningfully improve error detection and selective prediction.
A three-axis uncertainty estimator tailored to code properties improves average error detection AUROC from 0.696 to 0.776 across five LLMs — and a single-pass token entropy signal alone can match multi-pass baselines while being over 3× cheaper.
The Problem
When an LLM generates code that's silently wrong — compiles fine, looks reasonable, but returns incorrect results — the consequences compound. Bad code slips past review, gets integrated into pipelines, and breaks things downstream. Uncertainty estimation (UE) is supposed to catch this: score how confident the model is in its output, then flag or defer low-confidence generations for human review [§1].
The problem is that current UE methods for code are borrowed directly from natural language generation. They compute things like average token likelihood or semantic similarity between sampled outputs — techniques designed for prose, where a wrong word rarely ruins the whole passage [§1]. Code is different. A single flipped operator can break an entire program. Two syntactically different implementations can encode the same algorithm. And unlike natural language, code can actually be *run* [§1].
These three properties — which the authors call token fragility, the intent–code gap, and executability — mean that NL-derived uncertainty methods are systematically ignoring information that's available and useful for code [§1].
What They Did
The core idea is to decompose code uncertainty into three independent axes, each targeting one code-specific property [§2].
**Lexical uncertainty (token fragility).** Instead of averaging entropy across all generated tokens — the NL default — this signal focuses on the *most uncertain* positions. The method computes per-token entropy from the model's output distribution, then averages only the K highest-entropy tokens [§2.2]. Think of it as checking the model's confidence only at the few critical decision points (which operator? which index? which function name?) rather than diluting that signal across hundreds of boilerplate tokens. This requires only a single forward pass — no resampling.
**Algorithmic uncertainty (intent–code gap).** Two correct quicksort implementations can look completely different syntactically, and two near-identical code snippets can encode different algorithms. Comparing raw code is unreliable. Instead, the method prompts the LLM to generate N natural-language solution plans — numbered reasoning steps, no code allowed — and measures how much those plans agree with each other using a step-aware text similarity metric [§2.3]. Low agreement across plans means the model is uncertain about *which algorithm to use*, independent of implementation details. Conditioning Qwen3-14B on ground-truth pseudo-code lifts MBPP pass@1 from 54% to 98%, confirming that algorithmic-level information carries substantial correctness signal [§2.3].
**Functional uncertainty (executability).** The model generates test cases for the problem, then the candidate program is executed against them in a sandbox. The uncertainty score is simply the fraction of self-generated tests that the program fails [§2.4]. This is a behavioral signal unavailable in any NL setting. Importantly, this is used as a *calibration* signal — scoring confidence — not as a selection mechanism like CodeT-style reranking [§2.4].
The three scores are combined via a rank-normalized weighted sum. The ensemble exists to demonstrate that the axes are complementary; the individual signals are the primary contribution [§1].
The Results
Evaluated across four benchmarks (APPS-Intro, APPS-Interview, HumanEval, MBPP) and five code-capable LLMs, the three-axis ensemble achieves 0.776 average AUROC, compared to 0.696 for the strongest NL-derived baseline — an improvement of 8.1 points [Abstract]. On Qwen3-14B specifically, the ensemble reaches 0.800 average AUROC [§1].
The single-pass Top-K token entropy signal is surprisingly strong on its own. On Qwen3-14B, it matches the strongest multi-pass NL baseline while costing over 3× less compute, since it requires no resampling [Abstract]. Across all five models, it remains competitive as a low-cost signal [§1].
A revealing diagnostic: splitting token entropy over code tokens versus comment tokens shows that code-only entropy achieves 0.716 AUROC, while comment-only entropy scores 0.375 — worse than random [§1]. Full-sequence averaging, the NL default, masks this asymmetry entirely.
The limitations are concrete. The evaluation uses four benchmarks with clean problem specifications and official test suites [§2.1] — production codebases involve ambiguous specs, mixed human-AI authorship, and partial test coverage, which would stress all three axes differently. The functional signal depends on self-generated tests, which can be wrong, biased toward easy cases, or miss edge conditions [§2.4]. The algorithmic signal requires N additional LLM calls to generate solution plans [§2.3], adding latency that may be impractical for real-time autocomplete. For teams needing production-grade uncertainty tooling for messy, real-world codebases, reliable solutions are likely still a few years out.
Why It Matters
This work demonstrates that treating code as "just another token sequence" for uncertainty estimation leaves measurable performance on the table. Each of the three code-specific axes independently matches or outperforms the strongest NL baseline on the property it targets [§1], and combining them yields clear gains.
For practitioners, the immediate takeaway is practical: if you're using likelihood-based or semantic-consistency UE in a code generation pipeline, Top-K token entropy is a drop-in, single-pass alternative that's cheaper and potentially more informative [§1]. The three-axis ensemble is better but requires execution infrastructure and multiple LLM calls.
This is a lab proof-of-concept — four benchmarks, five models, controlled conditions. But the finding that code-specific properties carry orthogonal uncertainty information is well-supported by the results and suggests that code UE methods should be designed for code, not inherited from NL.