Skip to content

Prompt Engineering Cheatsheet

The core patterns

PatternWhen to use itShape
Zero-shotSimple, well-defined tasksJust ask.
Few-shotAnything where the output format is strictShow 2–5 examples before the real query.
Chain-of-ThoughtReasoning, math, multi-step planningAsk the model to “think step by step” before answering.
ReActAgent / tool-using flowsInterleave Thought → Action → Observation steps.
Self-consistencyHigh-stakes reasoning where one sample isn’t enoughSample n completions, take the majority answer.
ReflectionEditing or improving prior outputAsk the model to critique its own draft, then revise.

A reusable template

# Role
You are a <role> helping <audience> with <task>.
# Context
<background the model needs — pasted docs, prior turns, constraints>
# Task
<exactly what you want it to do>
# Output format
- Section 1: ...
- Section 2: ...
- Return as JSON with keys: foo, bar, baz
# Rules
- Do not <thing to avoid>
- If unsure, say "I don't know" instead of guessing.

Anti-patterns (things I stopped doing)

  • Stuffing the system prompt with every rule you’ve ever thought of. Keep it < ~400 tokens.
  • Using "Please" and "Thank you" as a substitute for clear instructions.
  • Asking for JSON without giving a schema example — you’ll get creative keys.
  • Re-reading the whole conversation every turn instead of summarizing + pruning.

A quick math bit

Token cost for a prompt of length nn tokens run kk times with self-consistency:

cost=k(ncin+mcout)\text{cost} = k \cdot (n \cdot c_{\text{in}} + m \cdot c_{\text{out}})

…where mm is the average completion length. Useful when deciding if that 10× sampling is worth it.

See also