A system prompt is a set of instructions an AI model receives before the conversation starts, and it applies to every message that follows. It sets the model's role, its audience, its rules and its default answer format, so you do not have to repeat them in each message. The user writes the prompts; the system prompt shapes how the model answers all of them.
Every chat app already uses one. When you open ChatGPT, Claude or Gemini, the model already has instructions from the company behind it, which the chat window does not show you. When developers build an app on top of a model, the system prompt is where they turn a general model into a coding tutor, a support assistant or a commit message writer.
What a system prompt does
A model's input in a chat has a structure: a system prompt first, then the conversation as alternating user and assistant messages. The system prompt sits above the whole exchange, so it is in front of the model for every reply, however long the chat gets.
That position makes it the right home for anything that should always hold: who the model is speaking to, what it may and may not do, what an answer should look like by default. Models are also trained to give it more weight than a user message when the two conflict. That is a tendency, not a lock. A determined user can sometimes talk a model out of its system prompt, which is why it should never be your only safeguard.
System prompt vs user message
| System prompt | User message | |
|---|---|---|
| Who writes it | The developer, or you in the app's settings | You, in the chat box |
| Scope | The whole conversation | One request |
| Typical content | Role, audience, rules, facts, default format | The task and the material for it |
| When it changes | Rarely | Every turn |
| Weight in a conflict | Usually higher | Usually lower |
A useful test: if a sentence would be true for every message in the chat, it belongs in the system prompt. If it is about this particular request, it belongs in the user message. "Answer in under 100 words" can go in either; "summarize the email below" is always a user message.
Where to set a system prompt
In the API, the system prompt is a separate input. With OpenAI's Python library it is the first message in the list, with the role system. OpenAI's documentation also uses the name developer message for the same kind of instruction on newer models.
from openai import OpenAI
client = OpenAI()
MODEL = "your-model-id" # e.g. from your provider's model list
response = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": "You are a patient Python tutor. Give hints, not full solutions."},
{"role": "user", "content": "Why does my loop stop at 9?"},
],
)
print(response.choices[0].message.content)
With Anthropic's Python library it is a top-level system parameter, and the messages list holds only the conversation:
import anthropic
client = anthropic.Anthropic()
MODEL = "your-model-id" # e.g. from your provider's model list
message = client.messages.create(
model=MODEL,
max_tokens=500,
system="You are a patient Python tutor. Give hints, not full solutions.",
messages=[{"role": "user", "content": "Why does my loop stop at 9?"}],
)
print(message.content[0].text)
Google's Gemini API calls it a system instruction. The name differs, the idea is the same.
In chat apps, you do not get the raw system field, because the app already has its own. What you get is a place to add standing instructions that the app includes for you. In ChatGPT these are custom instructions, project instructions and the instructions of a custom GPT. In Claude they are project instructions and the preferences in your profile. In Gemini they are the instructions of a Gem. Exactly how each app merges your text with its own instructions is not fully documented, but in practice they behave like a system prompt you share with the app.
What to put in a system prompt
- Role and audience. "You are a tutor for students in their first month of programming" sets the vocabulary and the level of every answer. Role prompting covers what a role changes and what it does not.
- Rules that hold for every turn. What the model must always or never do: give hints instead of full solutions, answer only questions about the product, reply in the user's language.
- What to do when unsure. "If the answer is not in the facts below, say you do not know" does more against invented answers than a general "be accurate".
- Facts the model needs. Product details, policies, the current date, the user's plan. A model cannot answer questions about your app from training data.
- Default format. Length, structure, whether to use code blocks. If a program reads the output, give the exact shape; see structured output.
What to leave out
Secrets. A system prompt is not private. Users can ask a model to repeat its instructions or trick it into it, and models do not reliably refuse. API keys, passwords and anything you would not want published do not belong there. Treat the system prompt as text the user may one day read, and see prompt injection for how instructions get overridden.
The task of one message. If the system prompt says "summarize this article", the second message in the chat has nowhere to go.
Piles of overlapping rules. Twenty rules written at different times tend to contradict each other, and the model has to guess which one wins. Group the rules, remove duplicates and state priorities when two can collide.
Padding. The system prompt is sent again with every request and counts against the model's context window, so each unnecessary paragraph is paid for on every turn.
System prompt examples
The first example is a product assistant. The system prompt sets a scope, a length and a rule for questions it cannot answer, and carries the facts the model needs. Switch between the tabs to send it different messages: the same system prompt shapes all three replies.
Open the purchase in your transactions and tap Split. Then choose the two categories, Groceries and Household, and enter the amount that belongs to each.
The second example is the kind of text you might put in custom instructions or project instructions in a chat app. It describes you and how you want answers, so every chat starts from that.
import { readFile } from "node:fs/promises";
const config = JSON.parse(await readFile("config.json", "utf8"));
Passing an encoding makes readFile return a string, which JSON.parse turns into an object. Top-level await only works in an ES module ("type": "module" in package.json or a .mts file); otherwise wrap the call in an async function. Add a try/catch if the file might be missing or malformed.
Without the system prompt, a question as short as "how do I read a JSON file?" leaves the model to guess the language, and the reply often comes in Python or plain JavaScript with a paragraph about what JSON is. With it, the reply picks the right language and runtime, skips the basics and follows the requested shape.
The same structure works for any assistant you set up: who it serves, the rules, what to do when unsure, the facts it needs and the answer format. Write it once, test it with a normal question, an off-topic one and one that tries to break a rule, and adjust until all three replies are what you want.
Frequently Asked Questions
What is a system prompt?
A system prompt is a set of instructions given to an AI model before the conversation starts, and it applies to every message that follows. It usually sets the role, the audience, the rules and the default answer format. In the API it is a separate system field or message; in chat apps, custom instructions and project instructions serve the same purpose.
What is the difference between a system prompt and a user prompt?
The system prompt holds standing instructions for the whole conversation and is usually written by the developer or set once in settings. The user prompt is a single message asking for one thing. When the two conflict, models are trained to give the system prompt more weight, though that is a tendency rather than a guarantee.
Can I set a system prompt in ChatGPT, Claude or Gemini?
Not the raw system field, but close to it. ChatGPT has custom instructions, project instructions and instructions for custom GPTs. Claude has project instructions and profile preferences. Gemini has instructions for Gems. The app combines what you write there with its own system instructions and applies it to your chats.
Can users see or extract a system prompt?
Often, yes. A user can ask the model to repeat its instructions or trick it into doing so, and models do not keep them reliably secret. Never put passwords, API keys or confidential business details in a system prompt, and do not rely on it as a security boundary.
How long should a system prompt be?
Long enough to cover what applies to every message and no longer. A personal one can be three or four sentences. A system prompt for a product often runs to a page, with the role, rules, facts and output format. Every word is sent with every request, so it also costs tokens each time.