Prompting patterns
Roles, examples, structure, and step-by-step reasoning—patterns that often help, with limits.
What you'll learn
- Apply role prompts, few-shot examples, and structured output requests.
- Use chain-of-thought style steps when logic errors appear.
- Recognize when a pattern stops helping and tools or RAG are needed.
In plain English
Prompting patterns are reusable templates: tell the model who it is, show examples of good answers, ask for bullet lists or JSON, or request step-by-step reasoning before the final answer.
None of these are magic spells—they nudge the model toward completions like ones it saw during training or fine-tuning.
How it works
Role prompts set tone and priorities (“You are a careful editor…”). Few-shot prompting includes one or more input–output demos in the prompt so the model mimics the pattern. Structured output asks for headings, tables, or JSON so downstream code can parse results.
Chain-of-thought (CoT) means asking the model to write intermediate steps. That can reduce arithmetic and logic slips because each step becomes context for the next token—though steps can still be wrong.
- Zero-shot: instruction only.
- Few-shot: instruction plus labeled examples.
- CoT: “Think step by step” or explicit scratchpad sections.
- Structured: schema, JSON keys, or fixed headings.
Going deeper
Patterns interact: a role plus JSON schema plus two examples can work well for extraction tasks; the same stack may be overkill for creative writing.
When tasks need fresh facts or actions in the world, pair prompting with RAG or tools—patterns alone cannot fetch live data.
Common misconceptions
- Chain-of-thought proves the model reasoned correctly.
- It exposes a generated scratchpad; each line is still next-token prediction.
- More shots always beat fewer.
- Examples consume context; irrelevant shots confuse the task.
Key facts
- Few-shot examples teach format and task boundaries via imitation.
- Role prompts bias style and safety behavior, not underlying knowledge.
- Structured outputs help pipelines but need validation parsers.
- CoT helps some reasoning tasks; it is not reliable on all math or logic.
- Combine patterns with retrieval or tools for factual or action tasks.
Sources used
These free resources informed this page. ANN writes original explainers; we do not copy course text behind paywalls.
- Anthropic Prompt Engineering Interactive Tutorial — Hands-on patterns for clearer instructions and examples.
- Hugging Face LLM Course — How LLMs behave as text predictors in applications.
- Google Machine Learning Crash Course — General ML evaluation mindset for generative systems.
Also explore AI companies, Live Feed, and Weekly Brief.
