In Part 1, we learned that LLMs are probability engines predicting the next token. In Part 2, we learned how to steer those probabilities through word choice, structure, and persona.
Now the practical question: how do you get an LLM to handle problems that one quick answer can't solve?
You can't make the model smarter. But you can change what it has in front of it when it writes the answer: more tokens of intermediate work, a different order of information, outside facts, or tighter constraints. Every technique in this post is one of those four moves.
The internet is full of "top 10 prompt techniques" lists. This post is not that. For each technique I'll explain the mechanism, when it helps, and what it costs, so you can decide whether it fits your problem.
A note on evidence. Each technique links to the paper it comes from, and any numbers are the ones that paper reports, on its own benchmarks and models. Results change from model to model, and several of these techniques matter less on the newer reasoning models (see the last section). Treat each one as a hypothesis to test on your own task. Part 5 covers how.
Before You Pick a Technique: What Is Actually Failing?
Most people skip this step and throw every technique at the prompt. Ask first:
- Reasoning? The model can't carry a multi-step problem to the right answer.
- Missing information? The answer depends on facts the model doesn't have (live data, your private data).
- Missed details? The answer is in the input, but the model overlooks it.
- Format or style? The content is fine, but the shape of the output is wrong.
- Hallucination? The model invents things when it should say it doesn't know.
- Sameness? You ask for five ideas and get the same idea five times.
Each failure has a different fix. A useful habit when writing any prompt: read it left to right, once, the way the model does, and ask what the next token would be at each point. The model has no way to ask you a clarifying question; everything it knows about your task is on the page.
The Core Problem: One Pass Is Not Much Thinking
Question → [single forward pass per token] → Answer Remember from Part 1 that the model produces one token at a time. If the answer to a hard problem has to come out in the first few tokens, the model has done very little computation to get there. Most techniques below work by letting the model write intermediate tokens first, so the final answer is conditioned on work already on the page.
Technique 1: Chain of Thought (CoT)
Source: Wei et al., 2022.
The problem
A cafeteria has 12 apples. They use 3 apples to make pies and then buy 0 more apples. How many apples are left?
If the model has to commit to a number immediately, it can compress the whole problem into one guess and get it wrong.
Why it works
When you ask for step-by-step reasoning, the model generates intermediate tokens, and those tokens become part of the context for everything that follows:
Step 1: Input → predicts "Start with 12 apples" Step 2: Input + Step 1 → predicts "Use 3, leaves 9" Step 3: Input + Steps 1-2 → predicts "Buy 0, still 9" Step 4: Input + all steps → predicts "Answer: 9" Each later step can lean on earlier written steps instead of recomputing everything internally. It's not a guarantee of correctness: a wrong step also stays in the context and can mislead the steps after it. That is why self-consistency (sample several chains, take the majority answer) helps on top of CoT.
How to use it
<problem> A cafeteria has 12 apples. They use 3 apples to make pies and then buy 0 more apples. How many apples are left? </problem> Work through this step by step, then give the final answer on its own line. When it helps, and the cost
- Helps: multi-step math, logic, debugging, anything where intermediate results matter.
- Costs: more output tokens and more latency. For "What is 2+2?" it is pure waste.
Technique 2: Chain of Draft (CoD)
Source: Xu et al., 2025.
The problem
CoT is verbose. Across thousands of calls, those reasoning tokens add up in cost and latency.
How it works
Humans don't write essays when they solve a problem; they jot down the essentials. CoD asks the model to do the same: a minimal draft per step, five words at most.
<problem> A cafeteria has 12 apples. They use 3 apples to make pies and then buy 0 more apples. How many apples are left? </problem> Think step by step, but only keep a minimum draft for each thinking step, with 5 words at most. Return the final answer after ####. Expected shape of the output:
Start: 12 apples. Used 3: 9 left. Bought 0: still 9. #### 9 What the paper reports
The authors report that CoD matches or surpasses CoT in accuracy on the tasks they tested, using as little as 7.6% of the tokens. That is a best case, not a promise. On your task and your model the gap could be different, so measure before you rely on it. Short drafts may work worse on smaller models, since the model has less room to "show" the work that the drafts compress away.
Technique 3: Self-Critique (Reflection)
Related work: Reflexion and Large Language Models Cannot Self-Correct Reasoning Yet.
The idea
After producing an answer, the model is asked to critique it and fix it:
Input → Draft answer → Critique ("what's wrong with this?") → Revised answer Mechanically it's the same trick as CoT: the critique is more tokens on the page, and the revised answer is conditioned on them.
The catch: self-critique alone is weak
The second paper above tests exactly this and finds that, for reasoning tasks, LLMs struggle to correct themselves without external feedback, and sometimes get worse after "correcting." In practice you will see this as a reflection step that confidently says "I checked, this is correct" about a wrong answer.
So the useful version is not "are you sure?" It's reflection that has something to check against:
- test or compiler output
- a tool result
- the source document
- an explicit rubric
def add(a, b):
return a + b + c
<test_output> NameError: name 'c' is not defined </test_output> Explain why the test failed, then fix the function. A second option is a separate critic call with a fresh context, so the critic isn't anchored on the first answer.
Cost
Roughly double the tokens and an extra round trip. Use it where mistakes are expensive, and give it a real signal to check against.
Technique 4: ReAct (Reasoning + Acting)
Source: Yao et al., 2022.
The problem
A model can only work with what is in its context. "What's Tesla's stock price right now?" can't be answered from training data. It needs to look something up.
How it works
ReAct puts the model in a loop with the outside world:
Thought → Action → Observation → Thought → Action → ... → Final Answer - Thought: the model reasons about what it needs.
- Action: it asks for a tool call (search, calculator, database).
- Observation: your code runs the tool and puts the result back into the context.
- Repeat until the model can answer.
The original paper did this with a text format. Modern APIs have native tool calling, which is the same idea with a structured format: the model returns a tool_use block, your code runs the tool, and you send the result back.
A working loop
The loop is the important part. If you call the API once and print the text, no tool ever runs.
import ast import operator import anthropic client = anthropic.Anthropic() MODEL = "your-model-name" # use whichever current model you have access to MAX_STEPS = 5 SYSTEM = "Use the tools when you need facts or arithmetic. Do not guess numbers." TOOLS = [ { "name": "search_web", "description": "Search the web and return a short text summary.", "input_schema": { "type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"], }, }, { "name": "calculate", "description": "Evaluate an arithmetic expression such as '84 / 68'.", "input_schema": { "type": "object", "properties": {"expression": {"type": "string"}}, "required": ["expression"], }, }, ] _OPS = {ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.truediv} def calculate(expression: str) -> str: def ev(node): if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)): return node.value if isinstance(node, ast.BinOp) and type(node.op) in _OPS: return _OPS[type(node.op)](ev(node.left), ev(node.right)) raise ValueError("unsupported expression") return str(ev(ast.parse(expression, mode="eval").body)) def search_web(query: str) -> str: # Mock data for the demo. Replace with a real search API. return "Germany: about 84 million people. France: about 68 million people. (mock data)" def run_tool(name: str, args: dict) -> str: try: if name == "calculate": return calculate(args["expression"]) if name == "search_web": return search_web(args["query"]) return f"Unknown tool: {name}" except Exception as e: # return errors to the model so it can recover return f"Tool error: {e}" messages = [{ "role": "user", "content": "How many times larger is Germany's population than France's?", }] for _ in range(MAX_STEPS): response = client.messages.create( model=MODEL, max_tokens=1024, system=SYSTEM, tools=TOOLS, messages=messages ) if response.stop_reason != "tool_use": break messages.append({"role": "assistant", "content": response.content}) results = [ {"type": "tool_result", "tool_use_id": b.id, "content": run_tool(b.name, b.input)} for b in response.content if b.type == "tool_use" ] messages.append({"role": "user", "content": results}) else: print("Stopped: too many tool steps.") print("".join(b.text for b in response.content if b.type == "text")) Notice what is not the prompt: the step limit, the error handling, the tool schemas, the loop. That is code around the model, and it decides whether the technique works at all. We'll come back to this idea in Part 6.
When it helps, and the cost
- Helps: live data, private data, calculations, anything that needs a lookup or an action.
- Costs: one API call per loop step, so latency and cost grow with the number of tool calls. Results also depend heavily on the quality of your tools and their descriptions.
Technique 5: Tree of Thoughts (ToT)
Source: Yao et al., 2023.
The problem
CoT follows one path. If the first step is wrong, the whole chain can fail. Some problems (puzzles, planning, design) need you to try several paths and abandon the dead ends.
How it really works
Real ToT is not a single prompt. It's a search procedure that calls the model several times:
def tree_of_thoughts(problem, breadth=3, depth=3, keep=2): frontier = [""] # partial solutions for _ in range(depth): candidates = [] for state in frontier: candidates += propose_next_steps(problem, state, n=breadth) # LLM call scored = [(evaluate(problem, c), c) for c in candidates] # LLM call frontier = [c for _, c in sorted(scored, reverse=True)[:keep]] return best(frontier) At each level the model proposes several possible next steps, a model call scores them, and you keep the best few. It's a breadth-first search where the model is both the generator and the judge.
The single-prompt approximation
Many people write a one-prompt version: ask for several approaches, score them, then pick one. It's cheap and often useful for design questions, but it's a simplification. The model scores its own options in the same pass, with no real search:
<problem> Design a system to detect fraudulent transactions in real time. Requirements: catch 95% of fraud, under 100ms latency, under 1% false positives. </problem> 1. Propose at least 3 distinct approaches. 2. For each, list strengths and weaknesses against the requirements. 3. Choose one and explain why it beats the others. 4. Then describe how to implement the chosen approach. When it helps, and the cost
- Helps: problems with several plausible routes and checkable intermediate states.
- Costs: the full algorithm uses many calls per question. Use it only where the value of getting it right justifies that.
Technique 6: Re-Reading (RE2)
Source: Xu et al., 2023.
The problem
Decoder-only models read left to right. While the model processes the early tokens of your question, it cannot yet "see" the later ones.
How it works
RE2 repeats the question in the prompt:
Q: {question} Read the question again: {question} A: Let's think step by step. On the second copy, every token can attend to the full first copy. The paper describes this as giving a unidirectional model a kind of "bidirectional" view of the question. It reports consistent improvements across 14 datasets, with a few exceptions on vanilla ChatGPT, and it stacks with CoT.
It's cheap: you pay for the extra copy of the question as input tokens.
Related problem: long inputs
Re-reading the question is different from "make sure the model remembers the document." For long inputs, the research that matters is Lost in the Middle: models tend to use information at the beginning and end of a long context better than information buried in the middle. Practical consequences:
- Put the important things at the start or the end. Instructions and constraints belong in one of those two places, not in the middle of 20 pages of text.
- Put long documents above the question, and the question after them.
- Ask for quotes first. For document Q&A, ask the model to extract the relevant quotes, then answer from those quotes. The model first copies the relevant text into recent context, then reasons over it.
Counting letters is a different problem
"How many r's are in strawberry?" isn't a re-reading problem. It's a tokenization problem (see Part 1): the model sees tokens, not letters. The fix is to make the letters visible:
Spell "strawberry" one letter at a time, separated by hyphens and numbered. Then count the r's. Technique 7: CO-STAR
CO-STAR is a prompt-structure checklist popularised by Sheila Teo, who used it to win GovTech Singapore's GPT-4 prompt engineering competition.
| Letter | Meaning | The question it answers |
|---|---|---|
| C | Context | What background does the model need? |
| O | Objective | What exactly should it do? |
| S | Style | What writing style? |
| T | Tone | What attitude? |
| A | Audience | Who is it for? |
| R | Response | What format should the output take? |
Why it helps
The model doesn't care about the letters or the headings. It helps you: it stops you from leaving things unspecified, and every unspecified thing is something the model fills in with whatever is most probable. That's the same lesson as Part 2's "vague label vs. definition."
# CONTEXT I'm building an educational platform that teaches machine learning to beginners. # OBJECTIVE Write the introduction for a post titled "How Neural Networks Learn". # STYLE Clear and analogical: explain with real-world comparisons. # TONE Friendly and encouraging. Avoid intimidating jargon. # AUDIENCE People with no machine learning background. # RESPONSE 2-3 paragraphs of markdown, opening with an engaging first sentence. Cost
A longer prompt. For simple queries it's overkill. For anything you'll reuse or hand to a teammate, it pays for itself in fewer retries.
Technique 8: Few-Shot Examples
The problem
Vague tasks give inconsistent output. "Summarize this" doesn't say how long, how formal, or what to keep.
How it works
Examples don't teach the model new facts. They show it the shape of a good answer: format, length, style. It infers the pattern and continues it.
<examples> <example> <input>The global economy entered recession in Q3 2024</input> <summary>Economic downturn started Q3 2024</summary> </example> <example> <input>New AI regulations in the EU require transparency in model training data</input> <summary>EU mandates AI training-data transparency</summary> </example> </examples> Summarize in the same style: <input>Tesla's new plant increased capacity by 40% while cutting costs</input> The trap: examples pull the output toward themselves
The model copies what it sees. If every example has the same length, opening, and structure, the outputs will too, which makes responses more generic and more like your examples than like the task.
- Use a small set (a handful, not dozens).
- Make them different from each other in length, topic, and structure, so the shared pattern is the thing you actually want.
- Include at least one awkward or edge-case example if edge cases matter.
- Check that your examples aren't leaking their content ("Tesla" appearing in an unrelated summary is a sign).
Technique 9: Telling the Model What to Do When It Doesn't Know
The problem
Ask "Can your product sync with Notion?" and give no information about Notion. The most likely continuation of a helpful-assistant answer is a confident "yes" or a confident invented detail.
What to do
"Don't make things up" is a weak instruction on its own: it names the behavior but doesn't give the model anything else to say. Instead, give it a valid way out, a specific thing to do in the "I don't know" case:
You answer questions about our product using only the <context> below. If the answer is not in the context, reply exactly: "I don't have that information. Please contact support@example.com." Do not guess features, prices, or integrations. <context> Our product supports: real-time collaboration, version history, and export to PDF. </context> <question>Can your product sync with Notion?</question> Why I think this works: when the model has a sanctioned, specific "I don't know" response with a known wording, that response becomes a high-probability continuation in exactly the situation where it should be used. (That's my mechanistic intuition, not a result from a paper. Test it on your own cases.)
Technique 10: Stop Sequences
A stop sequence isn't part of the prompt text. It's an API parameter: when the model generates that exact string, generation stops.
response = client.messages.create( model=MODEL, max_tokens=500, stop_sequences=["\n\n---"], # name varies by provider ("stop" in some APIs) messages=[{"role": "user", "content": "Give exactly 3 code review tips as bullets."}], ) Use it to:
- cut off rambling after the part you need,
- stop at a delimiter in structured output,
- stop a few-shot-style completion from inventing the next "example."
Check your provider's docs: parameter names differ, and some reasoning models restrict or ignore it.
Technique 11: Fighting Mode Collapse (Verbalized Sampling)
Source: Zhang et al., 2025.
The problem
After alignment training (Part 1), models drift toward safe, typical, predictable outputs. Ask for five jokes about cats and you often get one joke template five times. That hurts brainstorming, creative writing, and synthetic-data generation.
The paper argues that a cause is typicality bias in preference data: human raters tend to prefer familiar-sounding text, so the training pushes the model toward the typical answer.
The fix
Instead of asking for one answer, ask for several answers with their probabilities:
Generate 5 distinct answers to the question below, and for each one, state how likely you think it is (a probability from 0 to 1). Pick from across the range, not just the most typical ones. Question: Suggest a name for a note-taking app for developers. The model has to produce a spread instead of collapsing onto the single most typical answer. The paper reports 1.6 to 2.1 times more diversity in creative writing compared with direct prompting, without hurting factual accuracy or safety, and that more capable models benefit more.
Use it when you want variety (ideas, personas, test data), not when there's a single right answer.
What Changed: Thinking Models
Newer models can reason internally before they answer: OpenAI's reasoning models, Claude with extended thinking, Gemini's thinking modes, and others. This changes how several techniques above should be used.
- The thinking isn't free. Thinking tokens are generally billed as output tokens, even when the provider hides or summarizes them. A "thinking" call can cost much more than the visible answer suggests.
- Some techniques become less necessary. CoT, CoD, and RE2 all work by making the model write intermediate work. A reasoning model already does that. Provider guidance for these models often advises keeping prompts simple and not forcing step-by-step instructions. Check your provider's current docs, and measure instead of assuming.
- Other techniques are unaffected. ReAct and tool use, retrieval, clear context, few-shot examples, output format, and "what to do when you don't know" all give the model information or constraints, not just more thinking room. A reasoning model can't invent facts it doesn't have.
The mental model: techniques that add computation matter less as models reason on their own. Techniques that add information or constraints keep mattering. Part 6 is about the second kind.
Putting It Together: A Code Review Prompt
Let's combine CO-STAR (structure), a grounded checklist (self-critique with something to check against), and a "way out."
# CONTEXT We're reviewing a pull request for our payment service. Security is critical. This code goes to production. # OBJECTIVE Find real security, correctness, and reliability problems in the code below. # STYLE Technical and direct. # AUDIENCE The backend engineer who wrote it. # RESPONSE Markdown with sections: Security, Correctness, Reliability. Rate each issue Critical, Major, or Minor and quote the line it refers to. If you are not sure something is a problem, put it under "Questions" instead of claiming it is a bug. Before answering, check each issue against this list: - Is it visible in the code I was given, or am I assuming something? - Would the library's default behavior already prevent it? <code_to_review> def process_payment(user_id, amount, card_token): logger.info(f"Processing payment: {user_id} - {amount} - {card_token}") response = requests.post( "https://payment-api.example.com/charge", json={"user": user_id, "amount": amount, "token": card_token}, timeout=5, ) return response.json() </code_to_review> Real issues a good review should find:
- Critical: the card token is written to the logs.
- Major: no status check (
raise_for_status()) or error handling, so a failed charge may be parsed as if it succeeded. - Major: no idempotency key, so a retry after a timeout could double-charge a customer.
- Minor: no validation of
amount(negative values, currency precision).
And one thing a model will sometimes claim that is not a bug: "missing SSL verification." requests verifies TLS certificates by default. The lesson isn't about this snippet: models flag non-issues with total confidence, so check a review against the code. That's why the prompt asks the model to question itself against a list, and gives it a "Questions" section as an out.
Summary: Which Technique for Which Problem
| What's failing | Try | Extra cost | Watch out for |
|---|---|---|---|
| Multi-step reasoning | CoT | More output tokens | A wrong step can propagate |
| Same, but cost matters | CoD | Few extra tokens | Test on your model; smaller models may do worse |
| Errors you can detect | Self-critique with real feedback | About 2x tokens | Self-critique alone often rubber-stamps |
| Needs outside facts or actions | ReAct / tool use | One call per step | Tool quality; needs a step limit |
| Several possible routes | ToT | Many calls (full version) | Single-prompt version is only an approximation |
| Misses details in input | RE2, placement, quote-first | Small | Doesn't fix tokenization issues |
| Inconsistent output | CO-STAR, few-shot | Longer prompt | Examples pull outputs toward themselves |
| Hallucination | Give it a way out + ground it in sources | Small | Test with questions it can't answer |
| Repetitive outputs | Verbalized sampling | More output tokens | Not for tasks with one right answer |
The Deeper Point
All of these work for the same reason: they change what is in the model's context when it writes the answer. More intermediate tokens, a better order, outside facts, a clear shape, a safe exit.
Your job as a prompt engineer:
- Diagnose what is failing.
- Choose the technique that changes the right thing.
- Measure whether it helped on your task, with your model.
- Re-measure when the model changes, because it will.
Step 3 is the one almost everyone skips. In Part 4 we'll deal with what these techniques cost and how to automate the search for good prompts.

