Claude Prompt Engineering: 15 Techniques That Actually Work
by Sandlabs Team, Founder, Sandlabs
Most teams using Claude are leaving 80% of its capability on the table. The difference between a mediocre claude prompt and a well-engineered one is not a marginal improvement — it is the difference between an AI that frustrates your team and one that replaces entire workflows.
We have built dozens of Claude-powered systems at Sandlabs — from multi-agent credit assessments to document processing pipelines. Every project taught us the same lesson: prompt engineering is the highest-leverage skill in AI development.
This guide covers 15 claude prompt engineering techniques we use in production, each with before-and-after examples so you can apply them immediately.
1. System Prompts
System prompts set the ground rules for every interaction. They tell Claude who it is, what it should do, and how it should behave — before the user says a word.
Before:
Summarise this document for me.
After:
System: You are a senior financial analyst at an Australian mortgage brokerage.
You summarise documents with precision, flag regulatory risks, and use
Australian English spelling. Keep summaries under 200 words.
User: Summarise this document for me.
System prompts persist across the entire conversation. Use them for tone, constraints, formatting rules, and domain context that should apply to every response.
2. Role Assignment
Beyond basic system prompts, assigning Claude a specific expert role dramatically improves output quality. Claude draws on deeper domain knowledge when it "thinks" as a specialist.
Before:
Review this contract clause.
After:
You are a property law solicitor with 15 years of experience in
Australian commercial leases. Review this contract clause. Identify risks
to the tenant, flag any non-standard terms, and suggest amendments using
plain language.
The more specific the role, the better. "Senior tax accountant specialising in Australian R&D tax incentives" outperforms "accountant" every time.
3. Chain-of-Thought Prompting
Claude performs significantly better on complex tasks when you ask it to reason step by step. This is especially powerful for calculations, logic problems, and multi-factor decisions.
Before:
Is this startup a good investment?
After:
Evaluate this startup as a potential investment. Think through your
analysis step by step:
1. Assess the market size and growth trajectory
2. Evaluate the team's relevant experience
3. Analyse unit economics and path to profitability
4. Identify the top 3 risks
5. Give a final recommendation with confidence level (low/medium/high)
Explicit reasoning steps reduce hallucination and produce more defensible outputs — critical when your team relies on Claude's analysis for real decisions.
4. Few-Shot Examples
Show Claude exactly what you want by providing examples of ideal input-output pairs. This is the single most effective technique for getting consistent formatting and tone.
Before:
Write a product description for this item.
After:
Write a product description following this style:
Example input: Wool beanie, navy blue, merino, made in Australia
Example output: "Stay warm without the itch. Our navy merino beanie is
spun from 100% Australian wool — breathable in autumn, essential in
winter. One size fits all."
Now write a description for: Leather wallet, tan, hand-stitched,
kangaroo leather, six card slots
Three examples is usually the sweet spot. More than five rarely improves results and wastes tokens.
5. Structured Output (JSON/XML)
When Claude feeds data into another system, you need predictable structure. Explicitly request JSON or XML and provide a schema.
Before:
Extract the key details from this invoice.
After:
Extract invoice details and return valid JSON matching this schema exactly:
{
"vendor_name": "string",
"invoice_number": "string",
"date": "YYYY-MM-DD",
"line_items": [
{
"description": "string",
"quantity": number,
"unit_price": number,
"gst_included": boolean
}
],
"total_amount": number,
"currency": "AUD"
}
Return ONLY the JSON object. No markdown, no explanation.
For complex nested data, XML tags can be even more reliable than JSON because Claude handles XML nesting natively. Use <output> tags to clearly delineate where structured data begins and ends.
6. Temperature Tuning
Temperature controls randomness. Lower values (0.0-0.3) produce consistent, deterministic outputs. Higher values (0.7-1.0) produce creative, varied responses.
Before (default temperature):
# Using default temperature for everything
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
messages=[{"role": "user", "content": prompt}]
)
After (tuned per task):
# Data extraction — deterministic
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
temperature=0.0,
messages=[{"role": "user", "content": extraction_prompt}]
)
# Marketing copy — creative
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
temperature=0.8,
messages=[{"role": "user", "content": copywriting_prompt}]
)
Rule of thumb: if there is one correct answer, use temperature 0. If you want variety, increase it. Never use high temperature for data extraction or classification.
7. Prefilling Claude's Response
You can start Claude's response with specific text, forcing it into a particular format or mode from the first token. This is an underused technique that eliminates preamble.
Before:
Return the sentiment of this review as JSON.
Claude responds: "Here's the sentiment analysis: json { ... } "
After:
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
messages=[
{"role": "user", "content": "Return the sentiment of this review as JSON."},
{"role": "assistant", "content": "{"}
]
)
Claude responds: {"sentiment": "positive", "confidence": 0.92}
Prefilling eliminates "Sure, here's..." preambles and guarantees your output starts exactly how you need it. Essential for building reliable claude ai tools and pipelines.
8. Extended Thinking
For complex reasoning tasks, Claude's extended thinking feature lets it work through problems in a dedicated thinking block before producing its final answer.
Before:
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
max_tokens=4096,
messages=[{"role": "user", "content": "Analyse these three competing proposals..."}]
)
After:
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
max_tokens=16000,
thinking={
"type": "enabled",
"budget_tokens": 10000
},
messages=[{"role": "user", "content": "Analyse these three competing proposals..."}]
)
Extended thinking is particularly effective for multi-step analysis, debugging complex code, and tasks where Claude needs to weigh trade-offs. The thinking budget controls how much reasoning Claude can do — larger budgets for harder problems.
9. Tool Use (Function Calling)
Tool use transforms Claude from a text generator into an agent that can take action — querying databases, calling APIs, sending emails, and updating records.
Before:
What is the current balance for customer ID 4521?
Claude guesses or says it cannot access live data.
After:
tools = [{
"name": "get_customer_balance",
"description": "Retrieve current account balance for a customer",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {"type": "string", "description": "The customer ID"}
},
"required": ["customer_id"]
}
}]
response = client.messages.create(
model="claude-sonnet-4-6-20260320",
tools=tools,
messages=[{"role": "user", "content": "What is the current balance for customer ID 4521?"}]
)
Claude will call get_customer_balance with {"customer_id": "4521"}, and you return the real data. This is the foundation of every production claude ai assistant — connecting language understanding to real business systems.
If you are exploring what is claude ai good for in a business context, tool use is the answer. It is what turns Claude from a chatbot into a workflow engine.
10. Context Window Management
Claude's context window is large but not infinite. Poor context management leads to degraded performance, missed information, and unnecessary cost.
Before:
Here is our entire 200-page policy manual. Now answer this question...
After:
Here is the relevant section from our policy manual (Section 4.2:
Leave Entitlements, pages 34-36):
[relevant excerpt only]
Based on this policy section, answer the following question...
Strategies that work in production: chunk large documents and retrieve only relevant sections (RAG), summarise previous conversation turns, and place the most important context closest to your question. Claude pays strongest attention to the beginning and end of the prompt.
11. Prompt Chaining
Break complex workflows into sequential steps where each prompt's output feeds the next. This produces dramatically better results than asking Claude to do everything at once.
Before:
Read this contract, extract key terms, identify risks, and draft a
summary memo for the client.
After:
# Step 1: Extract
extraction = call_claude("Extract all key terms, dates, and obligations
from this contract. Return as JSON.")
# Step 2: Analyse
risks = call_claude(f"Given these contract terms: {extraction}\n\n
Identify the top 5 risks to our client, ranked by severity.")
# Step 3: Draft
memo = call_claude(f"Draft a 300-word client memo summarising these
key terms: {extraction}\n\nAnd these identified risks: {risks}\n\n
Use plain language. Australian English.")
Each step gets Claude's full attention on a single task. Prompt chaining is how we build most production systems at Sandlabs — it is more reliable and easier to debug than monolithic prompts.
Struggling to get Claude working reliably for your business? At Sandlabs, we build production AI systems powered by Claude — from custom agents to full workflow automation. Fixed pricing, 2-6 week delivery. Start a conversation and tell us what you are trying to build.
12. Error Handling Prompts
Production systems need graceful failure. Tell Claude explicitly how to handle edge cases, ambiguity, and missing information instead of letting it guess.
Before:
Classify this support ticket.
After:
Classify this support ticket into exactly one category:
billing, technical, account, shipping, other.
Rules:
- If the ticket is ambiguous, classify as "other" and explain why
- If the ticket contains multiple issues, classify by the PRIMARY issue
- If the ticket is empty or contains only greetings, return:
{"category": "unclassifiable", "reason": "No actionable content"}
- Never invent a category outside the list above
Defensive prompting catches the edge cases that break automations at 2am. Every production prompt should define what Claude does when the input is unexpected.
13. Evaluation Prompts
Use Claude to evaluate Claude. Self-evaluation prompts create quality gates that catch errors before they reach users or downstream systems.
Before:
Write a response to this customer complaint.
After:
Step 1: Write a response to this customer complaint.
Step 2: Now evaluate your response against these criteria:
- Does it acknowledge the customer's frustration? (yes/no)
- Does it offer a concrete resolution? (yes/no)
- Is it under 150 words? (yes/no)
- Does it avoid admitting legal liability? (yes/no)
If any criterion is "no", rewrite the response to fix it.
Return only the final, passing version.
This self-check pattern catches 60-70% of quality issues without any additional infrastructure. For higher stakes, use a separate Claude call to evaluate the first one's output.
14. Multi-Turn Conversation Strategies
Long conversations degrade Claude's performance as context fills up. Smart multi-turn design keeps conversations sharp and on-track.
Before:
# Turn 15 of an unstructured conversation
User: And what about the other thing we discussed earlier?
After:
# Periodic context refresh
System: You are helping the user plan a product launch. Here is the
current state of the plan:
- Product: Mobile expense tracker for Australian SMEs
- Launch date: 15 May 2026
- Decided: Pricing at $29/month, targeting accountants first
- Open questions: Distribution channel, launch content strategy
Continue the conversation from this context.
Summarise and re-inject context every 8-10 turns. This keeps Claude grounded and prevents the "what did we discuss earlier?" problem that plagues long conversations.
15. Production Prompt Templates
Mature teams do not write prompts from scratch. They use version-controlled templates with variables, tested against evaluation datasets.
Before:
prompt = f"Summarise this: {document}"
After:
SUMMARISATION_TEMPLATE = """
<role>Senior {domain} analyst at an Australian consultancy</role>
<task>
Summarise the following document in {max_words} words or fewer.
Focus on: {focus_areas}
Audience: {audience}
</task>
<rules>
- Use Australian English spelling
- Include exactly {num_bullets} bullet points for key findings
- End with a single-sentence recommendation
- If the document is too short to summarise meaningfully, say so
</rules>
<document>
{document}
</document>
"""
prompt = SUMMARISATION_TEMPLATE.format(
domain="financial",
max_words=200,
focus_areas="revenue trends, risk factors, regulatory compliance",
audience="C-suite executives",
num_bullets=5,
document=document_text
)
Templates enforce consistency across your team, make prompts testable, and let you iterate on structure without rewriting from scratch. Store them alongside your code and version them like any other production asset.
Quick Reference: Choosing the Right Technique
| Task Type | Best Techniques | Temperature |
|---|---|---|
| Data extraction | Structured output, prefilling, error handling | 0.0 |
| Analysis / reasoning | Chain-of-thought, extended thinking, evaluation | 0.0-0.2 |
| Content generation | Role assignment, few-shot, templates | 0.5-0.8 |
| Workflow automation | Tool use, prompt chaining, error handling | 0.0 |
| Customer-facing chat | System prompts, multi-turn, evaluation | 0.3-0.5 |
Frequently Asked Questions
What is the best way to start learning Claude prompt engineering?
Start with system prompts and role assignment as they are the simplest techniques that deliver the largest improvement. Then add chain-of-thought for complex reasoning tasks. Build one working prompt for a real use case before moving to advanced techniques like tool use or prompt chaining. Practical application beats theory.
How do I get Claude to return consistent JSON every time?
Combine three techniques: provide an explicit JSON schema in your prompt, use prefilling to start Claude's response with an opening brace, and set temperature to 0. For production systems, add a JSON validation step after each response and retry with error feedback if parsing fails. This combination achieves near-100% reliability.
What is the difference between system prompts and role assignment?
System prompts are a dedicated message type that sets persistent rules for the entire conversation, covering things like formatting, language, and constraints. Role assignment is a technique within any prompt that tells Claude to adopt a specific expert persona. They work best together: system prompt for universal rules, role assignment for task-specific expertise.
How many tokens should I budget for extended thinking?
For straightforward analysis, 2,000-5,000 thinking tokens is sufficient. For complex multi-step reasoning like comparing proposals or debugging intricate code, use 8,000-15,000 tokens. Start with a moderate budget and increase only if output quality is lacking. Thinking tokens add to latency and cost, so right-size them to the task complexity.
Can I use these techniques with the Claude API and Claude desktop app?
System prompts, role assignment, chain-of-thought, few-shot examples, and structured output work everywhere including the desktop app and API. Temperature tuning, prefilling, extended thinking, and tool use require the API. Prompt chaining and production templates are code-level patterns you implement in your application layer on top of the API.
Start Building With Claude
Knowing these 15 techniques is the first step. The real value comes from combining them into production systems that run reliably, handle edge cases, and scale with your business.
At Sandlabs, we are an AI development studio based in Australia that builds Claude-powered solutions for businesses — custom agents, workflow automations, document processing pipelines, and more. Fixed pricing, 2-6 week delivery, and we handle the prompt engineering, infrastructure, and ongoing optimisation.
If you have a workflow that Claude could transform, get in touch. We will scope it, price it, and build it.