What is a system prompt? How to write one for the LLM API
The short version
- A system prompt is the message that tells a model how to behave for the whole conversation. In the Chat Completions API, it is the message with
role: "system". - User messages carry each turn's topic. The system prompt carries the rules that never change: role, output format, limits, language and tone.
- Specific beats polite. Replace adjectives like "helpful" and "thorough" with who the model is, what it does, in what format, and what it must not do.
- Keep it short. It is sent, and billed as input tokens, on every request.
- It is an instruction the model usually follows. Users can try to override it, and it does not stop hallucinations.
Where the system prompt sits
A Chat Completions request is an array of messages, each with a role and content. There are three main roles:
| Role | What it is | Typical content |
|---|---|---|
system | The ground rules for the conversation | Role, output format, limits, language |
user | What the user says | Questions, requests, pasted documents |
assistant | The model's earlier replies | Conversation history you send back |
The system prompt holds whatever stays the same on every turn, for example:
- Role: "You are a customer support agent for an online store."
- Output format: "Always reply in JSON." "At most three bullet points."
- Limits: "Do not quote prices." "If you do not know, say 'unknown'."
- Language and tone: "Reply in plain English, in a friendly but brief tone."
The Anthropic Messages API puts the same thing in a top-level system field instead of a message role. The idea is the same.
Why not put it in the user message
For a short exchange, writing the same instructions into the user message often works about as well. There are still three reasons to keep them apart.
- Stability. User messages pile up as the conversation goes on, and early instructions get buried under later turns. The system message is treated as the frame of the conversation, so it holds across turns better.
- Priority. Many models are tuned to weigh system instructions above user instructions. Contracts like "the output is JSON" belong in the system prompt.
- Separation. Rules your app sets (system) stay apart from what the end user types (user), which keeps both the code and the prompts easier to manage.
Before and after
Replacing vague instructions with specific ones changes how stable the output is.
Before (vague)
You are an excellent assistant. Please answer politely.
After (specific)
You are the support agent for the SaaS product "Example".
- Reply in English.
- Use at most three bullet points, each under 20 words.
- Do not answer pricing or contract questions; direct the user to the sales team.
- If the answer is not in the provided documents, do not guess. Say "I couldn't confirm that."
Words like "excellent" and "polite" hand the judgment back to the model. Write down who it is, what it does, what format it uses, and what it must not do.
Three rules that hold up in production
- Specific beats polite. Courtesy in the prompt does not improve the answer. Spend the words on limits, format and edge cases.
- Put the output contract in the system prompt. JSON key names, length limits and anything else your app parses belong there; the user message carries only the topic.
- Keep it short. The system prompt is sent with every request and billed as input tokens each time. A 1,000-token system prompt sent on 100 calls is 100,000 input tokens. Cut the preamble. The context window post covers how those tokens add up against the model's limit.
In a request
A request with a system message looks like this. The endpoint is https://api.fastmetal.ai/v1/chat/completions.
curl https://api.fastmetal.ai/v1/chat/completions \
-H "Authorization: Bearer $FASTMETAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic-claude-haiku-4-5",
"messages": [
{"role": "system", "content": "You are the support agent for a SaaS product. Reply in English, in at most three bullet points. If the information is not in the documents, say \"I couldn'\''t confirm that.\""},
{"role": "user", "content": "How do I reset my password?"}
]
}'
With the OpenAI Python SDK, only base_url changes:
from openai import OpenAI
client = OpenAI(
api_key="<FASTMETAL_API_KEY>",
base_url="https://api.fastmetal.ai/v1",
)
resp = client.chat.completions.create(
model="anthropic-claude-haiku-4-5",
messages=[
{"role": "system", "content": "You are the support agent for a SaaS product. Reply in English, in at most three bullet points."},
{"role": "user", "content": "How do I reset my password?"},
],
)
print(resp.choices[0].message.content)
Models follow the same system prompt differently. Some keep the format exactly; others drift in tone. One FastMetal key calls many models, so the quickest comparison is to change the model value and run the same prompt again. The candidates are in the model catalog.
What a system prompt cannot do
A system prompt is an instruction. Treat it as one layer of control, with others around it.
- It can be overridden. If user input contains "ignore all previous instructions", the model may comply. An app that handles outside input needs input validation and output checks of its own, beyond the system prompt.
- It does not end hallucinations. "If you don't know, say so" lowers how often the model makes things up; it does not bring that to zero.
- Randomness is a separate setting. If the format still wobbles, look at
temperatureas well (temperature and top_p).
FAQ
Do I need a system prompt?
No. Without one, the model uses its default behavior. If your app depends on a stable format or tone, write one, even a short one.
System or user: where does an instruction go?
Anything that holds no matter how many turns pass goes in the system prompt. This turn's topic and documents go in the user message. Specs your app depends on, such as JSON key names, always go in the system prompt.
Is the system prompt billed?
Yes. It is sent as input tokens on every request, so a longer prompt costs more on every call. Short and specific is better for both quality and cost.
Summary
The system prompt sets the role, format, limits and language for the whole conversation. Write a specific contract in place of vague adjectives, keep it short, and do not rely on it as your only defense. The API getting-started guide covers your first request; then run the same system prompt against a few models and compare.