arXiv:2508.10031cs.CRcs.AI2025-08

通过过滤恶意上下文提升大模型安全,不损失原有性能。

Context Misleads LLMs: The Role of Context Filtering in Maintaining Safe Alignment of LLMs

  • 输入前预处理过滤不可信上下文,识别真实用户意图。
  • 对抗攻击成功率降低最高达92%,同时保持原模型性能。
  • 无需微调模型,适配所有大模型,即插即用。

尽管大语言模型(LLMs)在性能上取得显著进展,但各类越狱攻击正带来日益增长的安全与伦理风险。恶意用户常利用对抗性上下文欺骗模型,诱导其生成有害内容。本文提出一种名为上下文过滤(Context Filtering)的新防御机制,是一种输入预处理方法,可过滤不可靠上下文,识别包含真实用户意图的主提示,从而揭露隐藏的恶意行为。由于提升安全性常会损害模型帮助性,影响正常用户使用体验,本方法旨在增强安全性的同时保留原始性能。我们通过对比分析,在六种不同越狱攻击下评估该方法的防御效果,并比较其与当前最先进防御机制在帮助性方面的表现。实验表明,该方法将越狱攻击成功率最高降低92%,实现了安全与帮助性的最佳平衡。值得注意的是,上下文过滤是即插即用的通用方法,适用于所有大语言模型,包括白盒和黑盒模型,无需对模型本身进行微调。相关代码已开放供研究使用。

原文摘要 · Abstract (English)

While Large Language Models (LLMs) have shown significant advancements in performance, various jailbreak attacks have posed growing safety and ethical risks. Malicious users often exploit adversarial context to deceive LLMs, prompting them to generate responses to harmful queries. In this study, we propose a new defense mechanism called Context Filtering, an input pre-processing method designed to filter out untrustworthy and unreliable context while identifying the primary prompts containing the real user intent to uncover concealed malicious intent. Given that enhancing the safety of LLMs often compromises their helpfulness, potentially affecting the experience of benign users, our method aims to improve the safety of the LLMs while preserving their original performance. We evaluate the effectiveness of our model in defending against jailbreak attacks through comparative analysis, comparing our approach with state-of-the-art defense mechanisms against six different attacks and assessing the helpfulness of LLMs under these defenses. Our model demonstrates its ability to reduce the Attack Success Rates of jailbreak attacks by up to 92% while maintaining the original LLMs' performance, achieving state-of-the-art Safety and Helpfulness balance. Notably, Context Filtering is a plug-and-play method that can be applied to all LLMs, including both white-box and black-box models, to enhance their safety without requiring any fine-tuning of the models themselves. Our model is available for research purposes.

大模型安全越狱防御上下文过滤即插即用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。