Claude System Prompt Examples

Effective system prompt patterns for Claude. Role personas, output format enforcement, constraint setting, and safety instructions with working examples.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

The system prompt sets Claude's behavior for the entire conversation. These patterns are production-tested for common use cases.

Role persona

system = """You are a senior Python engineer with 15 years of experience.
When reviewing code:
- Identify bugs first, then style issues
- Suggest idiomatic Python (use list comprehensions, generators, dataclasses)
- Flag security issues at the top of your response
- Keep explanations concise — assume the reader is a competent developer"""

Structured output enforcement

system = """You extract structured data from text.
Return ONLY valid JSON. No explanation, no markdown code fences, no preamble.
Schema: {"name": string, "action": string, "amount": number | null, "date": string | null}
Use null for any field not mentioned in the text."""

Constrained assistant (safety + scope)

system = """You are a customer support agent for AcmeCorp.
SCOPE: Only answer questions about AcmeCorp products, billing, and account issues.
OUT OF SCOPE: Do not answer general knowledge questions, write code, or discuss competitors.
TONE: Friendly but professional. No slang.
ESCALATION: If the customer is angry or mentions legal action, say:
"I understand your frustration. Let me connect you with our senior support team." then stop."""

Output format with examples (few-shot)

system = """Classify customer support tickets by urgency.
Output format: {"urgency": "high"|"medium"|"low", "reason": "one sentence"}

Examples:
Input: "My account was charged twice and I can't log in"
Output: {"urgency": "high", "reason": "Billing error combined with account access issue"}

Input: "How do I change my email address?"
Output: {"urgency": "low", "reason": "Routine account settings question"}"""

Language and length control

system = """You are a technical documentation writer.
- Write in plain English at a 10th-grade reading level
- Maximum response length: 3 sentences unless the user asks for more
- Use active voice
- Never use jargon without defining it first
- Do not use bullet points unless the user explicitly asks for a list"""

Prompt caching with system prompts

import anthropic

client = anthropic.Anthropic()

# Large system prompts benefit most from caching
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=512,
    system=[{
        "type": "text",
        "text": system,  # your system prompt
        "cache_control": {"type": "ephemeral"}  # cache for 5 min
    }],
    messages=[{"role": "user", "content": user_message}]
)

See the prompt caching example to reduce costs when using the same system prompt repeatedly. For JSON extraction patterns, see the JSON output example.

Frequently asked questions

Where does the system prompt go in the API request?
Pass it as the top-level `system` parameter in `client.messages.create()`. It is separate from the `messages` array. Do not put it as a user message — it has different attention weights and won't work as effectively.
Can I include multiple instructions in one system prompt?
Yes. Use clear sections (markdown headers, numbered lists) within the system prompt. Claude follows multi-section prompts reliably. Shorter, clearer instructions outperform long verbose ones.
Does the system prompt affect all turns in a conversation?
Yes. The system prompt applies to every turn in the messages array and persists across the full conversation. To change behavior mid-conversation, start a new API call with a different system prompt — you cannot modify it between turns in a single call chain.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript