Short answer
A system prompt is the standing brief you give Claude before the conversation starts: who it is, what job it does, which rules it follows and which documents it should use. Write it in plain sentences, put reference material inside clearly labeled XML tags placed before the user's question, and send it through the API's separate system parameter.
Follow-up question Why does Claude respond well to XML tags?
Anthropic added system prompts with Claude 2.1 last November. The idea is simple: instead of repeating your instructions inside every user message, you set them once, above the conversation, and Claude treats them as the frame for everything that follows. Anthropic says a well-written system prompt helps Claude stay in a role over long conversations and makes it more likely to stick to its rules and its task.
System prompts are a developer feature. You use them through Anthropic's API, its Console's Workbench, or Amazon Bedrock. The claude.ai chat site doesn't offer them, so everything below assumes you're calling the API.
What goes into a system prompt
Anthropic's guide lists the kinds of things a system prompt can carry. Grouped into a checklist you can work through:
| Part | What to write | Example |
|---|---|---|
| Role | Who Claude is in this job | "You are the help desk assistant for Riverside Community Garden." |
| Task | What it should do for the user | "Answer members' questions about plots, fees and rules." |
| Context | Background it needs | Who the users are, what they usually ask |
| Rules | Limits and guardrails | Stay on topic, never invent fees, hand off to a person when unsure |
| Style | Tone, length, format | "Friendly, plain language, under 120 words." |
| Knowledge | Documents to rely on | The garden's rules and fee schedule |
| Checks | How to show its work | "Quote the rule you are relying on." |
You won't need every row each time. A short system prompt with a clear role, task and two or three rules often does more than a long one full of hedges.
A worked system prompt
Here is a complete system prompt for a community garden's help desk. Notice the order: documents first, inside tags, then the instructions. Anthropic's guide describes putting inputs before the question as vital for good results with Claude 2.1.
Here are the documents you will use to answer questions:
<documents>
<document index="1">
<source>Riverside Community Garden rules, 2024 edition</source>
<document_content>
[paste the rules here]
</document_content>
</document>
<document index="2">
<source>2024 plot fees</source>
<document_content>
[paste the fee schedule here]
</document_content>
</document>
</documents>
You are the help desk assistant for Riverside Community Garden. You answer questions from members and people thinking of joining.
Rules:
- Answer only from the documents above. If they don't cover a question, say so and suggest emailing the garden coordinator.
- Never guess a fee, date or rule. Quote the relevant line from the documents in <quote> tags, then give your answer.
- Only discuss garden matters. Politely decline anything else.
- Write in a friendly, plain style, in under 120 words.And here is how you send it, using Anthropic's Python library and the Messages API as documented this week. The system prompt goes in the top-level system parameter; the Messages API has no "system" role inside the message list.
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
with open("garden_system_prompt.txt", encoding="utf-8") as f:
system_prompt = f.read()
message = client.messages.create(
model="claude-2.1",
max_tokens=500,
system=system_prompt,
messages=[
{"role": "user", "content": "Can I keep chickens on my plot?"}
],
)
print(message.content[0].text)
Each later turn adds to messages, alternating user and assistant, with the first one always from the user. The system prompt stays the same throughout.
Try it: Write a system prompt for a small job you know well, such as answering questions about your club's bylaws. Ask it five questions, including one the documents don't answer and one off-topic request. Adjust a rule each time Claude does something you didn't intend, and keep a copy of each version.
Testing and limits
Test the edges, not just the easy questions. Ask something the documents don't cover, ask it to break a rule, and ask a question phrased the way a rushed user would type it. Each failure tells you which line of the system prompt to sharpen.
Keep expectations realistic about secrecy. Anthropic is clear that a system prompt makes Claude more robust against misuse but doesn't make a prompt leak-proof. You can wrap private instructions in tags and tell Claude never to reveal them, which helps somewhat, but no method is guaranteed, and heavy-handed secrecy rules can make the rest of the task worse. Don't put anything in a system prompt that would cause real harm if a user saw it.
Why does Claude respond well to XML tags?
XML tags are labels in angle brackets, such as <document> and </document>, that mark where a piece of text starts and ends. They aren't code that runs; they're signposts. Claude works well with them for three practical reasons.
First, they remove ambiguity. A long prompt mixes instructions, reference material and the user's question. Tags make the boundaries explicit, so a sentence inside a document is less likely to be mistaken for an instruction from you. That matters for long inputs: Claude 2.1 can read up to 200,000 tokens, about 500 pages, and clear structure helps it keep track of what each part is.
Second, tags give you names to point at. Once the rules live in <documents>, you can write "answer only from the documents above," and both you and Claude know exactly what that means. Anthropic's own guide recommends a specific nested format for multiple documents, with <document index>, <source> and <document_content> tags, so each passage carries a label you can cite.
Third, tags make Claude's output easier to handle. Asking for the supporting line in <quote> tags, or a final answer in <answer> tags, lets your program pull out each part reliably, and lets you check at a glance whether the quoted rule actually supports the reply. Anthropic uses tags this way throughout its own examples, so structuring a prompt with them means working in the format Claude's makers recommend.
Sources
- How to use system prompts — Anthropic, November 21, 2023
- anthropic-sdk-python: README and message_create_params — Anthropic (GitHub), March 1, 2024
- Introducing Claude 2.1 — Anthropic, November 21, 2023