TL;DR
Large Language Models (LLMs) are powerful code generators but are notoriously prone to hallucinations and subtle bugs. This paper introduces RISCOSET, a framework that leverages multiple hypothesis testing to prune uncertain components of LLM-generated code, outputting a "partial program" that is statistically guaranteed to contain a correct solution. By reframing uncertainty quantification as a multi-label problem, RISCOSET retains significantly more valid code than previous state-of-the-art methods—reducing unnecessary code removal by up to 24.5%.
What Problem Does This Paper Address?
When using LLMs for high-stakes software engineering, we need to know when to trust the model's output. Traditional Conformal Prediction (CP) provides a mathematical framework to guarantee that a model's prediction set contains the ground truth with high confidence. However, standard CP breaks down for code because it assumes independence between output tokens or components—an assumption that fails for highly structured, systemically interdependent data like abstract syntax trees (ASTs).
A recent alternative proposed using Probably Approximately Correct (PAC) prediction sets to prune uncertain nodes from an AST, leaving behind a reliable "partial program" sketch. However, this approach suffers from two major flaws:
- The Monotonicity Constraint: It assumes that risk decreases monotonically as the prediction set grows, which severely restricts the optimization space and leads to suboptimal, overly aggressive code pruning.
- Single-Label Limitation: It treats code generation as a single-label classification problem, failing to account for the fact that there are often multiple syntactically unique but semantically identical ways to write a correct program.
Methods
To overcome these limitations, the authors introduce RISCOSET, which reframes uncertainty quantification for code as a multi-label classification problem and applies the Learn Then Test (LTT) framework.
1. Structured Risk Function & AST Pruning
RISCOSET represents a program as an AST. Instead of forcing a strict monotonicity constraint, it sets up an optimization problem (solved via a Z3 SMT solver) to prune nodes based on their negative log-probabilities while enforcing tree connectivity. The goal is to minimize the number of nodes removed while keeping the total uncertainty below a threshold ($\lambda$).
2. Multiple Hypothesis Testing
Using the LTT framework, RISCOSET treats the selection of the optimal uncertainty threshold ($\lambda$) as a multiple hypothesis testing problem. It evaluates a grid of potential $\lambda$ values against a calibration dataset, computing binomial trial p-values for each to control the Family-Wise Error Rate (FWER). This mathematically guarantees that the resulting partial program contains a correct solution at a user-defined risk level ($\alpha$).
3. Selective Execution Strategy
Because code generation is multi-label, calibration normally requires sampling numerous candidate programs from the LLM and executing unit tests on all of them to find all valid variants—a massive computational bottleneck. RISCOSET introduces a Selective Execution Strategy that uses importance sampling and model perplexity scores to dynamically decide which programs actually need test execution and which can be safely accepted, bounding the potential label error rate ($\epsilon$).
Datasets
The authors evaluated RISCOSET across three popular Python code generation benchmarks using a 50/50 calibration/test split:
- HumanEval: 164 hand-written programming problems.
- MBPP (Sanitized): Approximately 500 crowd-sourced python problems.
- APPS: 1,000 introductory-level algorithmic problems.
Experiments were conducted using three open-source LLMs: DeepSeek-Coder-33B, Qwen2.5-Coder-32B, and Llama3.1-70B.
Key Insights and Ideas
- Embracing Multi-Label Reality: Acknowledging that multiple distinct code snippets can solve the same problem allows the framework to be far less conservative. If the LLM generates a valid alternative solution, RISCOSET doesn't penalize it as an error.
- The Power of Less Constraints: By switching from PAC to LTT, the authors dropped the explicit monotonicity constraint on the prediction sets. This expanded the feasible search space during optimization, meaning the algorithm can find much tighter, more informative partial programs.
- Compute-Aware Calibration: The selective execution strategy proves that you don't need perfect, fully-tested calibration data to give rigorous statistical guarantees. You can trade a tiny, controlled amount of risk for a massive reduction in unit-test execution time.
Key Results
RISCOSET consistently outperformed both the standard PAC baseline and a greedy pruning baseline across all datasets and models.
- Fewer Node Removals: At a risk level of $\alpha = 0.15$, RISCOSET reduced unnecessary node removals by 24.5% on MBPP and 20.3% on APPS compared to the best baseline. This leaves developers with a much more complete and useful code sketch.
- Guaranteed Coverage: Across 100 random trials, the empirical coverage of the generated code sets consistently remained above the theoretical target bound ($1 - \alpha$), validating the mathematical guarantees.
- Efficiency Gains: The selective execution strategy successfully avoided test-case execution for nearly 30% of the generated calibration programs while maintaining strict risk controls.
Limitations and Future Work
While RISCOSET eliminates test-time overhead, it still requires executing test cases during the calibration phase to augment labels. Even with the selective execution strategy, this introduces a computational cost before the model can be deployed with guarantees.
Additionally, the authors note that the performance of the maximum subtree removal parameter ($t_{max}$) is sensitive to how well-calibrated the underlying LLM is. Future work could explore adapting this framework to other highly structured generation domains, such as molecule generation or mathematical theorem proving.
Summary updated