Area 01 · LLM · Concept 07 of 20

System Prompts

Standing instructions that set the model’s role, rules and output style.

01–10 · The basePhase 1 · Weeks 3–6≈ 1 hour

The idea

The system prompt is sent with every call, before the conversation. It is where you describe the job, the audience, the tone, the rules and the output format. The model treats it as higher-priority context than user messages, though not as an unbreakable rule.

Good system prompts are specific and explain the reason behind rules. "Answer in under 80 words because users read on a phone" works better than "Be brief". Structure long prompts with headings or XML-style tags so instructions, reference data and examples are clearly separated.

Treat the system prompt as code: keep it in version control, give it a version number, and test changes against a fixed set of inputs before shipping.

Why it matters

It is the cheapest and most powerful control you have. Most "the model is bad at X" problems are fixed here before reaching for fine-tuning.

Words to know

  • Role promptTelling the model who it is acting as.
  • Instruction hierarchySystem instructions outrank user instructions.

Try it without code

Same question, two system prompts

  1. In a playground, set a system prompt for a pirate-themed kids’ tutor and ask "What is photosynthesis?".
  2. Change the system prompt to a terse biology reference for exam revision, and ask again.
  3. Note what changed: length, tone, structure, vocabulary.

Use it in code

A structured system prompt with tags, loaded from a versioned file.

python
import anthropic
client = anthropic.Anthropic()

SYSTEM = """<role>You are a support assistant for Acme Cloud.</role>
<rules>
- Answer in at most 80 words; users read on phones.
- If you are not sure, say so and suggest contacting support@acme.example.
- Never promise refunds; only humans can approve them.
</rules>
<format>Plain text. One short paragraph, then a bullet list of next steps if useful.</format>"""

reply = client.messages.create(
    model="claude-sonnet-5-5", max_tokens=300, system=SYSTEM,
    messages=[{"role": "user", "content": "My server is down, can I get my money back?"}],
)
print(reply.content[0].text)
PRACTICE · TICK IT AFTER THIS

Write a system prompt for your Build-this chatbot, save it as prompts/system_v1.txt, and record three test questions with the answers you expect.

Common mistakes

  • Writing rules in ALL CAPS instead of explaining why they matter.
  • Putting secrets in the system prompt. Users can often extract it.
  • Changing the prompt in production without testing.

Go deeper