The instruction hierarchy is a training method from OpenAI that teaches a language model to rank instructions by where they come from: the developer's system message first, then the user, then third-party content like tool outputs. When instructions conflict, the model should follow the higher-ranked one.
It was introduced in the paper The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions, submitted on April 19, 2024, by Eric Wallace, Kai Xiao, Reimar Leike, Lilian Weng, Johannes Heidecke and Alex Beutel. OpenAI also published a short overview.
The problem it targets
The paper argues that many attacks work because models treat every piece of text as equally authoritative. A system prompt written by the developer carries the same weight as a sentence in a web page the model just read.
That's the root of both prompt injection and jailbreaking. If a model gives a tool result the same authority as its developer, then whoever controls the tool result controls the model.
How the instruction hierarchy works
The paper sets out levels of privilege:
- System message from the application developer.
- User message from the person using the app.
- Third-party content such as tool outputs and search results.
Lower-level instructions fall into two kinds.
Aligned instructions fit the higher-level goal, so the model should follow them. The paper's example is a car-sales bot whose user asks it to reply in Spanish. That doesn't conflict with the developer's intent.
Misaligned instructions conflict with it, so the model should ignore them, or refuse if it can't proceed.
How they trained it
The team generated training data in two ways:
- Context synthesis for aligned instructions. A request is split into parts, the parts are placed at different levels, and the model learns to produce the same answer as if it had seen the whole request.
- Context ignorance for misaligned instructions. The model learns to respond as if the lower-level injection had never been there.
They fine-tuned GPT-3.5 Turbo with this data and compared it to a baseline trained the same way without it.
What the paper found
- Robustness went up on every main evaluation, by as much as 63%. The biggest gain cited was against system prompt extraction.
- It generalized. The model got more robust, by up to 34%, against attack types it never trained on, including jailbreaks, password extraction and prompt injection through tool use.
- General ability held steady. Scores on standard benchmarks were comparable to the baseline.
- Some over-refusal. The model followed harmless instructions nearly as well as before, with some regressions on test sets built to be tricky.
The appendix also reports that simply describing the hierarchy in a system prompt worked far worse than training on the data. That matters if you were hoping to get the same effect with a clever prompt.
Limits to keep in mind
The authors say their models are likely still vulnerable to strong adversarial attacks, and they list future work: handling multimodal inputs, refining how the model treats instructions it meets while browsing or using tools, and possible architecture changes.
So the instruction hierarchy makes injection harder. It doesn't make it impossible. It's a model-level layer, and it should sit beneath system-level defenses that don't depend on the model getting every judgment right, such as the design patterns for securing LLM agents or spotlighting.
What this means for your app
- Use the roles properly. Put your rules in the system message and keep untrusted content out of it. If you paste a web page into the system message, you've handed it the top rank.
- Return outside content as tool results where your API allows it, so the model can treat it as lowest priority.
- Don't rely on it alone. Keep least privilege, output validation and human approval for risky actions, as covered in How to Prevent Prompt Injection.
- Test across model versions. How well a model respects the hierarchy can change between releases, so rerun your tests whenever you switch.
Next step: run the canary payloads through each input role your app uses and check which ones the model obeys.