Prompt Engineering — Intermédio
Chapter 4: Separating Data from Instructions
As prompts grow complex, Claude needs to distinguish between what you're telling it to do (instructions) and what you're giving it to work with (data). Without clear separation, confusion follows — especially with long documents or user-generated content.
The Problem: If your instructions say "Summarize the following text" and the text itself contains phrases that look like instructions, Claude may get confused about what to do.
XML Tags: The Solution
Claude is specifically trained to recognize XML tags. They eliminate ambiguity about where one section ends and another begins. Use <instructions> for the task and <customer_review> (or <document>) for the content. Even if the content contained phrases like "analyze this" or "return JSON," Claude wouldn't be confused — it knows instructions live in <instructions>.
Standard Tag Vocabulary
- <instructions> — The task Claude needs to perform
- <context> — Background information
- <document> — Content to work with
- <example> / <examples> — Demonstrations of desired output
- <input> — Variable data (user query, etc.)
- <output_format> — How to structure the response
- <constraints> — Rules and limitations
Nested Structure for Multiple Documents
Wrap multiple documents in <documents>, each in <document index="1"> with <source> and <document_content>. Put <instructions> after the documents. Example: Compare the two reports and identify the top 3 trends.
Long Context Best Practices
- Put long documents first in your prompt.
- Put instructions and questions last.
- Ask Claude to quote relevant passages before answering — cuts through noise and reduces hallucination.
Example instructions: First, quote any clauses that mention payment terms. Then, summarize the payment structure in plain English.
Chapter 5: Formatting Output & Speaking for Claude
Specify Format Explicitly
Claude produces output in any format you need — JSON, markdown, HTML, tables, plain text, code — but you have to ask. Method 1: Direct instruction — e.g. "Return a JSON object with keys: sentiment, complaints, improvements". Method 2: XML format tags — e.g. "Wrap your response in <answer> tags and your reasoning in <reasoning> tags". Method 3: Provide a template — show Claude the exact structure you want filled in.
What Actually Works
Tell Claude what to DO, not what to avoid. LESS RELIABLE: "Do not use markdown in your response." MORE RELIABLE: "Write your response as smooth flowing prose paragraphs only. Do not use bullet points, headers, or bold text." Match your prompt style to your desired output style.
Controlling Verbosity
Claude 4.6 models default to concise, direct responses. MORE DETAIL: "Provide a comprehensive analysis. Include rationale for each point, edge cases, and potential counterarguments." LESS DETAIL: "Be extremely concise. One sentence per point. Skip all preamble and summary."
Eliminating Preambles (Claude 4.6)
- "Skip any introduction. Start directly with [the content]."
- "Begin your response with the JSON object. Nothing before it."
- "Do not summarize what you're about to do. Just do it."
Common Format Templates
JSON: Return a JSON object only. No prose, no markdown code fences. Schema: {"sentiment": string, "score": number, "tags": array}. Table: Format as a markdown table with columns e.g. Feature | Ours | Competitor A | Competitor B. Structured sections: Use exactly these sections in this order — SUMMARY (2–3 sentences), KEY FINDINGS (bullet points), RECOMMENDATION (1 paragraph), NEXT STEPS (numbered list).
Chapter 6: Precognition (Thinking Step by Step)
Asking Claude to reason through a problem before answering is one of the most reliable quality improvements. It avoids jumping to a plausible-sounding answer without working through the logic.
When to Use It
- Use step-by-step for: Math and logic problems; multi-step analysis (business decisions, contracts, tradeoffs); tasks with multiple interpretations; when you need to audit the reasoning; complex debugging.
- Skip it for: Simple factual questions; creative writing; speed-critical tasks.
How to Prompt for It
- Pattern 1 — Simple: "Think through this step by step before answering."
- Pattern 2 — Structured: "Before your final answer: 1. List all relevant facts from the input. 2. Identify any assumptions you're making. 3. Work through the logic. 4. State your conclusion."
- Pattern 3 — Tagged: "Put your reasoning in <thinking> tags. Put your final answer in <answer> tags."
Claude 4.6 Adaptive Thinking (API)
Claude Opus 4.6 has built-in adaptive thinking. For deep thinking: thinking={"type": "adaptive"}, output_config={"effort": "high"} or "max". For fast responses: output_config={"effort": "low"}.
Self-Verification
After completing your analysis, verify: Does your answer directly address what was asked? Are all factual claims supported by the provided text? Did you make any unwarranted assumptions? Correct any issues before finishing. Note: When extended thinking is disabled, Claude Opus 4.5 can be sensitive to the word "think." Use "consider," "evaluate," or "reason through" as alternatives.
Chapter 7: Using Examples
Few-shot (or multishot) prompting — providing examples of desired output — is one of the most reliable accuracy boosters. It shows Claude what you want instead of just telling it. Anthropic finding: A few well-crafted examples can dramatically improve accuracy and consistency — often more reliably than detailed written instructions.
Structure
Always wrap examples in XML tags: <examples> with multiple <example> blocks, each with <input> and <output>. End with <input>{{CUSTOMER_REVIEW}}</input> (or your variable) for the actual task.
Properties of Good Examples
- Relevant: Mirror your actual use case, not generic scenarios.
- Diverse: Cover edge cases and different scenarios — not just the easy ones.
- Consistent: Identical format and structure across all examples.
- 3–5 examples: The sweet spot between coverage and prompt length.
Common Mistakes
- Only easy examples → Include messy, ambiguous edge cases.
- All examples look the same → Vary inputs enough to teach the pattern.
- Inconsistent output format → Keep format identical across all examples.
- Too few examples (1–2) → Use 3–5 minimum.
- Missing actual task after examples → Always end with the real input to process.
Examples with Reasoning
For complex tasks, include <thinking> in your examples to show Claude how to reason. Meta-tip: Ask Claude to evaluate your examples: "Are these diverse enough? Do they cover the important edge cases? Suggest 2 additional examples I should add."
Perguntas frequentes
- Why use XML tags instead of plain sections?
- Claude is trained to recognize XML tags, so it clearly separates instructions from data. If user content contains phrases that look like commands, tags prevent confusion.
- When should I ask Claude to think step by step?
- Use it for math, logic, multi-step analysis, ambiguous tasks, and when you need to audit reasoning. Skip it for simple facts, creative writing, or when speed is critical.
- How many examples should I provide?
- 3–5 examples is the sweet spot. Make them diverse (including edge cases), relevant to your use case, and consistent in format. Always include the actual input to process after the examples.