system prompt
A system prompt is a message tagged with a special role — distinct from the user and assistant roles in the chat format OpenAI standardized around 2022 and 2023 — that sets persistent instructions, persona, and constraints for an entire conversation, usually hidden from the end user. What makes a system prompt different from just putting the same text at the top of a user message is not merely its position in the conversation: Wallace and colleagues' 2024 OpenAI paper "The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions" describes explicitly training models to treat system-level and developer-level instructions as outranking user instructions, so that a model correctly trained on this hierarchy will hold to a system instruction even when a user's message directly tries to override it — the priority isn't just a formatting convention, it's a behavior reinforced into the model's weights during training.
Prompt injection attacks exist precisely because this hierarchy has to be learned, not just formatted, and a model that only respects position rather than trained priority is trivially exploitable. A user message that opens with "ignore all previous instructions" or pastes in fake text formatted to look like a system message is attempting exactly the attack the instruction hierarchy is meant to resist — if a model only treated the first message in a conversation as more authoritative because of where it sits, rather than because of a learned, trained distinction in what kind of message it actually is, then any user could simply claim their own text was a system instruction and have the model believe it. This is why robustness against prompt injection is treated as a training problem in papers like Wallace et al.'s, not a prompt-formatting problem a developer can fully solve just by writing a stronger system prompt.
What actually goes inside a production system prompt is less about creative persona-writing than about three concrete jobs: defining scope, setting refusal boundaries, and constraining output format. A customer-support assistant's system prompt typically names what it can and can't help with, lists the specific topics or actions it should refuse or escalate to a human for, and specifies exactly how responses should be structured — because an assistant whose output format varies unpredictably from one response to the next is far harder to integrate into a product than one that can't handle every edge case gracefully. Tool-use permissions, where relevant, also live here: which tools the model is allowed to call and under what conditions is exactly the kind of instruction that needs to sit at the system level rather than be re-stated by the user every turn.
A longer, more detailed system prompt is not automatically a better one, and there's a real trade-off in how much space it occupies. Every token in the system prompt is a token present in every single turn of the conversation, consuming context window budget and, in API-billed usage, adding cost on every request regardless of whether a given turn actually needed that instruction — which is why production system prompts tend to converge on being as short as reliably possible rather than exhaustively covering every edge case up front, leaning instead on the model's trained instruction-following ability to generalize from a concise, well-specified set of rules.
The system prompt's real function is establishing a fixed, trusted frame that persists underneath an otherwise unpredictable stream of user input, and the reason that frame actually holds under pressure — rather than being just the first thing a clever user learns to talk the model out of — is that modern models are specifically trained to recognize and preserve exactly this distinction between an instruction that sits above the conversation and one that's just another message within it.