If you have built anything with a modern language model, you have encountered the idea of a "system prompt," often described as the instruction that sets the model's behavior or persona. But the system prompt is best understood not in isolation but as one piece of a larger structure: the chat message format. That format, a list of messages each tagged with a role, is how virtually all conversational models receive input today. Understanding roles and messages explains how instructions, conversation history, and user input coexist in a single request, and why that structure matters. This article unpacks it from the ground up.

Before chat: a single blob of textasdasasdsadasdasddasd

Early language models had a simpler interface. You passed one string of text, the prompt, and the model continued it. To build a chatbot on top of that, developers manually formatted everything into one blob: instructions, prior turns, and the latest question, separated by labels they invented. It worked, but it was fragile. There was no agreed structure, no clean boundary between the developer's instructions and the user's input, and every application reinvented the formatting.

The chat message format standardized this. Instead of one string, you send a structured list of messages. Each message has a role and content. The roles carry meaning the model has been trained to respect, and the structure makes the boundaries between different kinds of text explicit.

The three core roles

Most chat APIs share the same small set of roles. Their names are conventions, but the concepts are near-universal.

  • System: high-level instructions that frame the entire conversation. Tone, persona, rules, constraints, and context the model should honor throughout. Typically set by the developer, not the end user.

  • User: input from the person interacting with the model. Their questions, requests, and messages.

-assistant: the model's own responses. In a multi-turn conversation, prior assistant messages are included so the model can see what it already said.

A request is an ordered list of these messages. The system message, when present, usually comes first. Then user and assistant messages alternate, representing the back-and-forth of the conversation, ending with the latest user message that the model should now respond to.

A chat request is a list of role-tagged messages
messages = [
{"role": "system", "content": "You are a concise technical assistant. "
"Prefer short answers and SI units."},
{"role": "user", "content": "How far is the Moon from Earth?"},
{"role": "assistant", "content": "On average, about 384,400 km."},
{"role": "user", "content": "And the Sun?"}
]
The model reads the whole list and generates the next
assistant message, using the system framing and the prior turns.

In that example, the final user message "And the Sun?" only makes sense because the earlier turns are present. The model resolves "the Sun?" to "distance from Earth" using the conversation history, and it answers concisely with metric units because the system message told it to. Remove the system message and the style guidance disappears; remove the history and the follow-up becomes ambiguous.

What the system prompt actually does

The system prompt is a lever for behavior that should persist across the whole exchange. Good uses include setting a role ("You are a patient tutor for beginners"), establishing constraints ("Only answer questions about cooking; politely decline others"), defining output format ("Respond in valid JSON with keys 'summary' and 'tags'"), and supplying stable context ("The current product version is 4.2"). Because it is conceptually separate from user input, it is also where developers place guardrails they do not want casual user messages to override.

It is important to be clear-eyed about its nature, though. A system prompt is strong guidance, not an impenetrable wall. The model weighs all the messages together. Instructions in the system role generally carry more influence than ordinary user text, which is why safety and formatting rules go there, but they are still probabilistic guidance rather than hard enforcement. Treating the system prompt as unbreakable security is a mistake; it shapes behavior, it does not guarantee it.

How roles become model input

Underneath, the model still consumes a single sequence of tokens, so the structured message list has to be flattened back into text before generation. This is done with a chat template: a defined formatting scheme that inserts special tokens or markers around each message to signal its role. A simplified version looks like this.

Conceptual flattening of messages into one token sequence
def render(messages):
out = []
for m in messages:
out.append(f"<|{m['role']}|>\n{m['content']}\n<|end|>")
out.append("<|assistant|>\n") # cue the model to respond
return "\n".join(out)
The special role markers are what the model was trained to
recognize, so it knows which text is instruction vs. user input.

The exact markers differ between model families, and using the wrong template can noticeably degrade quality, because the model expects the specific delimiters it saw during training. This is a subtle but real detail: the "magic" of roles comes from the model having been fine-tuned on data formatted with these exact structural cues, so the format is not arbitrary decoration but part of what the model learned.

Beyond the core three: the tool role

As models gained the ability to call external functions, the message format grew to accommodate it, and most chat APIs now include an additional tool role (sometimes called "function"). The pattern works like this: the assistant can respond not with text but with a request to call a named tool and some arguments; the application executes that tool and appends a message with the tool role containing the result; then the model is called again and sees the tool output as part of the conversation, letting it produce a final answer grounded in that result. The important observation is that this did not require a new mechanism. It reused the same roles-and-messages structure, simply adding another role whose messages carry tool outputs. This extensibility is a strength of the format: new interaction patterns slot in as new message types rather than new protocols.

Multi-turn conversations and statelessness

A key property catches many newcomers off guard: chat APIs are typically stateless. The model does not remember previous turns on its own. Each request must include the full conversation history you want the model to consider. The illusion of memory in a chat interface is created by the application resending the accumulated messages every turn.

This has direct consequences. The conversation grows with each turn, consuming more of the context window and more tokens, which raises cost and eventually forces strategies like truncating or summarizing old turns. It also means the application, not the model, owns the conversation state and decides what history to include. Understanding this removes a lot of confusion about why a model "forgot" something: it was simply never sent that history in the current request.

Why standardizing the format matters

The roles-and-messages structure has become a de facto standard across the ecosystem, and that standardization is quietly powerful. Because many providers and open-weight models accept the same message shape, application code can target one format and talk to many different models. This is exactly what an OpenAI-compatible AI gateway standardizes: it exposes the familiar chat-messages interface so that the same request structure routes to different backends without rewriting the calling code. The system/user/assistant message list becomes a stable contract between applications and whatever model sits behind it.

Practical tips for writing system prompts

  • Be specific and concrete. "Answer in at most three sentences" beats "be brief."
  • Put durable rules in the system role and transient requests in user messages, so persistent behavior stays separate from one-off asks.
  • State output format explicitly when you will parse the response programmatically.
  • Do not rely on the system prompt alone for security-sensitive restrictions; combine it with validation outside the model.
  • Remember every turn resends history, so keep system prompts focused; needlessly long ones cost tokens on every single request.

Key takeaways

  • A system prompt is one message in the chat format, which structures input as an ordered list of messages each tagged with a role.
  • The core roles are system ** (durable framing and rules), **user (the person's input), and assistant (the model's prior replies).
  • The system prompt sets persistent behavior like persona, constraints, and output format, but it is strong guidance, not unbreakable enforcement.
  • Messages are flattened into one token sequence via a chat template with special role markers the model was trained to recognize, so the correct template matters.
  • Chat APIs are usually stateless: the application must resend the full history each turn, which drives token cost and context limits.
  • The roles-and-messages format is a de facto standard, and an OpenAI-compatible gateway standardizes exactly this interface so the same request can route to different models.