Evaluating the Instruction-Following Robustness of Large Language Models to Prompt Injection

Zekun Li, Baolin Peng, Pengcheng He, Xifeng Yan · Submission to ICLR 2024 · Rejected

Introduction

Large Language Models (LLMs) have demonstrated remarkable proficiency in following instructions, making them highly valuable for customer-facing applications. However, this paper introduces a new benchmark revealing a striking "instruction-following paradox": while better instruction-following capabilities make models more useful, they also render them more susceptible to being hijacked by malicious instructions hidden within retrieved text. This vulnerability is known as indirect prompt injection.

The Threat of Indirect Prompt Injection

As LLMs are increasingly integrated into applications like web-connected chatbots or plugins, they frequently rely on "Retrieval-Augmented Generation" (RAG). In this setup, a model fetches information from external sources to answer a user's query.

This creates a significant security vulnerability. An attacker can place "poisoned" content on a website—for example, a hidden sentence instructing the model to ignore previous commands and execute a new one. If an LLM retrieves this text while attempting to answer a benign question, it might abandon the user's original intent and follow the attacker's instructions instead.

Example of an indirect prompt injection attack where the model answers the injected question instead of the user's original query.

This paper seeks to quantify this risk and understand why certain models are more easily misled than others.

Methodology and Benchmarking

The authors established a pioneering benchmark using Extractive Question Answering (QA) as the primary testbed. The benchmark utilizes four representative QA datasets: NaturalQuestions, TriviaQA, SQuAD, and HotpotQA.

The evaluation follows a specific structure:

  1. The Setup: The model receives a user question and a context retrieved from the web.
  2. The Attack: An adversarial question is injected into the context. While benign in content (e.g., asking about a different fact in the text), it is adversarial in intent, aiming to divert the model from the original task. For datasets with only one question per context, GPT-4 was used to generate coherent injected questions to ensure contextual plausibility.
  3. The Defense: The researchers employed a standard "sandwich" defense, wrapping the retrieved content in XML tags (<context>...</context>) and providing a system prompt that explicitly instructs the model to ignore any commands found within those tags.

To measure the success of these attacks, the study introduces two key metrics:

  • Performance Drop Rate (PDR): Measures the decrease in the model's accuracy on the original user question after the injection.
  • Instruction Discrimination Rate (IDR): A ratio determining whether the model prioritized the original user instruction or the injected adversarial one.

Key Insights and Results

The benchmark revealed significant limitations in the robustness of state-of-the-art instruction-following LLMs against these attacks.

The Robustness Gap: There is a massive divide between proprietary models (like GPT-3.5-Turbo and Claude-2) and open-source models. Proprietary models were significantly better at ignoring injected instructions. Conversely, open-source models like Zephyr-7B and Alpaca-7B demonstrated the least robustness, often completely abandoning the user's question in favor of the injected one.

Instruction Discrimination Rate (IDR) across various models on the HotpotQA dataset, highlighting the stark differences in robustness.

Size Doesn't Guarantee Safety: Interestingly, LLaMA2-70B—the largest open-source model tested—was less robust than the smaller Vicuna-33B. This suggests that the specific instruction fine-tuning methodology matters more than raw parameter count. Prevalent instruction-tuned models appear prone to "overfitting" to any instruction phrase in the prompt, rather than truly comprehending which instructions are authoritative.

Recency Bias and Position: Models are highly susceptible to instructions placed at the end of the prompt. Moving an injection from the start of the context to the end caused a dramatic increase in PDR across almost all models, sometimes making the attack 2-3 times more effective. Models seem to "forget" system instructions, simply executing the last command encountered.

The "Ignore Previous" Vulnerability: Even the most robust models experienced significant performance hits when the injected instruction was prefixed with "jailbreak" phrases like "Ignore my previous instructions." This indicates a widespread struggle to maintain a strict hierarchy of privileged instructions.

Limitations and Future Work

While this study provides a crucial foundation, it focused exclusively on extractive QA. This allows for precise measurement but may not fully capture the nuances of more complex scenarios like code generation or creative writing, where injections might be subtler. Furthermore, the paper only tested prompt-level defenses. The authors suggest that future work must explore architectural changes or specialized training objectives to help models inherently distinguish between "system-level" instructions and "data-level" text, moving them from mere "instruction-completers" to robust, goal-oriented agents.

Summary updated

BibTeX
@misc{li2023evaluating,
  author = {Zekun Li and Baolin Peng and Pengcheng He and Xifeng Yan},
  title = {{Evaluating the Instruction-Following Robustness of Large Language Models to Prompt Injection}},
  year = {2023},
  eprint = {2308.10819},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.10819},
}
Figure