Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation. However, their applicability to mission-critical systems is hindered by "code hallucination"—the tendency to generate code that appears syntactically correct but fails on edge cases or specific functional requirements. Addressing this bottleneck requires rigorous verification methods. This paper introduces a "selective generation" framework that allows models to abstain from answering when uncertain. By leveraging automated dynamic code analysis (fuzzing) to generate hundreds of unit tests, the proposed system provides rigorous, statistical guarantees on the functional correctness of the output.
The Challenge of Code Hallucination
The primary barrier to deploying LLMs in high-stakes software engineering is hallucination. In natural language tasks, correctness is often subjective and difficult to verify automatically. Code, conversely, is executable and objectively verifiable.
The standard approach to verifying generated code relies on unit tests. However, most existing benchmarks (such as HumanEval) provide only a sparse set of manual tests. This sparse testing creates a significant vulnerability: a model might pass a few basic tests but fail catastrophically on untested edge cases. To bridge this gap, the authors propose a system capable of saying "I don't know" (abstaining) when it cannot guarantee correctness. This approach effectively trades the quantity of generated answers for the quality and functional correctness of those answers.
Methodology: Fuzzing and Selective Generation
The authors propose a selective code generation pipeline consisting of several core components:
1. $\alpha$-Code Entailment & Fuzzing
The researchers redefine code correctness through a concept called "$\alpha$-code entailment." Instead of relying on a handful of manual tests, they employ dynamic code analysis—specifically fuzzing tools like Atheris—to automatically generate hundreds of diverse input-output pairs from a reference solution. A generated code snippet is considered "correct" only if it passes a rigorous threshold ($1-\alpha$) of these fuzzed tests.
2. Selective Generation (SCG)
The framework implements a selection function, $s(x)$. If the model's confidence score for a generated code snippet exceeds a calibrated threshold $\tau$, the system outputs the code. If the confidence falls below this threshold, the system abstains, returning an "I don't know" (IDK) response.
3. Statistical Calibration
The core innovation of this framework is a learning algorithm that utilizes a calibration dataset to find the optimal threshold $\tau$. This threshold is mathematically designed to bound the False Discovery Rate (FDR)—the probability that the model provides an incorrect answer—below a user-specified risk level (e.g., 10%).
4. FuzzEval Paradigm
To support this methodology, the authors introduce FuzzEval, a new evaluation paradigm where models are tested against massive suites of fuzzed unit tests rather than static, limited test cases.
Datasets
To rigorously test their framework, the researchers "fuzzified" four popular competitive programming and coding benchmarks, creating:
- APPS-f (derived from APPS)
- Mercury-f (derived from Mercury)
- HumanEval-f (derived from HumanEval)
- MBPP-f (derived from MBPP)
For each problem, solutions were manually post-processed to create fuzzing harnesses. This enabled the generation of at least 600 input-output pairs per problem, providing a robust foundation for calibration and testing.
Key Insights
- Code is Uniquely Verifiable: Unlike text summarization or dialogue, the executable nature of code allows for the use of classical software engineering tools (like fuzzers) to create scalable "ground truth" labels without human intervention.
- The Power of Abstention: Allowing a model to remain silent enables "certified" safety. In high-stakes environments, an admission of uncertainty is vastly preferable to deploying a buggy or insecure code patch.
- Fuzzing Outperforms Manual Tests: Manual unit tests are often too weak to catch subtle hallucinations. Fuzzing explores a much wider array of execution paths, leading to a more honest and comprehensive assessment of a model's true capabilities.
- Statistical Rigor: The framework utilizes PAC-style (Probably Approximately Correct) bounds. This provides a mathematical assurance—rather than a mere heuristic—that the error rate will remain below the target threshold with high probability.
Key Results
The selective generation method was tested across several state-of-the-art models, including GPT-4o, Gemini 1.5 Pro, DeepSeek-R1, and CodeLlama 13B.
- Controllability: The SCG method successfully maintained the False Discovery Rate (FDR) below the target threshold across all datasets. For instance, if a user specified a maximum error limit of 30%, the system reliably calibrated itself to stay under that cap.
- Efficiency: While the model abstains more frequently to ensure safety, its "selection efficiency" (the rate at which it provides an answer) remained highly practical. Stronger models like GPT-4o exhibited significantly better efficiency than weaker models.
- The Fuzzing Benefit: Calibrating with fuzzed tests yielded much tighter error bounds and higher selection efficiency compared to baselines that relied on small sets of manual unit tests.
- Model Agnosticism: The proposed method functions as a post-processor. It can be integrated with any existing code LLM without the need to retrain the underlying model.
Limitations and Future Work
While highly effective, the framework has notable limitations:
- Dependency on Reference Code: Generating fuzzed unit tests currently requires a "canonical" reference solution. This limits applicability for entirely novel problems where no ground truth exists.
- Computational Overhead: Fuzzing and executing hundreds of tests per candidate solution introduces significant latency and compute costs compared to standard inference.
- I.I.D. Assumption: The statistical guarantees rely on the assumption that real-world prompts will follow the same distribution as the calibration prompts. Significant distribution shifts may weaken these guarantees.
Future Directions: The authors suggest exploring LLM-based unit test generation to eliminate the dependency on reference solutions. This could eventually allow the system to autonomously verify its own code for novel, unsolved problems.
Summary updated