Skip to main content
QUICK REVIEW

[论文解读] StruQ: Defending Against Prompt Injection with Structured Queries

Sizhe Chen, Julien Piet|arXiv (Cornell University)|Feb 9, 2024
Advanced Database Systems and Queries被引用 5
一句话总结

StruQ 通过使用结构化查询将提示与数据分离,并用结构化指令微调训练专门的LLM,使其忽略数据部分中的指令,从而在多种攻击类型下降低提示注入成功率,同时对效用的损失很小。

ABSTRACT

Recent advances in Large Language Models (LLMs) enable exciting LLM-integrated applications, which perform text-based tasks by utilizing their advanced language understanding capabilities. However, as LLMs have improved, so have the attacks against them. Prompt injection attacks are an important threat: they trick the model into deviating from the original application's instructions and instead follow user directives. These attacks rely on the LLM's ability to follow instructions and inability to separate prompts and user data. We introduce structured queries, a general approach to tackle this problem. Structured queries separate prompts and data into two channels. We implement a system that supports structured queries. This system is made of (1) a secure front-end that formats a prompt and user data into a special format, and (2) a specially trained LLM that can produce high-quality outputs from these inputs. The LLM is trained using a novel fine-tuning strategy: we convert a base (non-instruction-tuned) LLM to a structured instruction-tuned model that will only follow instructions in the prompt portion of a query. To do so, we augment standard instruction tuning datasets with examples that also include instructions in the data portion of the query, and fine-tune the model to ignore these. Our system significantly improves resistance to prompt injection attacks, with little or no impact on utility. Our code is released at https://github.com/Sizhe-Chen/StruQ.

研究动机与目标

  • 将提示注入作为LLM集成应用中的安全风险来处理,该风险被OWASP列为首要风险之一。
  • 提出一种自设计安全的LLM界面,将控制(提示)与数据分离。
  • 开发一种训练方法,使LLMs仅遵循基于提示的指令,同时忽略基于数据的指令。

提出的方法

  • 引入结构化查询,前端使用特殊标记和分隔符对提示和数据进行编码。
  • 从用户数据中过滤分隔符标记,防止基于完成的攻击。
  • 用结构化指令微调训练基础LLM,使其遵循提示部分的指令,而忽略数据部分的指令。
  • 构建包含干净样本和攻击样本(Naive 和 Completion-Other 攻击)的结构化指令微调数据集,用于教导忽略数据基于的指令。
  • 针对十一种攻击技术评估安全性,并使用 AlpacaEval 1.0 测量效用。
  • 使用安全的前端标记嵌入初始化和专用分隔符策略来缓解 Completion 攻击。

实验结果

研究问题

  • RQ1结构化查询是否能够在有意义地分离控制与数据,以防御提示注入攻击?
  • RQ2结构化指令微调是否使LLMs在保持任务效用的同时忽略数据中嵌入的指令?
  • RQ3StruQ 对包括 Completion 与 TAP 攻击在内的广泛提示注入技术的效能如何?

主要发现

  • StruQ 将大多数测试技术在 Alpaca 和 Mistral 上的攻击成功率降至低于 2%。
  • StruQ 显著降低基于 TAP 的攻击成功率(在 Alpaca 上从 97% 降至 9%;在 Mistral 上从 100% 降至 36%)。
  • 在 AlpacaEval 上,效用仅保留大约一个标准误损失。
  • 完成类攻击被前端的分隔符设计和过滤所缓解。
  • 该方法在提供对多种提示注入方法的广泛防御的同时,只带来较小的效用下降。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。