用语义伪装标签,让大模型抵御提示注入攻击。
Semantics as a Shield: Label Disguise Defense (LDD) against Prompt Injection in LLM Sentiment Classification
- 将真实标签换成语义相关或无关的伪装标签,阻断攻击指令与输出的对应关系。
- 在9个主流模型上测试,多数情况下恢复了被攻击下降的准确率。
- 语义相关的伪装标签(如好/坏)比无意义标签(如蓝/黄)更有效。
大型语言模型广泛应用于情感分析等文本分类任务,但其对自然语言提示的依赖使其易受提示注入攻击。特别是类别指令型攻击会利用模型标签集(如正面/负面)的知识,通过恶意指令覆盖模型正常行为。现有防御方法如检测过滤、指令层级和签名提示,要么需重新训练模型,要么易被混淆绕过。本文提出轻量级、模型无关的标签伪装防御(LDD),通过将真实标签替换为语义转换或无关的别名标签(如蓝色/黄色)来隐藏真实标签。模型通过少量示例隐式学习新标签映射,破坏攻击指令与决策输出间的直接关联。我们在九个先进模型(包括GPT-5、GPT-4o、LLaMA3.2、Gemma3和Mistral变体)上评估了LDD在不同少样本设置和对抗环境下的表现。结果表明,各模型在使用LDD后均部分恢复了因攻击损失的性能。绝大多数模型中,存在至少一对别名标签,使准确率高于仅依赖少样本学习而无防御的基线。语言学分析进一步显示,语义一致的别名标签(如好/坏)比语义无关的符号(如蓝/黄)提供更强鲁棒性。研究证明,语义本身可成为抵御提示注入的有效防御层。
原文摘要 · Abstract (English)
Large language models are increasingly used for text classification tasks such as sentiment analysis, yet their reliance on natural language prompts exposes them to prompt injection attacks. In particular, class-directive injections exploit knowledge of the model's label set (e.g., positive vs. negative) to override its intended behavior through adversarial instructions. Existing defenses, such as detection-based filters, instruction hierarchies, and signed prompts, either require model retraining or remain vulnerable to obfuscation. This paper introduces Label Disguise Defense (LDD), a lightweight and model-agnostic strategy that conceals true labels by replacing them with semantically transformed or unrelated alias labels(e.g., blue vs. yellow). The model learns these new label mappings implicitly through few-shot demonstrations, preventing direct correspondence between injected directives and decision outputs. We evaluate LDD across nine state-of-the-art models, including GPT-5, GPT-4o, LLaMA3.2, Gemma3, and Mistral variants, under varying few-shot and an adversarial setting. Our results show that the ability of LDD to recover performance lost to the adversarial attack varies across models and alias choices. For every model evaluated, LDD is able to restore a portion of the accuracy degradation caused by the attack. Moreover, for the vast majority of models, we can identify more than one alias pair that achieves higher accuracy than the under-attack baseline, in which the model relies solely on few-shot learning without any defensive mechanism. A linguistic analysis further reveals that semantically aligned alias labels(e.g., good vs. bad) yield stronger robustness than unaligned symbols(e.g., blue vs. yellow). Overall, this study demonstrates that label semantics can serve as an effective defense layer, transforming meaning itself into a shield against prompt injection.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。