Beyond basic instructions: reasoning elicitation, few-shot calibration, system prompt architecture, and pipeline decomposition.
Chain-of-thought (CoT) prompting asks the model to reason step by step before giving its final answer. Research consistently shows this improves accuracy on arithmetic, logic, and multi-step problems.
The simplest trigger phrase: "Let's think step by step." — but explicit step structures work even better.
prompt = """Solve the following problem step by step, showing your reasoning.
After reasoning, state your final answer on a new line starting with "Answer:".
Problem: A store has 240 apples. They sell 3/8 of them in the morning and
1/4 of the remainder in the afternoon. How many apples are left?
Let's think step by step:"""
Why it works: generating intermediate tokens forces the model to allocate computation to the problem rather than jumping to a plausible-sounding answer. The reasoning trace acts as scratchpad space.
Providing example input → output pairs inside the prompt calibrates the model's response format, tone, and reasoning style without any fine-tuning.
Classify the sentiment of customer reviews as POSITIVE, NEUTRAL, or NEGATIVE.
Review: "Delivery was lightning fast and the product exceeded expectations!"
Sentiment: POSITIVE
Review: "It works fine. Nothing special."
Sentiment: NEUTRAL
Review: "Arrived broken and customer service was unhelpful."
Sentiment: NEGATIVE
Review: "{{USER_REVIEW}}"
Sentiment:
The system prompt is your persistent configuration layer. It scopes every turn of the conversation and is prepended before the user's first message.
You are a senior code reviewer specialising in Python and security.
Your job is to review code snippets for bugs, security vulnerabilities, and style issues.
Rules:
- Always list issues by severity: Critical → High → Medium → Low
- Suggest a concrete fix for every issue you raise
- Do not comment on correct code; only flag problems
- If the code is safe and idiomatic, respond only: "LGTM — no issues found."
Claude is trained to pay special attention to XML-like tags. Using them creates unambiguous structure that separates instructions, data, and expected outputs.
<document> wrapperprompt = """<instructions>
Extract all action items from the meeting notes below.
Return them as a JSON array of objects with fields: owner, action, due_date.
If a field is not mentioned, use null.
</instructions>
<document>
{meeting_notes}
</document>
<output>
"""
# Claude will fill in and close the output tag
Pro tip: asking Claude to begin its response with an opening tag (like <output>) ensures it follows the structure rather than adding preamble text.
Complex tasks rarely fit in one prompt. Prompt chaining breaks them into sequential steps where each output feeds the next — improving reliability and making each step independently testable.
def chain_summarise_then_classify(document: str) -> dict:
# Step 1: summarise
summary = client.messages.create(
model="claude-haiku-4-5", max_tokens=300,
messages=[{"role": "user", "content":
f"Summarise in 3 sentences:\n\n{document}"}]
).content[0].text
# Step 2: classify the summary
label = client.messages.create(
model="claude-haiku-4-5", max_tokens=20,
messages=[{"role": "user", "content":
f"Classify as SPORTS/POLITICS/TECH/OTHER:\n\n{summary}"}]
).content[0].text.strip()
return {"summary": summary, "label": label}
Live examples showing CoT reasoning and XML extraction.