Claude Prompting Cheat Sheet: Techniques, Templates, and API Basics
Introduction
Good prompts are clear, specific, and structured. This cheat sheet collects the techniques that work well with Claude, with copy-and-paste templates and the basic API call. Model names and features change, so check Anthropic's documentation for the current list.
Prerequisites
- Access to Claude through the chat app or the API
Step-by-Step Guide
Step 1: Anatomy of a strong prompt
Include the pieces that matter: the task, the context, the constraints, and the format you want. Say what the result is for, because purpose helps Claude make good choices. Treat Claude like a smart new colleague who has none of your background.
Task: what you want done, in one clear sentence
Context: who it is for, why it matters, relevant background
Input: the text, data, or code to work on (clearly separated)
Constraints: length, tone, things to include or avoid
Format: how the answer should look (bullets, table, JSON, code)Step 2: Be clear and direct
State what to do rather than only what to avoid, and give the level of detail you expect. Vague prompts get generic answers.
Weak: "Write something about our product."
Better: "Write a 120-word product description for our standing desk for
remote workers. Friendly tone, mention the 5-year warranty,
no exaggerated claims."
Weak: "Don't be wordy."
Better: "Answer in three short bullet points."Step 3: Separate parts with XML tags
Tags such as document, instructions, and example keep long prompts unambiguous. Use consistent tag names and refer to them in your instructions.
<instructions>
Summarize the document in 3 bullet points for a busy manager.
</instructions>
<document>
...paste the text here...
</document>
<format>
Return only the bullets, no preamble.
</format>Step 4: Show examples
Two or three examples of the input and the output you want teach format and tone better than a long description. Include varied cases, and wrap them in tags.
Classify each message as billing, technical, or other.
<example>
Message: I was charged twice this month.
Category: billing
</example>
<example>
Message: The app crashes when I upload a photo.
Category: technical
</example>
Message: How do I change my profile picture?
Category:Step 5: Give Claude a role and room to think
A system prompt can set a role and audience. For problems that need reasoning, ask Claude to work through the problem step by step before answering, and keep the final answer separate. On models that support extended or adaptive thinking you can enable it in the API instead of asking in the prompt.
System: You are a senior data analyst. Explain results to non-technical
managers in plain language.
Think through the problem step by step in <thinking> tags, then give
your final answer in <answer> tags.Step 6: Work with long documents and control the output
Put long documents near the top of the prompt and your question at the end. Ask Claude to quote the relevant passages first when accuracy matters. Specify the output format exactly, and tell Claude to say when it does not know instead of guessing.
<documents>
<document index="1"><source>handbook.pdf</source>...text...</document>
</documents>
First quote the sentences that answer the question, then answer using
only those quotes. If the documents do not contain the answer, say
"I could not find this in the documents."
Question: How many vacation days do new employees get?
Return JSON only, with the keys "summary" (string) and "risks" (array of strings).Step 7: Reusable prompt templates
Fill in the bracketed parts. Keep your own library of templates for tasks you repeat.
Summarize: Summarize the text below in [N] bullets for [audience]. Keep
numbers and names exact. <text>...</text>
Extract: Extract [fields] from the text and return JSON with exactly
those keys. Use null when a value is missing. <text>...</text>
Review: Review this code for bugs, security issues, and unclear naming.
List issues by severity, each with a suggested fix. <code>...</code>
Rewrite: Rewrite the text for [audience] in a [tone] tone, about [N] words.
Keep all facts unchanged. <text>...</text>
Plan: Ask me up to 3 clarifying questions, then propose a step-by-step
plan for [goal] with time estimates.Step 8: Call Claude from Python
Install the anthropic package and set ANTHROPIC_API_KEY in your environment. Put instructions in system and the conversation in messages, and set max_tokens generously.
# pip install anthropic
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=2000,
system="You are a concise technical writer.",
messages=[
{"role": "user", "content": "Explain what an API key is in two sentences."}
],
)
print(message.content[0].text)FAQs
- How do I stop Claude from making things up?
- Give it the source material, ask it to answer only from that material and to quote supporting text, and explicitly allow it to say it does not know. Verify important facts yourself.
- Do I need special magic phrases?
- No. Clear instructions, good context, examples, and a defined output format matter far more than any trick phrase. Test and refine your prompt with real inputs.
Summary
Be specific about task, context, and format, separate inputs with XML tags, show examples, set a role, put long documents first, control the output format, and keep a template library.
Related tutorials
- Linux Command Line Cheat Sheet: Files, Permissions, Processes, and Networking
- Docker and kubectl Cheat Sheet: Containers, Images, Compose, and Kubernetes
- SQL Cheat Sheet: SELECT, Joins, Aggregates, and Data Changes
- Git Cheat Sheet: Everyday Commands, Branching, and Undoing Mistakes
- Langflow Cheat Sheet: Install, Components, API Calls, and Custom Components
Comments
Log in or create a free account to join the discussion.