一句话:提出免训练实时解码框架,用外部验证器与上下文相似性校验拒绝 LLM 不安全输出。
LLM 易生成有害内容,现有安全方法常需训练控制模型并在生成中主动干预,造成质量下降与计算开销。LLMSafeGuard 是一个轻量实时框架,将外部验证器集成到解码过程,拒绝不安全输出并放行有效输出。它用基于相似度的验证替代外部控制模型训练,并采用上下文级时机选择,仅在必要时干预。作者在去毒、版权保护和越狱防御三类任务、六个模型上评估:去毒至少减少 38.6% 有害输出且保持语言质量;越狱防御的有害分数较最佳基线至少降低 11.4%;上下文级时机选择较逐步验证加速 1.7 倍且不损效果。
Large Language Models (LLMs) have significantly advanced natural language processing (NLP) tasks, but also pose ethical and societal risks due to their propensity to generate harmful content. Existing methods have limitations, including the need for training specific control models and proactive intervention during text generation, which leads to quality degradation and increased computational overhead. To mitigate those limitations, we propose LLMSafeGuard, a lightweight real-time framework that integrates an external validator into decoding, rejecting unsafe outputs while allowing valid ones. We introduce a similarity-based validation approach, simplifying safety constraint validation and eliminating the need for external control model training. Additionally, LLMSafeGuard employs a context-wise timing selection strategy, which allows LLMSafeGuard to intervene in LLMs only when necessary. We evaluate LLMSafeGuard on three tasks: detoxification, copyright safeguarding, and jailbreak attack defending across six models, and the results demonstrate its superiority over SOTA baselines on all tasks. For instance, in detoxification, LLMSafeGuard reduces toxic output by at least 38.6% while preserving linguistic quality. For Jailbreak attack defending, LLMSafeGuard reduces the harmful score of the response LLMs under jailbreak attack at least by 11.4% compared to the best baseline. Additionally, its context-wise timing selection achieves a speedup of 1.7X over per-step validation, without compromising effectiveness.
@inproceedings{DongWLH26,
title = {LLMSafeGuard: A Training-Free Framework for Safeguarding LLM Decoding via Context-Wise Similarity Validation},
author = {Ximing Dong and Shaowei Wang and Dayi Lin and Ahmed E. Hassan},
booktitle = {FSE},
year = {2026},
doi = {10.1145/3803437.3806718}
}