Step 1 of 2

Prompt Engineering Playbook

Practical prompt patterns that work: clear instructions, examples, structure, chain-of-thought, and structured output.

13 min read

Prompt engineering isn't about magic phrases. It's about giving a very capable reader everything they need to do excellent work: a clear goal, the right context, examples of what good looks like, room to think, and a precise output format. This playbook covers the patterns that consistently work - and how to know whether a change actually helped.

The anatomy of a strong prompt#

Role & goalWho the model is acting as and what outcome you want - and why it matters
ContextBackground, audience, constraints, the data to work on
InstructionsSpecific steps or requirements, in order
ExamplesOne to a few samples of ideal input → output
ReasoningPermission to think step by step before answering
Output formatExact structure: sections, JSON schema, length, tone
Not every prompt needs every part, but most weak prompts are missing two or three of them.

Seven patterns that work#

1. Be clear, direct, and specific#

Vague prompts get generic answers. State the task, the audience, the constraints, and what success looks like. Say what you want rather than only what to avoid.

Vague

  • 'Write something about our new feature.'

Specific

  • 'Write a 120-word announcement of our CSV export feature for existing customers who asked for it. Lead with the benefit (share reports without screenshots), include one example, end with where to find it. Friendly, no hype words.'

2. Explain the why#

Context about why a rule exists helps the model generalize. "Never use ellipses" is followed literally; "this will be read aloud by a text-to-speech engine, so avoid ellipses - it can't pronounce them" is followed intelligently, including cases you didn't anticipate.

3. Show examples (few-shot)#

Examples are the most reliable way to pin down format, tone, and edge cases. Include a few diverse examples, including a tricky one, and make sure they match what you actually want - the model will copy their patterns closely.

Classify each support message as billing, bug, or feature_request.

Message: "I was charged twice this month."
Label: billing

Message: "Export button does nothing on Safari."
Label: bug

Message: "Would love dark mode for the dashboard!"
Label: feature_request

Message: "{new_message}"
Label:

4. Structure with tags#

When a prompt mixes instructions, documents, and examples, wrap each in clearly named tags so nothing blurs together - and refer to the tags by name.

<instructions>
Summarize the contract below for a non-lawyer. Flag any auto-renewal or
termination-fee clauses. Quote the exact clause text for each flag.
</instructions>

<contract>
{contract_text}
</contract>

<output_format>
1. Summary (5 bullets)  2. Flags (clause, quote, plain-English risk)
</output_format>

5. Let it think (chain-of-thought)#

For math, analysis, multi-step reasoning, and decisions, ask the model to reason before it answers. Research on chain-of-thought prompting showed large gains on reasoning tasks, and self-consistency - sampling several reasoning paths and taking the majority answer - adds more. Many current models also have built-in extended-thinking modes that do this for you.

Before answering, think through the problem step by step in <thinking> tags:
identify what's being asked, list the relevant facts, and check your arithmetic.
Then give only the final answer in <answer> tags.

Separating reasoning from the answer lets your code show only the answer while you keep the reasoning for debugging.

Chain-of-thought
Asking the model to reason step by step before answering - shown to significantly improve accuracy on math, logic, and multi-step problems.
Few-shot prompting
Including a few example input-output pairs in the prompt so the model learns the expected format, tone, and edge-case handling from them.
Self-consistency
Sampling several reasoning paths for the same question and taking the majority answer - adds reliability on top of chain-of-thought at the cost of extra API calls.
Token
The basic unit of text a model processes - roughly three-quarters of a word in English. Prompt length, output length, and cost are all measured in tokens.

6. Specify the output format exactly#

If code will consume the output, use the provider's structured output or tool-calling features with a JSON schema, and validate the result. If a human will read it, specify sections, length, and tone - and consider showing a sample of the format.

7. Chain prompts for complex tasks#

One prompt doing five jobs does each one worse. Split complex work into a chain - research → outline → draft → edit - where each step has a focused prompt and you can inspect (and fix) the intermediate results. See the five workflow patterns.

Working with long documents#

  1. 1Put long documents at the top of the prompt, and your question and instructions at the end.
  2. 2Wrap each document in tags with metadata (title, source, date).
  3. 3Ask the model to first quote the passages relevant to the question, then answer from those quotes.
  4. 4Remove irrelevant material - fewer, more relevant tokens beat more tokens.
  5. 5Keep the stable parts (instructions, documents) first so prompt caching can reuse them.

Beyond chain-of-thought#

TechniqueIdeaWhen it's worth it
Self-consistencySample several reasoning paths; take the majority answerTasks with a single checkable answer; worth the extra calls
Tree of ThoughtsExplore multiple reasoning branches, evaluate them, backtrack from dead endsSearch-like problems (puzzles, planning) where a first attempt often fails
Self-critiqueDraft → critique against criteria → reviseWriting and code with clear quality criteria
Role promptingAssign an expert role in the system promptSetting domain vocabulary, depth, and tone

Iterate with evidence, not vibes#

A prompt change that fixes one example can quietly break five others. Treat prompts like code:

  1. 01Test set20-100 real inputs incl. hard cases
  2. 02RunCurrent prompt → baseline
  3. 03Change one thingA single, deliberate edit
  4. 04CompareScore both on the whole set

↺ Compare feeds back into Test set

Keep the change only if it wins on the set, not just on the example that prompted it.

Common mistakes#

  • Under-specifying - leaving format, audience, or length to chance.
  • Contradictions - "be concise" plus a list of twelve things to cover.
  • Negative-only instructions - say what to do instead of only what not to do.
  • Examples that don't match the ask - the model copies the examples, not the instructions.
  • Stuffing everything into one prompt - split it into a chain.
  • Judging by one output - outputs vary; judge on a test set.

The Prompts library has copy-ready prompts built on these patterns - for coding, writing, analysis, agents, and everyday work.

Papers behind this guide

Further reading

Search Data Science After Dark

Search across prompts, models, papers, guides, and library topics.