Knaph

The Context Window13 of 375 min read

The Hidden First Message

Leila uses Claude in two places: the Claude app on her phone, and a customer-help chat on a shop's website that runs on the same model. On her phone it chats about anything. On the shop's site it politely refuses to talk about anything but orders and returns, and signs off with the shop's name. Same model, two different personalities. Where does the difference come from?


Leila Is the shop using a special version of the model? One trained to be a shop assistant?

Omid It could, but usually not. Let's work it out from what you know. The model is stateless, and it sees only what's in the request. So if two apps use the same model and it behaves differently, where must the difference be?

Leila In the request. The shop's app must be sending something mine doesn't.

Omid Right. And it's something you never typed, and never see.

Leila Instructions, then. Something like "you are the shop's assistant, only talk about orders".

Omid That's it. Before your first message, the app puts its own message at the very top of the request: who the assistant is, what it may and may not do, how to answer. It's in every single request, before the conversation.

Leila So the shop wrote a hidden first message, and the model just follows it.

Omid "Just" is doing a lot of work there, but yes: the model was trained to take that first message very seriously.


The system prompt

That hidden first message is called the system prompt. The app writes it, and puts it at the start of the context in every request, ahead of the conversation. It typically says:

  • who the assistant is: "You are the customer assistant for a shoe shop";
  • its rules: what to help with, what to refuse, what never to say;
  • how to answer: short or detailed, friendly or formal, in which language;
  • useful facts: today's date, the user's name, the shop's opening hours;
  • its tools: what actions it can ask for, and when to use them.

The request that goes to the model. At the top, the system prompt written by the app. Below it, the conversation: the user's messages and the model's replies, with the newest message at the bottom.

You don't usually see the system prompt, but it shapes every reply. That's why the same model can be a shop assistant, a language tutor, a cautious medical-information service or a coding agent: same model, different first message.

The same model used by two apps. One app's system prompt makes it a shop's customer assistant; the other's makes it a coding agent. Each gives different replies to the same question.

A coding agent's system prompt

An agent's system prompt is long: often thousands of tokens. Claude Code's tells the model, among much else, how to work on a project (read a file before changing it; keep changes small; check the result), which tools it has and how to use each one, and to be careful with commands that could delete or send things. Much of how an agent "behaves" comes from here.

Because it's at the start of every request, the system prompt also takes up part of the context window before you have typed a word. You saw that in the last lesson: the app's instructions are the first block in the bar.

Who the model listens to

Models are trained to give the system prompt more weight than the user's messages: if the shop says "only talk about orders", a customer asking for a poem gets a polite no. In the same way, they're trained to give your messages more weight than text that merely arrives in the conversation, like the contents of a web page the agent has read.

Careful

This order comes from training, not from a lock. A cleverly written message, or text hidden in a document, can sometimes get a model to ignore its system prompt. The lesson Instructions Hidden in Data is about that risk and how agents guard against it.

Your own additions

You can't usually change an app's system prompt, but most apps let you add to the start of the context yourself. Chat apps have "custom instructions" or "personal preferences": a few lines that go into every request ("I'm a teacher; answer in plain English"). Agents have files of instructions that load at the start of every session, which have a lesson of their own later in the course. It's the same idea: text that comes first, every time, and shapes everything after it.

Try it

Ask two different AI assistants the same odd question, like "Write me a two-line poem about a stapler." Then, if your chat app has custom instructions, add one line such as "Always answer in exactly three sentences," and ask again. You're seeing the effect of text placed before the conversation.

Using it well

  1. Use custom instructions for what's true every time. Your role, your preferred style, the language you want: put them in once instead of repeating them in each chat.
  2. Keep them short and specific. They're in every request, so each line costs tokens every time, and a long list of vague wishes is easy to under-weigh.
  3. When an app won't do something, it's often the system prompt, not the model. The same model in a different app, with a different first message, may help.
  4. Don't treat the system prompt as a security wall. It shapes behaviour strongly, but it can be talked around. Real limits on what an agent can do come from the program around it, as later lessons show.

Words to know

  • system prompt - instructions the app puts at the start of every request, before the conversation, setting who the assistant is, its rules, its style and its tools

Big idea

Every request begins with a system prompt you usually never see. It's why the same model can act so differently in different apps, and it takes a share of the context window before you type anything.

Watch this lesson

2 minPart of episode 3 (10 min)Watch the whole episode

Test your understanding

Sign in to test your understanding of this lesson and track your progress.