Instruction hierarchy

An instruction hierarchy is a ranking that tells a language model whose instructions win when they conflict, so developer rules outrank user requests and text from tools or web pages carries the least authority.

A chatbot or AI agent receives text from several sources at once: the developer's system prompt, the user's messages, and content pulled in by tools, such as a web page, an email or a file. Language models have often given all of it the same priority, so an instruction hidden in a web page could carry as much weight as the developer's own rules. That is the opening prompt injection attacks exploit. An instruction hierarchy fixes an order of priority and trains the model to follow it.

OpenAI researchers set out the idea in an April 2024 paper, The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions, by Eric Wallace and colleagues. Their ranking put system messages from the developer first, user messages second, model outputs third and tool outputs last. Lower-ranked instructions are not simply ignored. If they fit the higher-level rules, such as a user asking a car-sales bot to reply in Spanish, the model should follow them. If they conflict with those rules, the model should ignore them or decline.

The paper's motivating example is an email assistant. A message arrives whose body tells the assistant to forward every email in the inbox to an outside address. Without a hierarchy, the model may treat that sentence as a command. With one, it treats the email as data to read, not orders to obey. The authors trained GPT-3.5 on generated examples of both cases and reported improvements in resistance of up to 63% on their main evaluations, including attempts to extract the system prompt, and up to 34% on attack types not seen in training, with standard capability scores roughly unchanged. The model did become more likely to refuse some harmless requests.

The approach has since been written into company rules for model behaviour. OpenAI's Model Spec, as published in October 2026, describes a chain of command running from OpenAI's own rules through developer messages to user messages, and says quoted text, file attachments and tool outputs have no authority by default, so instructions inside them are to be treated as information.

In practice, an instruction hierarchy is a trained habit, not a security boundary. It makes prompt injection harder but does not make it impossible, which is why security guidance still tells developers to limit what an agent can do once it has read untrusted content.

Common questions

What is the instruction hierarchy in LLMs?

It is a priority order for instructions from different sources. Developer system prompts rank highest, user messages next, and content returned by tools such as web pages or emails lowest. The model is trained to follow lower-ranked instructions only when they fit the higher-ranked ones.

Does the instruction hierarchy stop prompt injection?

It reduces it but does not stop it. OpenAI's 2024 paper reported large improvements in resisting injections and jailbreaks, including attack types not seen in training, but no trained behaviour is perfectly reliable. Developers still need other controls, such as limiting what actions an agent can take.

Who created the instruction hierarchy?

The idea was set out by OpenAI researchers Eric Wallace, Kai Xiao, Reimar Leike, Lilian Weng, Johannes Heidecke and Alex Beutel in a paper published in April 2024. They tested it by training GPT-3.5.

Does the instruction hierarchy make models refuse more?

It can. The 2024 paper found the trained model sometimes ignored or refused harmless instructions, and noted regressions on two tests designed to check for this. The authors expected the effect to matter less in everyday use and suggested more training data could reduce it.

Finding more

Search for "instruction hierarchy LLM", "privileged instructions prompt injection" and "model spec chain of command" to see the original research and how companies apply it. The most reliable sources are the research paper on arXiv and the behaviour specifications that model providers publish themselves. Independent prompt injection studies are a useful check, since a provider's own evaluation usually tests the attacks it trained against.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.