NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

C-SafeGen: Certified Safe LLM Generation with Claim-Based Streaming Guardrails

Mintong Kang, Zhaorun Chen, Bo Li

Despite the remarkable capabilities of large language models (LLMs), they remain vulnerable to adversarial attacks and "jailbreaking" prompts that trick them into generating harmful content. While extensive safety alignment (like RLHF) helps, it is not foolproof. Current defenses typically rely on reactive guardrails or heuristic safety decoding, both of which lack the formal mathematical guarantees required for high-stakes deployments in fields like healthcare or finance.

To bridge this gap, researchers have introduced C-SafeGen, a novel framework that provides provable safety risk upper bounds for LLM generation. By combining a "claim-based" decoding algorithm with statistical techniques from conformal prediction, C-SafeGen not only detects unsafe content but mathematically bounds the risk of generating it.

The C-SafeGen Framework

C-SafeGen shifts the paradigm from post-generation detection to certified, safe-by-design generation. It achieves this through two primary components: Claim-based Stream Decoding and Conformal Risk Certification.

Overview of the C-SafeGen framework, illustrating the Claim-based Stream Decoding (CSD) process and backtracking mechanism.

1. Claim-Based Stream Decoding (CSD)

Instead of evaluating safety token-by-token (which lacks context and is computationally heavy) or checking the entire response at the end (which is too late), CSD operates at the level of claims (e.g., sentences or logical statements).

  • Segmentation: The algorithm identifies critical points, such as newlines or periods, to define a discrete claim.
  • Streaming Guardrail: As each claim is completed, an external guardrail model evaluates it in real-time.
  • Backtracking & Resampling: If a claim's risk score exceeds a predefined safety threshold, the system "rewinds" the model's KV-cache to the start of that claim and resamples the generation.
  • Efficiency: By leveraging KV-caching, the model avoids re-processing the entire prompt during a backtrack, significantly reducing computational overhead.

2. Conformal Risk Certification

The mathematical foundation of C-SafeGen relies on conformal analysis. By treating LLM generation as a statistical process and evaluating a small calibration dataset, the framework calculates a high-confidence upper bound on the safety risk. This allows developers to set rigorous, provable targets—for example, demanding a 90% confidence that the safety risk remains below 5%—and C-SafeGen will automatically derive the necessary decoding configurations to meet that guarantee.

Experimental Validation and Key Results

The researchers evaluated C-SafeGen using two primary safety benchmarks: AdvBench (harmful prompts) and JailbreakBench (prompts engineered to bypass filters). They tested the framework on Llama-3.1-8B and 13B models, utilizing LlamaGuard3-8B and ShieldGemma-9B as external guardrails.

Comparison of safety risks across different decoding methods on AdvBench and JailbreakBench, showing CSD achieves the lowest risk with tight theoretical bounds.

The empirical results highlight several key advantages of the C-SafeGen approach:

  • Superior Safety: CSD consistently achieved the lowest safety risk across all benchmarks when compared to established baselines like Self-reminder, Safety-Opt, and SafeDecoding.
  • Tight Theoretical Bounds: The "conformal safety risk" (the theoretical limit) closely matched the "empirical safety risk" (actual observed risk). This demonstrates that the mathematical proofs accurately reflect real-world performance.
  • Efficiency Gains: Compared to a "Best-of-N" approach (generating multiple versions and selecting the safest), CSD was roughly 6x faster (approximately 7 seconds vs. 40+ seconds per instance) while delivering superior safety. Adding KV-cache optimization further reduced runtime to under 5 seconds per instance.
  • Scaling Insights: Interestingly, the 13B model sometimes exhibited higher safety risks than the 8B model under certain conditions, reinforcing the notion that simply scaling up a model does not inherently resolve safety vulnerabilities.

Limitations and Future Directions

While C-SafeGen represents a significant step forward in certified LLM safety, it has limitations. The framework's effectiveness is inherently tied to the quality of the external guardrail model; if the guardrail has blind spots, the certification remains technically valid but practically flawed. Additionally, C-SafeGen treats the LLM as a black box, potentially missing early internal activation signals of unsafe generation. Finally, the current certification relies on a specific evaluation distribution. If user query patterns shift dramatically (e.g., novel jailbreak techniques), the safety bounds may require re-calibration, pointing toward adaptive or "online" certification as a promising area for future research.

Summary updated

BibTeX
@inproceedings{kang2025c,
  author = {Mintong Kang and Zhaorun Chen and Bo Li},
  title = {{C-SafeGen: Certified Safe LLM Generation with Claim-Based Streaming Guardrails}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=nOsEyBGk1I},
}
Figure