Skip to content
bits
Prompting that works · Lesson 5 of 10

Roles and the system prompt

Tutor:

A request to Claude has two places for words. The system prompt says who Claude is and the rules that hold for the whole conversation. The messages carry the conversation itself: what the user asks, and Claude's replies.

The most common thing to put in the system prompt is a role. Anthropic's guidance is that even a single sentence of role focuses Claude's behaviour and tone for your use case.

import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const reply = await client.messages.create({
model: "claude-haiku-5-5",
max_tokens: 1024,
system: "You are a patient science tutor for 12-year-olds. Use everyday examples and no jargon.",
messages: [{ role: "user", content: "Why is the sky blue?" }],
});
for (const block of reply.content) {
if (block.type === "text") console.log(block.text);
}
TypeScriptUTF-8● lines 8–9: highlighted
Tutor:

The role lives in system, so it applies to every turn. The user's question goes in messages. The loop at the end prints only the text blocks: Claude Haiku 5.5 thinks by default, so a reply can start with a thinking block (more on that in lesson 7).

Tutor:

A good role is more than a job title. “You are a tutor” helps a little. Add who it's talking to and how it should sound, and it helps a lot.

No role vs Role, audience and toneillustrative: made-up numbers that show the idea, not output from a real modelcompare

promptWhat is an API?

No role

An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate with each other, defining the methods and data formats for requests and responses.

Role, audience and tone

Think of a restaurant. You don't walk into the kitchen; you tell the waiter what you want, and the waiter brings it back. An API is the waiter between two apps.

Tutor:

The right column came from adding: “You are a patient teacher explaining tech to a 10-year-old. Use one everyday comparison and no jargon.”

Building a chatbot? Anthropic suggests telling Claude Haiku 5.5, in the system prompt, that its rules hold for the whole conversation, even when a user argues, gives a sympathetic reason or keeps asking. In their testing, that line made it stick to the system prompt more often.

quick check+10 neurons
Tutor:

You're building Moon Café's help bot. Where does “You are Moon Café's assistant. Only answer questions about the café.” belong?

    Type your answer or tap an option · Enter checks

    Tutor:

    An honest note about this sandbox. It already has a system prompt, and you can't change it: “You are the model in bits, a sandbox where people learn to prompt. Answer the prompt directly and briefly (under 80 words). No preamble.” Whatever you type arrives as the user message.

    So here, put your role at the top of your message. That works too; it's just not where a role belongs in your own app.

    Your turn. Ask Claude to explain what an API is, with a role, an audience and a tone.

    Your turn

    Run your prompt and the replies land here.

      • Gives a role, not yet
      • Names the audience, not yet
      • Sets a tone, not yet
      • Asks the question, not yet
      • Ran at 1.0, not yet
      run at
      ~0 tokens

      Turn on JavaScript to run prompts.