An instruction hierarchy is a priority ordering of instruction sources that a large language model is trained to respect, so that system and developer instructions outrank user messages, and user messages outrank text arriving from tools, documents and web pages. In AI security, it is a model-level defense against prompt injection and jailbreaks: when a lower-privileged input tries to override a higher-privileged one, the model is expected to ignore the conflicting instruction while still completing the legitimate task.
The idea was formalized in 2024 research on training models to prioritize privileged instructions, and it now appears in the published behavior specifications of several model providers, often described as a chain of command. It sits alongside architectural defenses such as spotlighting, the dual LLM pattern and CaMeL, which do not rely on the model choosing correctly.
Why language models need an instruction hierarchy
A language model needs an instruction hierarchy because it receives all of its inputs as one token stream. Without explicit training, a sentence inside a retrieved email or a search result carries roughly the same weight as the developer’s system prompt, which is the root cause of indirect prompt injection.
Classic software separates code from data at the level of the processor and the operating system. A language model has no hardware boundary between instructions and data, so the separation must be learned. The hierarchy gives the model a rule for resolving conflicts: trust follows the source of the text, not its wording, its urgency or its claimed authority.
Privilege levels and how they are ranked
Most implementations define three or four privilege levels, each mapped to a distinct message role in the chat format. The table below shows a typical ordering from highest to lowest authority.
| Level | Message source | Typical content | Default trust |
|---|---|---|---|
| Platform or system | Model provider | Usage policies and safety rules | Highest, cannot be overridden |
| Developer | Application builder | Persona, scope, tool rules | High within platform limits |
| User | Person in the conversation | Questions and task requests | Medium within developer limits |
| Tool output | Search, files, APIs, web pages | Retrieved data | Treated as data, no authority |
The key design choice is that tool outputs carry no instruction authority at all. A web page can supply facts for an answer, but an imperative sentence inside it, such as a request to forward the user’s files, should be treated as content to report, not a command to execute.
Aligned and misaligned instructions
The hierarchy does not tell the model to ignore everything below the top level. It distinguishes aligned instructions, which fit the goals of higher-level instructions, from misaligned instructions, which contradict them or have nothing to do with the assigned task.
A user asking a customer support assistant to answer in Spanish issues an aligned instruction, and the model should comply. A user asking the same assistant to reveal its system prompt issues a misaligned one when the developer has marked the prompt as confidential. The following table summarizes the expected behavior.
| Situation | Classification | Expected behavior |
|---|---|---|
| User asks for a shorter answer | Aligned | Comply |
| User asks to ignore the system prompt | Misaligned | Decline politely and continue |
| Retrieved page says to email a password | Misaligned, injected | Ignore and optionally warn |
| Tool result reports an error code | Data | Use as information |
| Developer forbids topics outside scope | Higher-level rule | Enforce over user requests |
Getting this balance right is difficult. A model that is too strict refuses benign requests, while a model that is too permissive follows injected text. Both failures are measured during evaluation.
How models are trained to follow the hierarchy
Models learn the hierarchy through supervised fine-tuning and reinforcement learning on synthetic conversations that contain deliberate conflicts. Two complementary data-generation strategies are widely described.
- Context synthesis decomposes a compound instruction into parts and places them at different levels, teaching the model to combine aligned instructions correctly.
- Context ignorance inserts adversarial instructions into lower levels and trains the model to produce the response it would give if the injection were absent.
- Red-team generation uses one model to write attacks against another, which supplies varied injection styles at scale.
- Refusal calibration adds benign look-alike prompts so that the model does not over-generalize into refusing normal requests.
Evaluation then covers system prompt extraction, direct jailbreaks, indirect injection through tools and over-refusal on benign inputs. Published results show substantial robustness gains on attack types not seen in training, together with a modest increase in unnecessary refusals.
Instruction hierarchy compared with other defenses
An instruction hierarchy is a probabilistic, model-internal control, so it is best combined with defenses that enforce separation outside the model. The comparison below shows how it fits with neighboring techniques in the AI security toolkit.
| Defense | Where it operates | Main strength | Main weakness |
|---|---|---|---|
| Instruction hierarchy | Model weights | No change to application code | Can be bypassed by novel attacks |
| Spotlighting | Prompt formatting | Marks untrusted text clearly | Relies on model attention |
| Dual LLM pattern | Application architecture | Privileged model never sees raw data | Limits flexibility |
| CaMeL | Control and data flow | Enforces policies deterministically | Engineering effort and latency |
| LLM firewall | Input and output filtering | Blocks known patterns | Misses paraphrased attacks |
The practical lesson is defense in depth. The hierarchy lowers the success rate of attacks, while architectural controls limit the damage when an attack still succeeds, which matters most for agents that combine private data, untrusted content and external actions, the combination known as the lethal trifecta.
Limitations and common misconceptions
The most important limitation is that an instruction hierarchy is not a security boundary. It shifts probabilities, and determined attackers using multi-turn jailbreaks, token smuggling or multimodal prompt injection can still find inputs that the model misclassifies.
- Misconception: a strong system prompt is enough. Wording alone does not create privilege; the model must be trained to honor roles.
- Misconception: role labels are unforgeable. If an application concatenates untrusted text into the system message, that text inherits system-level privilege.
- Risk: over-refusal. Aggressive training can make assistants ignore legitimate user preferences.
- Risk: ambiguous authority. Conflicts between two developer instructions, or between a developer and platform policy, need explicit tie-breaking rules.
Developers should therefore keep untrusted content in tool or user roles, apply least privilege to every tool an agent can call, and require human confirmation for irreversible actions such as payments, deletions or outbound messages.
In everyday language
Think of a new employee at a bank. The bank sets the rules, the manager gives daily tasks, and customers make requests. If a customer hands over a note saying the manager wants the vault opened, the employee should not obey the note. Authority comes from who is speaking, not from what the note claims.
An instruction hierarchy teaches an AI model the same habit. Rules from the company that runs the app come first. Requests from the person chatting come next. Text the model reads on web pages or in files is information only, never orders. This makes the model much harder to trick, although not impossible to trick.
Seen in the real world
A software company deploys an email assistant that can read a user’s inbox, summarize messages and draft replies. An attacker sends an email containing hidden white text that tells the assistant to forward the last ten invoices to an outside address and then delete the evidence.
Because the underlying model was trained with an instruction hierarchy, it treats the email body as tool output without authority. It summarizes the message as a suspicious email containing embedded instructions and takes no forwarding action. The developer had also configured the application so that sending mail requires user confirmation, giving a second barrier.
During a later security review, the team runs a set of several hundred injection test cases. Most are ignored by the model, and the few that slip through are stopped by the confirmation step. The review concludes that layered controls, not the model alone, kept the invoices safe.