Skip to content

Advanced Prompt Engineering

Techniques that double quality when the case is hard. Chain of Thought, XML Tags, prefill, extended role.

9 min · Intermediate · 2 of 2

TL;DR

Five techniques that turn any amateur prompt into a senior one: XML tags · Few-shot · Chain of Thought · Prefill · Extended role. Combined, they double response quality.

1 · XML Tags — structure Claude understands

Anthropic specifically trained Claude to understand XML markup. It’s not optional for complex prompts — it’s what keeps the AI from confusing context, task, and format.

Anti-pattern (everything loose)

Analyze this spreadsheet. Style: executive report. Find 3 patterns.
Company is a dental clinic with R$ 380 ticket. Focus on churn.

Claude tries to guess what’s data, what’s task, what’s tone. Gets half wrong.

Correct pattern

<context>
Company: dental clinic
Average ticket: R$ 380/month
Analysis focus: churn
</context>

<data>
[attached spreadsheet]
</data>

<task>
Find 3 patterns that explain churn over the last 90 days.
</task>

<format>
Executive report, 1 page, in PT-BR.
</format>

Result: more predictable responses, less rambling, consistent format.

Useful tags for founders

  • <context> — who the company is, key numbers, constraints
  • <data> — the numbers, spreadsheets, documents
  • <task> — what to ask, clear action verb
  • <format> — how to deliver
  • <example> — reference input/output
  • <constraints> — what NOT to do
  • <persona> — who Claude is being

2 · Few-shot — teach by example

When describing a pattern is hard, show the pattern. Few-shot is giving 2-3 examples before the real task.

Practical example: standardizing customer responses

You are a Customer Success manager. Reply to customer emails following
exactly the style of the examples below.

<example>
Customer: "I find the product expensive for what it delivers."
Response: "I get it. Can you tell me which features you expected to have on the current plan? I want to understand if it's pricing or if we still haven't unlocked value for you."
</example>

<example>
Customer: "I want to cancel."
Response: "Before canceling, in 3 minutes can I show you exactly what you used this month? Maybe there's a feature that solves what's missing — or maybe canceling is the right call. You decide afterwards."
</example>

Now respond:
Customer: "[new email here]"

Result: Claude follows tone, structure, and exact pattern, without you having to describe it in prose.

3 · Chain of Thought — think before answering

Magic phrase:

“Think step by step before answering. Show your reasoning. Only then give the conclusion.”

Significantly reduces logical errors on problems that involve:

  • Multi-step financial calculations
  • Diagnosis that depends on cross-referencing variables
  • Decisions with multiple trade-offs

Advanced variation: scratchpad thinking

Before the final response, use the <scratchpad> tag to list:
1. Which variables I need to consider
2. Which hypotheses I'm discarding and why
3. The logical order of the reasoning

Then, give the final answer in <response>.

You can ask it to hide the scratchpad if you only want the clean response.

4 · Prefill — force the format

Useful when you need the response to come out in an exact format. You “start the response” in its place.

Case 1: force pure JSON

Without prefill:

“Here is your response in JSON: json\n{...}\n

With prefill (in the API, the messages parameter ends with role assistant):

{ "role": "assistant", "content": "{" }

Claude continues the response from {. Clean JSON with no preamble.

Case 2: force a direct opening

Skip the intro. Start your response directly with "RECOMMENDATION:".

Works in claude.ai too. Shortcut to avoid “Sure, I can help you with that…“

5 · Extended role — it’s not just “you are an analyst”

Basic role:

“You are a sales analyst.”

Extended role:

You are a Head of Sales with 15 years in Brazilian B2B SaaS, average ticket
R$ 5k/month. You've sold at companies of 5 to 50 reps. Your obsession is
ticket dropping due to excessive discounting. You read funnels with a magnifying glass.

Difference: the AI takes on the language, priorities, and biases of the detailed role. It will mention margin where another would only mention volume.

When to combine (and the multiplier effect)

Maximum prompt for complex analysis of a real company:

<persona>
You are a senior CFO with 12 years in Brazilian SaaS Series A/B.
Were CFO at a company that grew 8x in 3 years. Your trademark is detecting
revenue leak before others and cutting cost with surgery, not an axe.
</persona>

<context>
Company: SaaS for dental clinic management
Stage: Series A, 14M ARR
Team: 38 people
Cash: R$ 12M
Burn: R$ 1.4M/month
Growing 6% MoM but churn went from 2.1% to 3.8%
</context>

<data>
[P&L spreadsheet + churn spreadsheet]
</data>

<task>
1. In <scratchpad>, list every variable considered and which you cut from the analysis.
2. In <diagnosis>, give the real picture (not what the CEO wants to hear).
3. In <action_30_days>, recommend 3 moves with R$ impact.
4. In <risk>, point out what could go wrong with each move.
</task>

<format>
Response in XML as above. Use markdown tables where it makes sense.
</format>

<example>
For tone inspiration (use the style, not the content):
"Churn isn't rising due to price — it's rising because monthly subscribers
of < 6 months represent 70% of cancellations. Onboarding is bleeding."
</example>

Think in steps before answering. Show reasoning.

This prompt extracts from Claude the kind of analysis a senior analyst would take 2-3 days to produce.

When to use what — table

TechniqueUse whenWatch out
XML TagsPrompt > 200 wordsNot necessary for simple questions
Few-shotVisual pattern hard to describeDon’t use a biased example
Chain of ThoughtCalculation, multi-variable decisionIncreases tokens (and cost)
PrefillNeed exact format (JSON, code)Only works in the API, not the chat
Extended roleDomain-specific analysisDon’t invent credentials that bias things badly

Next step

Apply everything in the prompt library — you can read how each one uses these techniques.

Or see how to build a custom Skill to automate the use of these prompts.

Entrega da lição
12 min

Tarefa

Take a real problem from your business (pending decision, complex analysis). Write the prompt using XML tags + ask for explicit Chain of Thought ('show reasoning before the conclusion'). Paste the prompt + Claude's output.

Como saber que entregou

Prompt uses at least 2 different XML tags. Output shows step-by-step reasoning separated from the final conclusion.

Auto-validável · você sabe se entregou
Compartilhar resultado ↗
Fontes oficiais