Manuscript Offprint

arXiv:2610.11300

Characterizing Overconfident Failure in LLM-Based Code Generation

Ravishka Rathnasuriya, Wei Yang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

RAVISHKA RATHNASURIYA, University of Texas at Dallas, USA

WEI YANG, Fudan University, China

Large language models (LLMs) are increasingly used for automated code generation, but generated programs can appear syntactically plausible while still failing execution-based correctness checks. Existing validation methods, such as testing and program analysis, remain essential but are often incomplete, costly, or applied only after generation. Model-derived uncertainty is therefore a natural early reliability signal.

This paper studies the dilemma of overconfidence in code LLMs where incorrect programs are often generated with token-level confidence comparable to correct programs. We study this dilemma across four open-source code models and three execution-based benchmarks. Our analysis begins by investigating whether existing uncertainty metrics provide reliable proxies for execution correctness in code generation. We then characterize overconfidence at both global and local token levels, asking whether incorrect programs remain indistinguishable from correct ones under confidence and entropy summaries, including selective generation and the limits of instruction tuning. Finally, we evaluate whether common mitigation strategies reduce this failure mode, and we examine latent representations as exploratory evidence for future reliability mechanisms.

Our study yields four findings. First, existing uncertainty signals provide only partial and model-dependent evidence of execution failure. Second, overconfidence persists at both program and token levels, and uncertainty-based selection does not consistently improve accepted-set accuracy. Third, instruction tuning can increase certainty on failing generations without consistently improving correctness discrimination. Fourth, common mitigation techniques improve specific aspects of reliability but do not reliably resolve overconfident failure. Our exploratory latent analysis suggests that hidden representations may encode correctness-related signals that output confidence does not expose. Together, these findings identify overconfident failure as a software-engineering reliability problem and offer a practical path toward building more reliable LLM-driven code-generation systems.

1 Introduction

Large language models (LLMs) have become increasingly effective at code generation, synthesizing implementations from natural-language specifications, programming tasks, and partial code contexts [1–5]. They are now integrated into software development workflows to assist with implementation, debugging, testing, and repair [6–9]. However, generated code is not self-validating. A program may be syntactically valid, idiomatic, and plausible while still violating the intended specification, especially on edge cases revealed only through execution. Thus, a central reliability challenge for LLM-based software engineering is not only whether a model can generate code, but whether a system can determine when generated code should be trusted.

Existing validation approaches primarily rely on execution-based evaluation [10–13] or program analysis [14–16]. These techniques are essential, but they do not fully solve the deployment-time reliability problem. Execution requires tests, input generators, or behavioral oracles, which may be incomplete, expensive, or unavailable for each generated candidate. Program analysis can identify specific defect classes, but it is often conservative, property-specific, and does not generally estimate whether an arbitrary generated program satisfies its specification. Moreover, both execution and analysis are typically applied after generation. This limits their ability to provide lightweight, model-intrinsic reliability signals during interactive code generation.

A natural alternative is an uncertainty-aware code-generation system. In an ideal setting, the system would know whether a generated program generalizes to unseen tests or real user inputs.

Authors' Contact Information: Ravishka Rathnasuriya, ravishka.rathnasuriya@utdallas.edu, University of Texas at Dallas, Richardson, USA; Wei Yang, yang_wei@fudan.edu.cn, Institute of Systems for Advanced Computing, Fudan University, Shanghai, China.

Ravishka Rathnasuriya and Wei Yang

Such a generalizability oracle is unavailable in practice, because functional correctness can only be established through validation against a specification, tests, or downstream behavior. Therefore practical systems must rely on proxies. The broader machine-learning literature operationalizes this proxy through uncertainty metrics derived from predictive distributions, confidence scores, entropy, margins, calibration methods, and related quantities. Such metrics have been extensively studied in classification tasks [17–27] and more recently in natural language generation (NLG) [28–33], where they are used as proxies for output correctness, factuality, or risk. These estimates also support selective abstention [34–36], where high-risk outputs are withheld or routed to additional validation.

However, uncertainty is less directly related to correctness in code generation than in classification or open-ended NLG. In classification, uncertainty is defined over the label distribution, and evaluation is performed on the predicted label. In open-ended NLG, uncertainty is commonly estimated over the generated response and evaluated against response-level properties such as correctness or factuality. In code generation, model probabilities are assigned during token generation, whereas correctness is determined by the execution behavior of the completed program. Therefore, a generated program can have high token likelihood and still fail to satisfy its specification. Thus, token- and sequence-level uncertainty are only proxies for execution correctness.

Using token- and sequence-level uncertainty as proxies for execution correctness creates a dilemma of overconfidence in code generation. A generated program may receive high model confidence and still fail execution-based evaluation. This mismatch is consistent with how code LLMs are trained and evaluated. First, autoregressive training optimizes next-token prediction rather than whether model confidence reflects execution correctness. Second, standard code-generation evaluation measures generation success rather than the reliability of model confidence. Pass@1 and pass@k measure [10–13] whether generated programs pass the evaluation tests, whereas binary grading gives no credit to abstention [37]. Therefore, such evaluation does not assess whether failing generations receive lower confidence than passing ones. Testing and program analysis provide evidence more directly tied to execution correctness, but they require external validation and may be costly or incomplete. Therefore, model-derived uncertainty remains attractive as an early reliability signal, despite the possibility of overconfident failures.

There is growing research interest in using uncertainty to support reliable code generation. Existing studies pursue three main directions. First, they evaluate uncertainty estimators as predictors of code correctness [33, 38]. Second, they calibrate confidence against observed correctness or use uncertainty to support abstention and other reliability decisions [39–43]. Third, recent studies examine how uncertainty behaves when it is used to guide candidate selection, correction, or other generation-time decisions [44, 45]. These studies show that uncertainty can provide useful information about correctness, but their evaluations mainly measure estimator performance or the effectiveness of an uncertainty-guided decision rule. However, important questions remain about the reliability of uncertainty as a proxy for execution correctness. Prior studies demonstrate that uncertainty can be informative, but they do not fully establish the extent to which it remains reliable when passing and failing generations receive similar uncertainty scores. It also remains unclear where this mismatch arises during generation, under which conditions it persists, and whether and to what extent common mitigation strategies can address it. Addressing these questions requires a systematic characterization of the reliability limits of model-derived uncertainty in code generation.

To characterize the reliability limits of model-derived uncertainty, we first conduct a preliminary study of existing uncertainty measures (Section 4). Across 17 generation-stage metrics and six prefill-stage metrics, no measure provides stable failure ranking across models and benchmarks. We then examine overconfidence through token confidence and predictive entropy at both program and token levels (Section 5). Failing programs often remain highly certain, including within their least-confident token regions. This misalignment affects selective generation where reducing coverage does not consistently increase selective accuracy and can decrease it when failures occupy high-certainty regions. Furthermore, instruction tuning can also increase certainty on failing generations without a corresponding improvement in correctness discrimination. These findings show that overconfidence is a distinct reliability problem where improvements in generation accuracy do not necessarily improve the model's ability to identify which generations are likely correct.

Finally, we evaluate whether common mitigation techniques reduce overconfident failure (Section 6). Post-hoc calibration substantially improves probability alignment, but calibrated scores provide little predictive skill beyond the benchmark pass rate. Repeated sampling improves recovery at small budgets, but its improvements diminish and a persistent set of tasks remains unsolved. Moreover, explicit abstention prompting likewise does not reliably induce deferral on incorrect generations. As an exploratory analysis, we find systematic pass–fail differences in latent-state geometry that are not reflected in output-token confidence. These results show that improving generation success or confidence calibration does not necessarily eliminate overconfident failure.

This paper makes the following contributions:

  • We formulate the dilemma of overconfidence in code LLMs as a barrier to practical uncertainty-aware code generation.

  • We show that existing uncertainty signals provide only partial and model-dependent evidence of execution failure across both prefill and generation stages.

  • We characterize overconfidence at program and token levels, and show that it can persist under selective generation and after instruction tuning.

  • We evaluate post-hoc calibration, repeated sampling, and explicit abstention, showing that none reliably resolves overconfident failure despite improving specific aspects of reliability.

  • We provide exploratory evidence that latent representations contain correctness-related structure not reflected in output uncertainty, motivating representation-aware reliability mechanisms.

References (72)