Beginner

Basic Prompt Structure

Understand exactly how Claude processes your messages. Master the four-component framework that underpins every effective prompt.

12 min read 8 examples Chapter 1 of 11

How Claude Reads Your Message

Every interaction with Claude follows a structured conversation format. Unlike a search engine that parses keywords, Claude processes entire conversational contexts — understanding role, intent, constraints, and desired output all at once.

The Claude API uses a turn-based message format: alternating Human and Assistant turns. Understanding this structure is the foundation of every other technique in this course.

💡
Key Mental Model
Think of Claude as an extremely capable colleague who needs complete context to do their best work. The more context you provide in the right structure, the better the output.

The Turn-Based Conversation Format

The Claude API separates messages into Human and Assistant turns. This maps directly to how you write prompts:

API Format (Python)
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Explain the difference between supervised and unsupervised learning."
        }
    ]
)

print(message.content[0].text)

The Four Components of a Great Prompt

Every high-quality prompt contains some combination of these four elements. Not all are required for every prompt, but knowing them lets you diagnose why a prompt isn't working.

🎯
1. Task
What you want Claude to do. Be explicit: "summarize", "classify", "write", "debug", "explain". The task should be the first thing Claude reads.
📋
2. Context
Background information Claude needs to do the task well. Who is the audience? What is the purpose? What constraints apply?
📄
3. Input Data
The actual content Claude should work with — a document, code snippet, list, or question. Keep this clearly separated from your instructions.
📐
4. Output Format
How you want the response structured — bullet points, JSON, a table, paragraph prose, or a specific template. Without this, Claude chooses for you.

System Prompts: Setting the Stage

The system prompt is a special instruction block that runs before the conversation starts. It's where you establish Claude's persona, define constraints, and provide standing instructions that apply to every turn.

System prompts are invisible to end users (in most implementations) but have the highest priority for shaping Claude's behavior.

System Prompt Example
client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    system="""You are a senior Python developer with 15 years of experience.
You specialize in clean, production-ready code.
Always explain your reasoning.
Format code examples with syntax highlighting.
If a request is ambiguous, ask one clarifying question.""",
    messages=[
        {"role": "user", "content": "How do I handle database connection pooling?"}
    ]
)

Before vs. After: Structured Prompts in Action

See the difference a structured prompt makes. Both prompts ask for the same thing — but the outputs are dramatically different.

Tell me about machine learning.
SYSTEM: You are a technical writer creating course material for software developers with no ML background. USER: Write a 150-word introduction to machine learning for software developers. Cover: what it is, why it matters, and one concrete example. Format: 3 short paragraphs. No jargon without explanation.
Machine learning (ML) is a branch of artificial intelligence where systems learn from data rather than following explicit rules. Instead of writing code that says "if email contains 'win a prize', mark as spam," you show the system thousands of labeled spam/ham emails and it learns the pattern itself. This matters to developers because ML is now embedded everywhere: search ranking, autocomplete, fraud detection, recommendation engines. As a software engineer, you'll increasingly integrate ML models into your applications via APIs even if you don't build them yourself. A concrete example: Netflix's recommendation system. Rather than hand-coding "show action movies to users who watched Die Hard," ML analyzes billions of watch patterns and discovers complex correlations you'd never think to program manually. The model improves as it sees more data.

Anatomy of a Complete Prompt

Here is a fully annotated prompt demonstrating all four components working together:

Complete Prompt Anatomy
# ROLE (sets expertise and tone)
You are a senior data scientist specializing in NLP.

# TASK (what to do — verb + object)
Classify the sentiment of the following customer reviews.

# CONTEXT (background that shapes the response)
These reviews are for a B2B SaaS product. "Neutral" means
the customer neither recommends nor discourages others.
Use the classifications for a stakeholder dashboard.

# INPUT DATA (the actual content to process)
Reviews:
1. "Onboarding took too long but the core features work."
2. "Transformed our entire reporting workflow. 10/10."
3. "Support team responded in 2 days. Expected faster."

# OUTPUT FORMAT (structure and schema)
Return a JSON array with objects containing:
- "id": review number
- "sentiment": "positive" | "neutral" | "negative"
- "confidence": 0.0 to 1.0
- "key_phrase": the most sentiment-bearing phrase

The Order of Components Matters

Claude reads prompts sequentially. Research and practice show that task-first ordering produces the most focused responses:

1
Start with the task
Lead with the verb and object: "Summarize...", "Classify...", "Write...", "Debug...". This primes Claude's attention on the right goal.
2
Add context and constraints
Who is the audience? What's the use case? Any hard constraints? This shapes tone, depth, and approach.
3
Provide your input data
Put the document, text, or data to be processed clearly after your instructions. Use delimiters to separate it.
4
Specify output format last
Describe the exact format you need. JSON? Markdown? A specific template? Format instructions work best as the final instruction.
Chapter 1 Takeaway
Every prompt has an implicit structure. Making it explicit — task, context, data, format — is the single highest-leverage change you can make to improve output quality. Before writing your next prompt, ask: which of the four components am I missing?

Practice Exercise

Take this weak prompt and rewrite it using all four components:

Original (Weak)
Explain neural networks.

Consider: Who is the audience? What depth? What format? What specific aspect? Try your rewrite in the Playground →