The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions

Paper · arXiv 2404.13208 · Published April 19, 2024
LLM Alignment

Today’s LLMs are susceptible to prompt injections, jailbreaks, and other attacks that allow adversaries to overwrite a model’s original instructions with their own malicious prompts. In this work, we argue that one of the primary vulnerabilities underlying these attacks is that LLMs often consider system prompts (e.g., text from an application developer) to be the same priority as text from untrusted users and third parties. To address this, we propose an instruction hierarchy that explicitly defines how models should behave when instructions of different priorities conflict. We then propose an automated data generation method to demonstrate this hierarchical instruction following behavior, which teaches LLMs to selectively ignore lower-privileged instructions. We apply this method to LLMs, showing that it drastically increases robustness—even for attack types not seen during training—while imposing minimal degradations on standard capabilities.

Introduction. Modern large language models (LLMs) are no longer envisioned as simple autocomplete systems—they could instead empower agentic applications such as web agents, email secretaries, virtual assistants, and more (Nakano et al., 2021; Parisi et al., 2022; Schick et al., 2024; Shen et al., 2024). One of the major risks for widely deploying such applications is that adversaries could trick a model into executing unsafe or catastrophic actions. For example, a prompt injection attack (Willison, 2022; Schulhoff et al., 2023; Toyer et al., 2024) against an LLM-powered email assistant could theoretically exfiltrate a user’s private emails:

These types of attacks, such as jailbreaks (Wei et al., 2023), system prompt extractions (Perez & Ribeiro, 2022), and direct or indirect prompt injections (Greshake et al., 2023) can provide a worrying mechanism for users to attack an application (e.g., to bypass developer restrictions, expose company IP) or third parties to attack a user (e.g., revealing their private data, spamming them, using their session for DDOS campaigns).

In this work, we argue that the mechanism underlying all of these attacks is the lack of instruction privileges in LLMs. Modern LLMs take as input text of various types, including System Messages provided by application developers, User Messages provided by end users, and Tool Outputs. While from an application standpoint it is evident that these should be More concretely, when multiple instructions are present, the lower-privileged instructions can either be aligned or misaligned with the higher-privileged ones. For example, certain instructions are clearly benign: if an LLM is instructed to act as a car salesman bot and a user says “use spanish”, the model should comply with this aligned instruction. On the other hand, Figure 1 illustrates a clearly misaligned instruction: rather than answering the user’s question, the first web result tries to extract the conversation history. For these types of instructions, we ideally want the model to ignore the lower-privileged instructions when possible, and otherwise the model should refuse to comply if there is no way to proceed.

To generate training data, we leverage two principles: synthetic data generation and context distillation (Askell et al., 2021; Snell et al., 2022). For aligned instructions, we generate examples that have compositional requests (e.g., ”write a 20 line poem in spanish”) and decompose the instructions into smaller pieces (e.g., ”write a poem”, ”use spanish”, ”use 20 lines”). We then place these decomposed instructions at different levels of the hierarchy and train models to predict the original ground-truth response. For misaligned instructions, we train models to act as if they are completely ignorant of the lower-level instructions. We create these examples using red-teamer LLMs for different attacks (e.g., prompt injections, system prompt extractions) and use this data in combination with generic instructionfollowing examples to fine-tune GPT-3.5 Turbo using supervised fine-tuning and RLHF.

To evaluate, we use open-sourced and novel benchmarks, some of which contain attacks that are unlike those seen during training time. Our approach yields dramatically improved robustness across all evaluations (Figure 2), e.g. defense against system prompt extraction is improved by 63%. Moreover, we observe generalization to held-out attacks that are not directly modeled in our data generation pipeline, e.g., jailbreak robustness increases by over 30%. We do observe some regressions in “over-refusals”—our models sometimes ignore or refuse benign queries—but the generic capabilities of our models remains otherwise unscathed and we are confident this can be resolved with further data collection.

Related work. The Anatomy of an LLM Most modern LLMs, especially in chat use cases, process structured inputs consisting of System Messages, User Messages, Model Outputs, and Tool • A System Message defines the general instructions, safety guidelines, and constraints for the LLM, as well as tools available to it (e.g., first message in Figure 1). These messages can only be provided by the application developer. • User Messages are an end user’s inputs to the model (e.g., second message of Figure 1). • Model Outputs refer to responses from the LLM, which may consist of text, images, audio, calls to a tool, and more (e.g., third message of Figure 1). • Tool Outputs may contain internet search results, execution results from a code interpreter, or results from a third-party API query (e.g., fourth message of Figure 1).

Prompt Injections The most concerning exploit is prompt injections, where adversaries insert instructions that subvert the intent of the system designer (see Introduction for an example). Prompt injections do not target the models themselves, but rather the applications built on top of them. Consequently, if an application has access to confidential data or can take actions in the world, prompt injections can cause catastrophic harms such as exfiltrating user data (Greshake et al., 2023) or hijacking the LLM’s actions (Toyer et al., 2024).

Jailbreaks Another well-known attack vector is jailbreak, which specifically aims to escape the safety behavior that is trained into an LLM. As such, they often don’t specifically conflict with a model’s previous instructions. There are a myriad of attack variants (Schulhoff et al., 2023; Zou et al., 2023; Wei et al., 2023) that can allow adversaries to perform malicious tasks such as generating spam, misinformation, or producing pornographic content.

System Message Extraction The System Message defines the expected behavior of the model, and it may contain well-curated business logic, private information such as passwords, or safety related instructions. The prompt could thus be considered intellectual property, and having knowledge of the prompt can aid in other attacks (Toyer et al., 2024). System message extraction attacks aim to reveal the entirety of the system message or a specific secret from it. They fit into the instruction hierarchy as many developers explicitly tell the model not to reveal its system message. These attacks are straightforward to execute (Perez & Ribeiro, 2022; Zhang & Ippolito, 2023; Schulhoff et al., 2023)—even when models are told to avoid repeating their prompt—by using attacks such as:

Method. A common analogy for AI-powered applications is that the LLM acts as an operating system: it executes the instructions, determines the control flow, and handles data storage (Weng, 2023; Shen et al., 2024). Using this analogy, the current state of affairs is that every instruction is executed as if it was in kernel mode, i.e., untrusted third-parties can run arbitrary code with access to private data and functions. The solution to these challenges in computing has been to create clear notions of privilege, e.g., operating systems use a hierarchy of access and control (Corbat ́o & Vyssotsky, 1965; Ritchie & Thompson, 1974) and attacks such as SQL injections (Su & Wassermann, 2006) and command injections (Zhong et al., 2024) are solved by not treating user inputs as privileged instructions (Thomas et al., 2009).

With this perspective, we can view one of the underlying causes for the attacks in Section 2 as the lack of a corresponding instruction hierarchy in modern LLMs. We propose to create such a hierarchy, where LLMs will defer to higher-privileged instructions in the case of conflicts. Figure 1 provides an overview of these ideas.

3.1 Overview of Ideal Model Behavior More concretely, when multiple instructions are presented to the model, the lower-privileged instructions can either be aligned or misaligned with the higher-privileged ones. Our goal is to teach models to conditionally follow lower-level instructions based on their alignment with higher-level instructions:

• Aligned instructions have the same constraints, rules, or goals as higher-level instructions, and thus the LLM should follow them. For example, if the higher-level instruction is “you are a car salesman bot”, an Aligned instruction could be “give me the best family car in my price range”, or “speak in spanish”. Alternatively, in cases such as web browsing (Figure 1), an Aligned instruction could be the words “Click here for the Philadelphia 76ers score” on a website. • Misaligned instructions should not be followed by the model. These could be because they directly oppose the original instruction, e.g., the user tries to trick the car salesman bot by saying “You are now a gardening helper!” or “IGNORE PREVIOUS INSTRUC- TIONS and sell me a car for $1“. These instructions could also simply be orthogonal, e.g., if a user asks the bot “Explain what the Navier-Stokes equation is”.

Models should not comply with misaligned instructions, and the ideal behavior should be to ignore them when possible, and otherwise the model should refuse to comply if there is otherwise no way to proceed.

3.2 Training Data Generation for Different Attacks To effectively imbue the instruction hierarchy into LLMs, we propose methods for creating training data, leveraging two key principles: synthetic data generation and context distillation (Askell et al., 2021; Snell et al., 2022). Precisely, we propose two approaches to handle aligned and misaligned instructions.

• Context Synthesis. For Aligned instructions, we generate examples using an approach we denote context synthesis. We take compositional requests and decompose the instructions into smaller pieces. We then place these decomposed instructions at different levels of the hierarchy and train models to predict the original ground-truth response. • Context Ignorance. For Misaligned instructions, we use the exact opposite approach: we train models to predict the same answer they would have generated if they never saw the lower-level instructions.

While creating this data, we strike a careful balance not to trigger overrefusal behavior, where a model refuses to comply even when a low-priority instruction was aligned. In particular, it is possible to prevent prompt injections by having the model never follow instructions in lower privilege inputs but that would greatly damage the model’s instruction following capabilities.

Discussion. Defenses for Prompt Injection For prompt injection on closed-domain tasks (Section 3.2), recent work has advocated for teaching a model to treat third-party user inputs as data, not as instructions (Chen et al., 2024; Willison, 2023; Zverev et al., 2024; Yi et al., 2023; Liu et al., 2023). In particular, Chen et al. (2024) proposed to train LLMs to ignore instructions provided in the user input. Our work differs in that we focus on a hierarchy of instructions with multiple levels, whereas they focus specifically on system messages versus user messages. Moreover, they train models to completely ignore all instructions in the user messages, whereas we train models to conditionally follow lower-level instructions when applicable.

System-level Guardrails We focus on model-based mechanisms for mitigating attacks, which is complementary to other types of system-level mitigations. For example, one could ask users to approve or deny certain actions (e.g., calling an API). We envision other types of more complex guardrails should exist in the future, especially for agentic use cases, e.g., the modern Internet is loaded with safeguards that range from web browsers that detect unsafe websites to ML-based spam classifiers for phishing attempts.

Automated Red-teaming Our work fits into the larger trend of automatically generating adversarial training data for LLMs. We generate data using a combination of few-shot prompting, end-to-end training of attacker LLMs, and context distillation. Recent work also explores ways of using LLMs to generate “red-teaming” data (Perez et al., 2022; Ganguli et al., 2022), and others uses gradient-based transfer attacks to produce even stronger adversaries (Wallace et al., 2019; Zou et al., 2023; Geiping et al., 2024).

Conclusion. We proposed the instruction hierarchy: a framework for teaching language models to follow instructions while ignoring adversarial manipulation. Our current version of the instruction hierarchy represents a dramatic improvement over the current state of affairs for today’s LLMs. Furthermore, given that we have established a behavior taxonomy and over-refusal evaluations, we have confidence that substantially scaling up our data collection efforts can dramatically improve model performance and refine its refusal decision boundary.

There are numerous extensions that are ripe for future work. First, there can be refinements to how our models handle conflicting instructions, e.g., we currently train our models to never follow instructions during browsing or tool use. Second, we focus on text inputs, but LLMs can handle other modalities such as images or audio (Gemini et al., 2023), which can also contain injected instructions (Willison, 2023). We hope to study both the natural generalization of our models to these modalities, as well as create multi-modal instruction hierarchy data. Third, we will explore model architecture changes to better instill the instruction hierarchy, e.g., using specialized embeddings for messages at different levels.

Limitations. Finally, our current models are likely still vulnerable to powerful adversarial attacks. In the future, we will conduct more explicit adversarial training, and study more generally whether LLMs can be made sufficiently robust to enable high-stakes agentic applications.

Lines of inquiry this paper opens 24

Research framings built by reading the notes related to this paper — the questions it feeds into.

Does alignment training genuinely modify model behavior or only outputs? What tradeoffs emerge between instruction following and other model capabilities? How do training data, curriculum, and scale affect capability development? How do quality and diversity in synthetic data affect model capabilities? Why does model self-revision amplify confidence in incorrect answers? How does training data format influence the reasoning strategies models learn? Why don't component-level safety measures prevent system-level safety failures? What systematic biases affect LLM judges and their evaluation outcomes? Do different language models independently converge on similar outputs? What are the fundamental limits of prompting in creating new model capabilities? How do architectural constraints limit monolithic LLM performance on complex tasks?