mlsanityData to 14 Oct 2026

Uncertainty-Guided Chain-of-Thought for Code Generation with LLMs

arXiv 2503.15341 ↗First posted 19 Mar 2025cs.SEcited by 32

On the map: LLM reasoning → Reasoning for agents, planning and code

Abstract (arXiv)

Chain-of-Thought (CoT) reasoning has been demonstrated as an effective technique for improving the problem-solving capabilities of large language models (LLMs) in the context of code generation. However, existing CoT methods often exhibit a tendency toward "overthinking", where the LLM consistently applies reasoning strategies without adequately considering the task's underlying complexity. This results in the LLMs allocating excessive computational resources, in terms of tokens, to relatively simple tasks or problems where the correct answer is already evident. Additionally, this overthinking may lead LLMs down incorrect reasoning paths, resulting in incorrect code generation. In this paper, we introduce UnCertainty-Aware Chain-of-Thought (UnCert-CoT), an LLM-based approach designed to enhance code generation by incorporating an uncertainty-aware CoT reasoning mechanism, which focuses computational resources on targeting points where LLMs are more prone to error. We propose two confidence-based uncertainty measures: Entropy-based and Probability Differential-based methods. When uncertainty is high, UnCert-CoT activates CoT-decoding to generate multiple reasoning paths and selects the final code that exhibits the highest likelihood of correctness. In contrast, LLM directly generates the code when uncertainty is low. This uncertainty judgment mechanism allows LLMs to prioritize complex tasks and avoid unnecessary steps in simpler cases, thereby improving overall efficiency and accuracy in code generation. Our experimental results demonstrate that UnCert-CoT significantly enhances code generation accuracy on challenging benchmark MHPP(Mostly Hard Python Problems), it achieves improvements up to 6.1% on PassRate accuracy, particularly in situations where traditional LLMs are prone to errors.

Key facts. Cited by 32 papers in the map (data through 14 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 20 of its 26 references that are in the map. First posted on arXiv 19 Mar 2025.

Builds on

20 of 26 references.

Closest ancestors · 3

Same direction, newest first

  1. 2024Qwen2.5-Coder Technical Report18 Sep
  2. 2023Structured Chain-of-Thought Prompting for Code Generation11 May
  3. 2023Teaching Large Language Models to Self-Debug11 Apr

Other references · 17

  1. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  2. 2022Large Language Models are Zero-Shot Reasonerscited by 4,374
  3. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  4. 2022Challenging BIG-Bench Tasks and Whether Chain-of-Thought Can Solve Themcited by 1,807
  5. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
  6. 2022Large Language Models Are Human-Level Prompt Engineerscited by 1,045
  7. 2024Do NOT Think That Much for 2+3=? On the Overthinking of o1-Like LLMscited by 570
  8. 2024Chain-of-Thought Reasoning Without Promptingcited by 210
  9. 2023Planning with Large Language Models for Code Generationcited by 182
  10. 2022Natural Language to Code Translation with Executioncited by 124
  11. 2022Repository-Level Prompt Generation for Large Language Models of Codecited by 106
  12. 2024Calibration and Correctness of Language Models for Codecited by 49
5 more
  1. 2024Teaching Code LLMs to Use Autocompletion Tools in Repository-Level Code Generationcited by 30
  2. 2024MHPP: Exploring the Capabilities and Limitations of Language Models Beyond Basic Code Generationcited by 26
  3. 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applicationscited by 26
  4. 2023Guiding Language Models of Code with Global Context using Monitorscited by 20
  5. 2024Exploring Data-Efficient Adaptation of Large Language Models for Code Generationcited by 3

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 13; 2026: 19.

32 papers.

Sort:

By area:

  1. 2025TokUR: Token-Level Uncertainty Estimation for Large Language Model Reasoningcited by 24
  2. 2025Think Just Enough: Sequence-Level Entropy as a Confidence Signal for LLM Reasoningcited by 24
  3. 2026Uncertainty Quantification in LLM Agents: Foundations, Emerging Challenges, and Opportunitiescited by 20
  4. 2025Semantic Energy: Detecting LLM Hallucination Beyond Entropycited by 18
  5. 2025Temporalizing Confidence: Evaluation of Chain-of-Thought Reasoning with Signal Temporal Logiccited by 11
  6. 2025TreeDiff: AST-Guided Code Generation with Diffusion LLMscited by 11
  7. 2025Reasoning Efficiently Through Adaptive Chain-of-Thought Compression: A Self-Optimizing Frameworkcited by 6
  8. 2026From Reasoning Traces to Reusable Modules: Understanding Compositional Generalization in Language Model Reasoningcited by 5
  9. 2025Chain-of-Code Collapse: Reasoning Failures in LLMs via Adversarial Prompting in Code Generationcited by 4
  10. 2025Self-Reflective Generation at Test Timecited by 3
  11. 2026Lil: Less is Less When Applying Post-Training Sparse-Attention Algorithms in Long-Decode Stagecited by 3
  12. 2026Uncertainty Propagation in LLM-Based Systemscited by 3
20 more
  1. 2026Functional Entropy: Predicting Functional Correctness in LLM-Generated Code with Uncertainty Quantificationcited by 3
  2. 2025Fast, Slow, and Tool-augmented Thinking for LLMs: A Reviewcited by 2
  3. 2025Can Confidence Estimates Decide When Chain-of-Thought Is Necessary for LLMs?cited by 2
  4. 2025Reinforcement Learning-Guided Chain-of-Draft for Token-Efficient Code Generationcited by 1
  5. 2026Benchmarking Text-to-Python against Text-to-SQL: The Impact of Explicit Logic and Ambiguitycited by 1
  6. 2026Uncertainty and Fairness Awareness in LLM-Based Recommendation Systemscited by 1
  7. 2025Enhancing LLM Reasoning via Non-Human-Like Reasoning Path Preference Optimizationcited by 0
  8. 2025Lifecycle-Aware code generation: Leveraging Software Engineering Phases in LLMscited by 0
  9. 2026Synthesizing File-Level Data for Unit Test Generation with Chain-of-Thoughts via Self-Debuggingcited by 0
  10. 2026Structural Anchors and Reasoning Fragility:Understanding CoT Robustness in LLM4Codecited by 0
  11. 2026Improving LLM Code Generation via Requirement-Aware Curriculum Reinforcement Learningcited by 0
  12. 2026OracleTSC: Oracle-Informed Reward Hurdle and Uncertainty Regularization for Traffic Signal Controlcited by 0
  13. 2026ThinkBooster: A Unified Framework for Seamless Test-Time Scaling of LLM Reasoningcited by 0
  14. 2026Code-MUE: Measuring Code LLMs' Uncertainty through Execution-based Semantic Interaction Graphscited by 0
  15. 2026How Reasoning Shapes Social Bias in LLM-Generated Code?cited by 0
  16. 2026When Uncertainty Isn't Enough: An Empirical Study of Self-Correction in Code Generationcited by 0
  17. 2026GUT: Quantifying and Optimizing the Reasoning Uncertainty of LLMs via Graph Complexitycited by 0
  18. 2026Uncertainty Quantification for LLM Agents: A Taxonomy, an Evaluation Protocol, and an Empirical Studycited by 0
  19. 2026Visible Reasoning Is Not a Universal Optimizer: Persona- and Thinking-Dependent Effects in Analytics Code Generationcited by 0
  20. 2026The Optimal Decoder is Tilted Temperaturecited by 0

Similar, not cited

Close in wording, no citation either way

  1. 2023Chain-of-Thought in Neural Code Generation: From and For Lightweight Language Models
  2. 2025Code Execution as Grounded Supervision for LLM Reasoning
  3. 2025Scaling Code-Assisted Chain-of-Thoughts and Instructions for Model Reasoning
  4. 2025Understanding Chain-of-Thought Effectiveness in Code Generation: An Empirical and Information-Theoretic Analysis
  5. 2024Understanding Chain-of-Thought in LLMs through Information Theory
  6. 2025CoT-UQ: Improving Response-wise Uncertainty Quantification in LLMs with Chain-of-Thought
  7. 2025SEER: Enhancing Chain-of-Thought Code Generation through Self-Exploring Deep Reasoning
  8. 2026Hierarchical Chain-of-Thought: Enhancing LLM Reasoning Performance and Efficiency