Manuscript Offprint

arXiv:2610.34961

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

Mintong Kang, Zhaorun Chen, Bo Li

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Despite the remarkable capabilities of large language models (LLMs) across diverse applications, they remain vulnerable to generating content that violates safety regulations and policies. To mitigate these risks, LLMs undergo safety alignment; however, they can still be effectively jailbroken. Off-the-shelf guardrail models are commonly deployed to monitor generations, but these models primarily focus on detection rather than ensuring safe decoding of LLM outputs. Moreover, existing efforts lack rigorous safety guarantees, which are crucial for the universal deployment of LLMs and certifiable compliance with regulatory standards. In this paper, we propose a Claim-based Stream Decoding (CSD) algorithm coupled with a statistical risk guarantee framework using conformal analysis. Specifically, our CSD algorithm integrates a stream guardrail model to safeguard sequential claims generated by LLMs and incorporates a backtracking mechanism to revise claims flagged with high safety risks. We provide theoretical guarantees demonstrating that the CSD algorithm achieves the desired generation distribution subject to safety constraints. Furthermore, we introduce a generation risk certification framework and derive a high-probability upper bound on the safety risk of the proposed CSD algorithm. We prove that our method can asymptotically control safety risk to any desired level. Empirical evaluations demonstrate the effectiveness and efficiency of the CSD algorithm compared to state-of-the-art safety decoding approaches. Additionally, we validate the soundness and tightness of the derived safety risk upper bound using realistic data.

1 Introduction

Large language models (LLMs) [37, 29] have seen widespread adoption due to their remarkable capabilities in natural language understanding and generation. Open-source LLMs, such as DeepSeek-R1 [12], promote accessibility and transparency, fostering innovation across various applications. However, their openness also introduces substantial safety and security risks. Malicious actors can exploit open-source models by embedding backdoors [45] or crafting adversarial prompts to bypass safety constraints [50, 17], potentially leading to harmful generations. Such vulnerabilities pose real-world risks, including misinformation propagation, bias amplification, and security threats in autonomous systems [43]. These risks highlight the pressing need for rigorous safety guarantees in LLM generations, especially in high-stakes scenarios such as healthcare, finance, and policy-making.

Current approaches to mitigating unsafe LLM outputs are predominantly empirical and lack formal assurances. During the training phase, reinforcement learning from human feedback (RLHF) [30, 32] aims to align LLMs with human preferences and safety norms. However, RLHF is computationally expensive [16] and remains susceptible to adversarial attacks and jailbreak exploits [50]. At the inference phase, guardrail models [15, 25, 19, 33, 22, 47] attempt to filter unsafe responses, but they merely classify harmful content rather than proactively ensuring safe generation. Likewise, decoding-time interventions [44, 42, 48] modify token sampling strategies to reduce risk but lack theoretical safety guarantees. The absence of provable risk bounds limits the reliability of these empirical defenses, making them unsuitable for applications demanding strict safety assurances.

In this work, we introduce C-SafeGen, the first certification framework for bounding safety risks in LLM generations. C-SafeGen is model-agnostic, enabling its application to both open-source and closed-source LLMs in a black-box setting. We establish theoretical guarantees that, given a specific model configuration, C-SafeGen can compute high-probability upper bounds on safety risks under mild assumptions. Furthermore, C-SafeGen provides a principled mechanism to derive valid decoding configurations that ensure compliance with a specified risk threshold.

To complement this certification framework, we propose Certifiably Safe Claim-based Stream Decoding (CSD), a novel decoding algorithm that enforces provable safety constraints during generation. CSD dynamically adjusts token sampling strategies using KV-cache mechanisms and a guardrail model, ensuring fluency and coherence while maintaining certified safety bounds.

We validate C-SafeGen and CSD through extensive empirical evaluations on standard safety benchmarks. Our results demonstrate that C-SafeGen yields tight and reliable safety risk estimates, effectively bounding empirical risks with minimal gaps. Additionally, CSD significantly reduces unsafe generations while preserving high-quality outputs. These findings establish C-SafeGen and CSD as foundational tools for the deployment of provably safe LLMs in real-world applications.

References (42)