LearnThatStack Ace your next interview
Prompt Engineering · question
Question 3 of 55

What is a system prompt, and how does it differ from a user message?

beginner
← All Prompt Engineering questions
Re-explain

A system prompt is the instruction block you set once for the whole conversation. A user message is a single turn of input from the person or your calling code.

client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a support agent for Acme. Answer only from the provided docs.",
    messages=[{"role": "user", "content": "How do I reset my password?"}],
)

In Anthropic's Messages API the system prompt is a top-level system parameter, not a role inside messages. OpenAI's API takes it as a message with role system or developer.

The system prompt persists across every turn, so it holds the durable rules: the role and tone, the output format, and the hard limits. When a user message contradicts it, models are trained to follow the system prompt. Keep per-request data in the user message. A stable system prompt also caches well as a shared prefix.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Prompt Engineering One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • You said the system prompt persists across turns. Where does it live between requests? The Messages API is stateless, so your code resends the system prompt and full history on every call. It persists only because you keep sending it.
  • How do the major APIs rank system, developer and user instructions when they conflict? Name the instruction hierarchy. It is a trained preference, not a guarantee, so a strong answer also enforces hard limits in code.
  • Should a system prompt be treated as a secret, and what would you never put in one? Assume users can extract it. Keep keys, credentials and other users' data out, and never rely on its wording as access control.
  • How does prompt caching change what you put in the system prompt versus the user message? Caching matches an exact prefix, so stable rules go first and stay unchanged. A timestamp or user name in the system prompt changes the prefix on every call.
  • Can a well-written system prompt stop prompt injection that arrives in the user message? A strong answer says it only lowers the odds, then puts the real limits outside the model, like tool permissions and checks on the output.

What you can say

  1. A system prompt is the instruction block you set once for the whole conversation, and a user message is a single turn of input from the person or your calling code.
  2. In Anthropic's Messages API the system prompt is its own top-level system parameter, not a role inside messages, while OpenAI takes it as a message with the system or developer role.
  3. Since it applies to every turn, I put the durable rules there, meaning the role and tone, the output format and the hard limits.
  4. If a user message contradicts those rules, models are trained to follow the system prompt, which is why the rules belong there and not in a user turn.
  5. Per-request data goes in the user message, because a system prompt that never changes caches well as a shared prefix and one that changes on every call does not.

Weak answers to avoid

  • Says the system prompt is just the first message In Anthropic's API it is a separate top-level system parameter, not a message. Say where each API puts it and that it applies to every turn.
  • Puts per-request data in the system prompt Changing it every call breaks the shared-prefix cache and mixes durable rules with one-off data. Rules go in the system prompt, request data in the user turn.
  • Claims the system prompt always wins Models are trained to follow it over user messages, but that is not a guarantee. Say that hard limits also need checks outside the model.
  • Defines both terms but never says why the split matters The interviewer wants to hear what goes where. Name the durable rules, like role, format and hard limits, and say why they belong in the system prompt.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Prompt Engineering cheatsheet.

← Back to all Prompt Engineering questions
Pro · $10/mo

48 of 55 Prompt Engineering answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime