TL;DR
LLMs are notorious "bluffers" that often generate code that passes unit tests while harboring critical security vulnerabilities. This paper introduces joint-CRC, a framework that uses Conformal Risk Control to provide a mathematical guarantee on the "silent failure rate"—ensuring that the probability of shipping code that is either incorrect or insecure stays below a user-defined threshold.
What Problem Does This Paper Address?
When we use LLMs for coding, we usually rely on two types of checks: unit tests (for correctness) and static analyzers like Semgrep (for security). However, existing deployment strategies often fail to handle these risks simultaneously.
A "Silent Wrong" occurs when code passes tests but fails on edge cases. A "Silent Insecure" occurs when code passes tests but contains a vulnerability (like SQL injection) that a static analyzer could have caught, but the system ignored. Current methods typically optimize for one or the other. If you only gate for security, you might ship broken code; if you only gate for correctness, you might ship a security nightmare. The authors identify a particularly tricky failure mode called Stable-Correct-But-Insecure (SCI), where an LLM confidently and consistently generates the same insecure-but-test-passing snippet across multiple samples, tricking standard "majority vote" or "self-consistency" filters.
Methods
The authors extend Conformal Risk Control (CRC)—a statistical framework for bounding expected loss—to the joint event of a failure in either correctness or security.
- Sampling and Clustering: For a given prompt, the system samples $K$ candidates (e.g., $K=8$). It then clusters these candidates based on their "behavioral signature"—a combination of which tests they pass and what security flags they trigger.
- The "Good" Cluster: A cluster is only considered "good" if it passes all tests and triggers zero security rules.
- Joint-CRC Wrapper: The system calculates a "joint-good concentration score" ($c_{good}$). It then uses a calibration set to find a threshold ($\lambda$). If the largest good cluster is smaller than this threshold, the system abstains (refuses to ship the code and routes it for human review).
- Disjunctive Composition: The key innovation is treating the two risks as a single disjunctive event ($wrong \lor insecure$). This allows a single CRC call to bound the total risk more tightly than traditional methods like Bonferroni correction, which would treat the risks separately and result in a looser, less useful bound.
Datasets
The researchers evaluated their method using:
- Primary Corpus: 13 hand-curated Python microbenchmarks covering common CWEs (Common Weakness Enumerations) like SQL injection, unsafe deserialization, and weak hashing.
- SecureForge Stress Test: 30 complex web-app prompts (Flask/PyMySQL) designed to test the limits of the verifier harness.
- HumanEval+: A standard 164-problem algorithmic benchmark used as a control to ensure the method doesn't degrade performance when security risks are absent.
Key Insights and Ideas
- Single-axis $\not\Rightarrow$ Joint: This is the "aha" moment. The authors prove that controlling for security alone still leaves a 34% joint failure rate because the system ships "secure" code that simply doesn't work. You must calibrate for the union of risks.
- Abstention as a First-Class Citizen: Instead of forcing the LLM to pick the "best" of a bad bunch, joint-CRC allows the system to communicate uncertainty. This aligns with the "trust budget" of a developer—you decide how much risk ($\alpha$) you can tolerate.
- Generator Agnostic: The framework works as a "wrapper." Whether you are using a massive frontier model like Claude 3.5 Sonnet or a smaller local model like Qwen-1.5B, the calibration procedure adapts to the model's specific error distribution without needing to retrain it.
Key Results
On the primary benchmark (with a risk budget $\alpha = 0.10$):
- Joint-CRC achieved 0% observed silent failures while maintaining a high coverage rate (82.6%). It essentially matched the performance of an "oracle" that could see the ground truth.
- pass@1 (shipping the first sample) leaked "bad" code 42.1% of the time.
- pass@1 + Semgrep gate (a standard industry approach) still leaked bad code 26% of the time.
- Security-only CRC hit its security goal but leaked 33.6% joint-bad code because it was blind to correctness failures.
Limitations and Future Work
- Verifier-Defined Reality: The guarantee is only as good as the verifiers. If a bug isn't covered by the unit tests or a vulnerability isn't in the Semgrep ruleset, joint-CRC won't catch it. The authors call this "analyzer-conditional" security.
- Hidden Correctness: The current study uses the same tests for both clustering and evaluation. The authors note that catching "hidden" correctness failures (bugs that pass the provided tests but fail on secret "gold" tests) is the next logical step and would require a disjoint test split.
- Single-Turn Only: The current wrapper is designed for single-shot code generation. Extending this to multi-step agents (like those that browse files or self-correct) remains an open challenge.
Summary updated