Abstract
Large Language Models (LLMs) have transformed software development by automating code generation. However, these models often produce buggy or "hallucinated" code without any indication of uncertainty, placing a significant debugging burden on developers. We introduce HonestCoder, an execution-free framework designed to estimate LLM confidence through multi-modal consistency. By analyzing the similarity of multiple generated samples across text, syntax, data flow, and semantic embeddings, HonestCoder selectively filters out low-confidence outputs. Our evaluation on the TruthCodeBench benchmark shows that HonestCoder significantly improves the reliability of code suggestions, outperforming traditional confidence metrics like token probability by up to 27.79% in AUROC.
Introduction
While tools like GitHub Copilot are widely adopted, they remain prone to errors, failing on approximately 30-40% of programming requirements in standard benchmarks. The primary issue is not just the presence of bugs, but the lack of a "refusal" mechanism; LLMs typically provide a plausible-looking answer even when they are guessing. This forces developers to spend considerable time reviewing and debugging erroneous code, which can be ten times more costly than writing code from scratch.
Previous attempts to quantify LLM confidence have relied on internal model states (e.g., token log-probabilities), which often suffer from over-confidence. HonestCoder addresses this by shifting the focus to output consistency, assuming that a confident model will produce deterministic results across multiple attempts.
Methodology: Multi-modal Consistency
HonestCoder operates on the principle that if an LLM is truly "confident" about a solution, it will produce functionally identical code across multiple independent generation attempts. Conversely, uncertainty leads to diverse, inconsistent outputs. The framework uses an execution-free pipeline, avoiding the overhead and security risks of running unverified code.
The HonestCoder pipeline consists of three stages:
- Diverse Generation: For a given requirement, the LLM generates $N$ programs (typically 20) using temperature sampling to introduce diversity.
- Multi-modal Similarity Analysis: The system calculates similarity across four distinct modalities to capture different aspects of code logic:
- Textual: N-gram overlap of code sequences.
- Syntactic: Concrete Syntax Tree (CST) comparison to check structural consistency.
- Data Flow: Analysis of variable dependency graphs to ensure logical flow is identical.
- Semantic Embedding: Cosine similarity of the hidden states from the LLM's last layer.
- Selective Presentation: A weighted average of these similarities forms a confidence score. If the score falls below a threshold, the system refuses to provide code, sparing the developer from reviewing likely errors.
Results and Discussion
To evaluate HonestCoder, we developed TruthCodeBench, a multilingual benchmark (Python and Java) containing 2,265 samples with ground-truth pass/fail labels for several popular LLMs, including DeepSeek-Coder and Code Llama. This benchmark allows us to measure how well the confidence score aligns with actual execution success.
Key findings include:
- Enhanced Detection: HonestCoder achieved a 27.79% improvement in AUROC and a 63.74% improvement in AUCPR over baselines for Code Llama-7B. It effectively identifies "hallucinations" that surface-level metrics miss.
- Logic-Awareness: By incorporating data flow and syntax, HonestCoder identifies cases where code might look similar textually but contains fundamental logical flaws. As shown in the similarity distributions, correct programs exhibit significantly higher consistency across all four modalities.
- Efficiency: Parallel sampling keeps the overhead low, adding only ~0.4 seconds per request. This makes it suitable for real-time integration into IDEs.
Conclusion
HonestCoder provides a robust, execution-free method for making LLMs "honest" about their limitations. By leveraging multi-modal consistency, it effectively filters out buggy code, allowing developers to trust the suggestions they receive. Future work will explore integrating this with Selective Retrieval-Augmented Generation (RAG) to provide external help when internal confidence is low, further reducing the "silent refusal" rate.
Summary updated