5.8 KiB
title, source, author, published, created, description, tags
| title | source | author | published | created | description | tags | ||
|---|---|---|---|---|---|---|---|---|
| The Prompt Engineering Playbook: 11 Patterns That Work on Every LLM in 2026 | https://x.com/ihtesham2005/status/2028441207807066534 |
|
2026-03-02 | 2026-03-02 | Canadian mom, coffee lover, sleep addict |
|
Most people prompt like they text a friend.
"Hey can you help me with this?"
That works for simple tasks. It breaks the second you need consistency, structure, or quality across hundreds of runs.
If you want reliable output from Claude, GPT, DeepSeek, Gemini, or any other frontier model in 2026, you need patterns.
These 11 work across all major LLMs.
Beginner Patterns
1. Few-Shot Learning
What it does?
Shows the model input → output examples before your real request so it learns the pattern implicitly.
When to use it?
Formatting tasks, classification, style matching, data transformation.
Example:
Convert customer feedback into sentiment tags.
Examples:
Input: "Delivery was fast but the box was damaged"
Output: {"delivery": "positive", "packaging": "negative"}
Input: "Great product, terrible support"
Output: {"product": "positive", "support": "negative"}
Now do this:
Input: "App works perfectly on iPhone but crashes on Android"
Output:
Three examples are usually enough. More rarely improves results.
2. Role or Persona Setting
What it does?
Changes vocabulary, depth, and reasoning style by assigning a specific identity.
When to use it
Technical writing, expert review, niche domains.
Example:
You are a senior DevOps engineer who manages Kubernetes clusters at scale.
Review this Dockerfile and give direct, technical feedback.
Do not soften criticism.
[paste Dockerfile]
Persona affects both knowledge register and tone.
3. Constraint Framing
What it does?
Defines hard boundaries before the task so the model anchors on them.
When to use it?
Social posts, UI copy, API responses, space-limited outputs.
Example:
Write a product description.
Constraints:
- Maximum 60 words
- Must include battery life: 40 hours
- Must include price: $299
- No superlatives
- End with a question
Put constraints before the task description, not after.
4. Structured Output Forcing
What it does?
Forces predictable structure like JSON, XML, tables.
When to use it?
When piping output into databases, automation tools, or frontends.
Example:
Analyze this support ticket.
Return ONLY valid JSON with this structure:
{
"category": "billing|technical|shipping|other",
"priority": "low|medium|high|critical",
"sentiment": "positive|neutral|negative",
"requires_human": true|false,
"summary": "one sentence max"
}
Do not include text outside JSON.
Explicitly saying return ONLY valid JSON reduces formatting errors dramatically.
5. Step-by-Step Decomposition
What it does?
Breaks complex tasks into ordered steps.
When to use it?
Migration plans, procedural tasks, multi-stage reasoning.
Example:
Help me migrate MySQL to PostgreSQL.
1. List compatibility issues
2. Show syntax differences
3. Provide a script to detect incompatibilities
4. List two manual tests required
Complete each step fully before moving on.
Intermediate Patterns
6. Chain-of-Thought
What it does?
Forces the model to reason step-by-step before giving the final answer.
When to use it?
Math, logic, multi-condition decisions.
Example:
Calculate projected revenue.
Show your work before the final number.
For reasoning-native models, explicit CoT may not be required. For standard models, it improves accuracy.
7. Context Priming
What it does?
Front-loads background information to narrow interpretation space.
When to use it?
Internal documentation, niche products, domain-specific writing.
Example:
Context:
This is documentation for a Rust library that compiles Vue templates.
Audience: Rust developers unfamiliar with Vue.
Style: Clear prose, minimal jargon, example before explanation.
Task:
Write the Getting Started section.
Without context, output becomes generic.
8. Anti-Hallucination Framing
What it does?
Encourages the model to admit uncertainty rather than fabricate.
When to use it?
Research, legal, compliance, factual work.
Example:
If you are uncertain, say "I am not certain."
Do not estimate missing facts.
This reduces confident false answers.
9. Verification Loop
What it does?
Asks the model to check its own output against test cases.
When to use it?
Code, calculations, structured analysis.
Example:
Write a regex for email validation.
Then test it against these valid and invalid cases.
If it fails, fix before final answer.
Self-checking catches a meaningful portion of errors.
10. Comparative Analysis
What it does:
Forces tradeoffs instead of surface descriptions.
When to use it:
Tool selection, vendor comparison, architecture decisions.
Example:
Compare Redis vs Memcached for 10k requests per second.
Evaluate latency, memory efficiency, persistence, complexity.
Then pick one and defend it.
Do not hedge.
Models default to it depends answers unless forced to commit.
11. Iterative Refinement
What it does?
Breaks output across multiple turns instead of one mega-prompt.
When to use it?
Long-form writing, product strategy, complex architecture.
Turn 1:
Give outline only.
Turn 2:
Expand strongest sections.
Turn 3:
Write full article.
Iterative passes consistently outperform one-shot prompts.
Final Principle
Most prompting failures are not model failures.
They are instruction failures.
If you define:
- Context - Constraints -Structure - Verification - Role
You dramatically reduce variance.
Prompting is not about clever phrasing.
It is about controlling degrees of freedom.
Once you understand that, every LLM becomes more predictable.