Prompt engineering
At a glance
Definition
Prompt engineering is the practice of designing inputs — the prompts — sent to language models to reliably produce desired outputs. It's the craft that sits between raw model capability and practical application. Every ChatGPT power user, every developer building on the Anthropic or OpenAI APIs, every team deploying LLM-powered products does prompt engineering, whether they call it that or not.
The discipline emerged with GPT-3 in 2020. Users quickly discovered that the same model could produce dramatically different quality outputs depending on how the prompt was structured. Adding a few examples (few-shot prompting) improved results. Asking the model to reason step by step (chain-of-thought) transformed math and logic tasks. Assigning a role, structuring outputs, and providing context all mattered.
By 2026, prompt engineering has matured from clever tricks to systematic engineering. Teams maintain prompt libraries with version control. Frameworks like DSPy treat prompting as programming and optimize prompts automatically. Evaluation platforms (LangSmith, Promptfoo) let you test prompt changes like you'd test code changes. Provider cookbooks from Anthropic, OpenAI, and Google document proven patterns.
The core techniques are surprisingly universal. Zero-shot: describe the task in words. Few-shot: show examples. Chain-of-thought: ask for reasoning. System prompts: set persona and constraints. Structured output: constrain the format. ReAct: interleave reasoning with tools. Combined thoughtfully, these produce reliable behavior even on complex tasks.
Real-world example
The same task, three prompting techniques
Say you want an LLM to classify customer support emails as billing, technical, feature-request, or complaint. A naive prompt might just ask 'What category is this email?' The model may respond inconsistently, hedge with prose, or use categories you didn't define. Better prompts use progressively more structure: (1) a system prompt defining the categories and constraints, (2) few-shot examples showing the desired format, (3) structured output like JSON to force a parseable response. Each layer dramatically improves reliability in production.
# Progressively better prompts for email classification
from anthropic import Anthropic
client = Anthropic()
email = "Hi, I was charged twice for my October subscription..."
# ❌ Naive prompt — inconsistent output format
def classify_v1(email):
return client.messages.create(
model="claude-opus-4-8", max_tokens=100,
messages=[{"role":"user","content":f"What category: {email}"}]
).content[0].text
# ✅ Better — system prompt + constraints + one-word output
def classify_v2(email):
return client.messages.create(
model="claude-opus-4-8", max_tokens=20,
system="""You classify customer emails into exactly one of:
billing, technical, feature-request, complaint.
Respond with ONLY the category word — no explanation.""",
messages=[{"role":"user","content":email}]
).content[0].text
# ✅✅ Best — few-shot examples + structured JSON output
def classify_v3(email):
return client.messages.create(
model="claude-opus-4-8", max_tokens=200,
system="""Classify support emails. Return JSON:
{"category": "...", "confidence": 0.0-1.0, "reasoning": "..."}
Categories: billing, technical, feature-request, complaint.""",
messages=[
{"role":"user","content":"I can't log in for 3 days now."},
{"role":"assistant","content":'{"category":"technical","confidence":0.95,"reasoning":"Login issue."}'},
{"role":"user","content":"Add dark mode please."},
{"role":"assistant","content":'{"category":"feature-request","confidence":0.98,"reasoning":"Feature ask."}'},
{"role":"user","content":email},
]
).content[0].textWhen you'll encounter this
- You're building any LLM feature — the prompt is the interface between your product and the model.
- You're debugging model behavior — most 'model bugs' are actually prompt bugs.
- You're optimizing cost — shorter prompts and better structure often reduce token count 30-50%.
- You're improving reliability — structured prompts with examples and constraints cut hallucination and format drift.
- You're evaluating whether to fine-tune — a well-designed prompt is often the correct baseline before spending on fine-tuning.
How it works
Start with a clear task description
State what you want in plain language. Include the input format, desired output format, and any constraints. Vague prompts produce vague outputs.
Add a system prompt
The system prompt sets persona, style, and constraints before the user message. It anchors behavior across many turns.
Show examples (few-shot)
For anything with format or nuance, examples beat descriptions. 2-5 diverse examples establish the pattern the model should follow.
Structure the output
Ask for JSON, XML, or a specific format. Structured outputs are parseable, testable, and reduce ambiguity. Modern models support strict JSON mode.
Handle edge cases explicitly
Tell the model what to do when it's uncertain, when input is malformed, or when the request is out of scope. Silence on edge cases = unpredictable behavior.
Add chain-of-thought where reasoning matters
For complex tasks, ask the model to reason step by step (CoT) before producing the final answer. Dramatically improves math, logic, and multi-step tasks.
Iterate with an eval set
Build a small set of test inputs with expected outputs. Every prompt change gets tested against the set. This is the difference between prompt engineering and prompt vibes.
Version and monitor
Treat prompts like code — version control, review, monitor in production. Prompts that worked six months ago may need updates as models change.
Common misconceptions
The bar is rising, but the discipline persists. Modern models need less careful prompting for simple tasks. But production systems, agents, and edge cases still require deliberate design. Prompt engineering shifts from 'clever tricks' to 'systematic design' — it doesn't disappear.
No. Long prompts increase cost, latency, and can degrade quality (models focus less on middle content). Trim aggressively. Every sentence in a production prompt should earn its place.
Neither replaces the other. Prompt engineering is your first tool — often sufficient. Fine-tuning is for consistent behavior at scale, cost reduction, or capabilities prompting can't reliably produce. See our comparison.
Related terms
Related in Prompt Engineering
Broader concepts
Narrower / specific concepts
Head-to-head comparisons
Where you'll see this in practice
Related models
Learn more
- Take the Master Prompt Engineering path
- Read: How Chain-of-Thought Actually Works
- Compare Prompt Engineering vs Fine-tuning
- Browse Prompt Engineering category
Sources & further reading
- Chain-of-Thought Prompting Elicits Reasoning in LLMs — Wei et al., 2022. Read →
- Anthropic's Prompt Engineering Documentation — Official Anthropic guide. Read →
- DSPy: Compiling Declarative Language Model Calls — Khattab et al., 2023. Read →
- The Prompt Report: A Systematic Survey of Prompting Techniques — Schulhoff et al., 2024. Read →
Frequently asked about Prompt Engineering
By 2026, yes — treated as a first-class discipline in most serious teams. It has version control, evaluation, testing, and monitoring. The 'not real engineering' criticism reflected early ad-hoc practices. Mature prompt engineering is systematic, measurable, and reproducible.
Two things: read what works (papers, others' prompts, provider cookbooks) and evaluate systematically. Every good prompt engineer maintains an eval set for their common prompts and treats prompt changes like code changes.
Start with zero-shot for simple tasks — modern models handle a lot without examples. Add few-shot when you need consistent format, unusual style, or the task is genuinely ambiguous. Few-shot uses more tokens; use it when the reliability gain justifies the cost.
Not building an eval set. Teams tweak prompts based on 'looks right' vibes, then can't tell if changes help. A simple eval set of 20-100 examples with expected outputs transforms prompt engineering from art to science.
Mostly. Core patterns (few-shot, CoT, system prompts) work across Claude, GPT, and Gemini. But each model has quirks — Claude responds better to XML tags for structure, GPT to markdown, Gemini to explicit reasoning cues. Test on your target model.
Technically reviewed by the AI Terms Guide editorial team on August 6, 2026. Last updated: August 6, 2026. Spotted an error? Let us know — corrections ship within 24 hours.
Building with AI? Try our sister sites
Deep coverage of AI errors, code patterns, and pricing you won't find in the reference.
AI Terms Weekly
One deep term, three new models, one comparison — every Tuesday.