What Is Prompt Engineering? Definition, Core Techniques and Examples
What prompt engineering is, what it can and cannot fix, the core techniques with examples, and how practitioners test prompts, with links to Anthropic and OpenAI's official guidance.
Prompt engineering is the practice of designing and testing the instructions, context and examples you give a language model so that it produces the output you need, reliably. It works with an existing model as-is. It does not involve training or fine-tuning.
The definition has two halves, and both matter. Designing is writing a clear prompt. Testing is checking that the prompt keeps working across realistic inputs, and that's what separates prompt engineering from simply asking a question well.
This page covers fundamentals: what the term means, the core techniques, and how prompts are evaluated. For a hands-on walkthrough with before/after rewrites, read How to Write Better AI Prompts.
What a Prompt Is Made Of
Most effective prompts combine some of these parts:
| Part | What it does | Example |
|---|---|---|
| Task | What to produce | "Summarize this incident report" |
| Context | Facts the model can't know | "Readers are on-call engineers who weren't involved" |
| Material | The input to work on, clearly delimited | <report>...</report> |
| Format | Shape of the output | "5 bullets, then a table of action items with owners" |
| Constraints | What to avoid or limit | "Don't speculate about root cause beyond the report" |
| Examples | Demonstrations of good output | Two sample summaries |
| Role (optional) | Perspective or tone to adopt | "You are reviewing this as a site reliability engineer" |
A simple question needs only a task. A prompt that runs hundreds of times inside an application usually needs most of these parts.
What Prompt Engineering Can and Cannot Fix
Prompt engineering is the right tool when the model can do the task but isn't doing it the way you need: wrong format, missing details, inconsistent tone, skipped steps.
It is the wrong tool, or only part of the answer, when:
- The model lacks the information. No phrasing will make it know your internal pricing or yesterday's data. Provide the material, or connect a retrieval system.
- The problem is cost or speed. Anthropic's prompt engineering overview notes that latency and cost can sometimes be improved more easily by choosing a different model (Anthropic, Prompt engineering overview, checked 2026-11-05).
- You need guaranteed correctness. Prompts reduce errors; they don't eliminate them. Facts, figures and citations still need verification.
Core Techniques
Be clear and specific
Say what you want, for whom, in what form. Anthropic's guide suggests a practical test: show the prompt to a colleague with minimal context on the task, and if they would be confused, the model probably will be too (Claude prompting best practices, checked 2026-11-05).
Vague: Write about our new feature.
Specific: Write a 120-word changelog entry for existing users announcing
that projects can now be exported as CSV or JSON from the Share
menu. Lead with what they can now do. No marketing adjectives.
Explain the reason behind instructions
A rule with a reason is easier for a model to apply sensibly in cases you didn't anticipate. Anthropic's guide gives the example of explaining that a response will be read aloud by text-to-speech, rather than only forbidding ellipses (checked 2026-11-05).
Keep each answer under 3 sentences. These appear in a mobile
notification, which truncates after about 180 characters.
Show examples (few-shot prompting)
Examples are one of the most dependable ways to steer format and tone. Both vendors recommend examples that vary: Anthropic says they should be relevant, diverse and clearly marked (for example with <example> tags), and OpenAI recommends showing "a diverse range of possible inputs with the desired outputs" (OpenAI prompt engineering guide, checked 2026-11-05).
Classify each support ticket as billing, bug, or how-to.
<example>Ticket: "I was charged twice this month" -> billing</example>
<example>Ticket: "Export button does nothing in Safari" -> bug</example>
<example>Ticket: "Where do I change my team name?" -> how-to</example>
Ticket: "The invoice PDF shows last year's address"
Structure the prompt and delimit the material
When a prompt mixes instructions, context and pasted content, mark each part. Anthropic recommends XML tags such as <instructions> and <context>; OpenAI recommends Markdown headings and XML tags to mark sections and the boundaries of reference content (both checked 2026-11-05). For long documents, Anthropic recommends putting the documents first and the question after them.
Specify the output format
If output is parsed by code or pasted into a template, define it exactly: field names, types, allowed values. Many APIs also offer structured-output features that enforce a schema; check your provider's current documentation, because prompt wording alone doesn't guarantee valid JSON.
Ask for reasoning on multi-step problems
For analysis, math and decisions with several factors, asking the model to work through the steps before answering can improve results and makes errors easier to spot. Many current models also have built-in reasoning or "thinking" modes, which changes how much you need to ask for this explicitly. See the chain-of-thought prompting guide.
A warehouse holds 200 units. It ships 40% on Monday and 25% of the
remainder on Tuesday, then receives 30 units on Wednesday. How many
units are on hand at the end of Wednesday? Show each step.
(Worked answer, for checking: 200 - 80 = 120; 120 - 30 = 90; 90 + 30 = 120 units.)
Separate standing instructions from the request
APIs distinguish persistent instructions from individual requests. Anthropic uses a system prompt; OpenAI's current guide describes developer messages, which it says are "prioritized ahead of user messages" (checked 2026-11-05). Standing rules (tone, policies, output format) go there; the specific task goes in the user message. See System Prompts vs User Prompts.
Assign a role when it adds useful focus
A one-line role ("You are reviewing this as a security engineer") can set tone and domain focus. Anthropic's guide recommends role prompting in the system prompt (checked 2026-11-05). A role does not add knowledge the model lacks, and it is not a substitute for specific instructions. See the role-playing prompts guide.
Break large tasks into steps (prompt chaining)
When a task has distinct stages, run them as separate prompts and pass the output forward. Anthropic describes self-correction as a common pattern: generate a draft, review it against criteria, then refine, with each step as a separate call so you can inspect it (checked 2026-11-05).
Step 1: List every API endpoint in this code with its HTTP method.
Step 2: For each endpoint in the list, identify missing input validation.
Step 3: Write validation schemas for the five riskiest endpoints.
Tune generation settings where available
APIs may expose settings such as temperature that change how varied outputs are. Which settings exist and what they do differs by model, so check your provider's documentation. See Temperature and Top-P Settings.
How Prompts Are Tested
Testing is the part most often skipped. Anthropic's overview assumes, before you start prompt engineering, that you have a clear definition of success criteria, some way to test empirically against them, and a first draft prompt (checked 2026-11-05). OpenAI's guide recommends building tests and evaluation suites that measure prompt behavior, and pinning production applications to specific model snapshots so behavior stays consistent (checked 2026-11-05).
In practice, a minimal loop looks like this:
- Define success. What does a good output contain? What makes it unusable?
- Collect test inputs. A handful of realistic cases, including awkward ones.
- Run and score. Run the prompt several times per input and score against your criteria.
- Change one thing at a time. Then re-run the same inputs and compare.
- Re-test when the model changes. A prompt tuned on one model version can behave differently on the next.
How to Write Better AI Prompts has a worked rubric you can copy.
Prompt Engineering in Different Kinds of Work
The techniques stay the same, but the context that matters changes:
- Software development: language and framework versions, conventions, error-handling expectations, tests. Coding assistants also read persistent rules files; see How to Write Cursor Rules.
- Writing and content: audience, voice, structure, and what claims need sources. See writing prompts for content creators.
- Data analysis: schema, metric definitions, and how results will be verified. See the data analysis prompts guide.
- Research and academic work: source requirements and verification, since models can produce plausible but nonexistent references. See the academic writing prompts guide.
Common Misconceptions
- "There's a magic phrase." Results come from clarity, context and examples, not secret wording. Phrases that seem to help on one model often don't transfer.
- "A longer prompt is a better prompt." Irrelevant context can distract. Include what changes the answer.
- "If it worked once, it works." Outputs vary between runs. A prompt is reliable when it holds up across many inputs.
- "Prompt engineering is only for developers." Anyone who writes reusable instructions for an AI assistant is doing it. Code matters only when you call models through an API.
Frequently Asked Questions
Is prompt engineering still relevant as models improve?
Models have become better at inferring intent, but they still can't know your context, audience or definition of "good" unless you provide it. The testing half of prompt engineering becomes more important as prompts move into products and team workflows.
Do I need to code?
No. Writing and testing prompts in a chat interface is prompt engineering. Coding becomes useful when you run prompts through an API or automate evaluations.
Which model is best for prompt engineering?
No single model is best for every task, and rankings change with each release. Test your actual prompts on the models you're considering. For how prompting styles differ, see ChatGPT vs Claude prompt differences.
Where can I find official guidance?
Start with the vendors' own documentation: Anthropic's prompt engineering overview and prompting best practices, and OpenAI's prompt engineering guide. Vendor guidance is updated as models change, so check the current version.
Where to Go Next
- How to Write Better AI Prompts: ten techniques with before/after examples and an evaluation rubric
- Chain-of-Thought Prompting
- System Prompts vs User Prompts
- Role-Playing Prompts
- Temperature and Top-P Settings
To study complete prompts written by others, browse the prompt directory and look at how each template separates fixed instructions from variables.
Related Articles
System Prompts vs User Prompts: Roles, Priority and Provider Differences
How system, developer and user messages work in the OpenAI, Anthropic and Gemini APIs, which instructions win when they conflict, and how ChatGPT and Claude app settings differ from API system prompts.
How to Write Better AI Prompts: 10 Practical Techniques
A practical how-to for writing better AI prompts: 10 techniques with before/after examples, plus a simple rubric-based workflow for comparing prompt variants before you rely on one.
Coding Prompts That Work: A Workflow from Context to Verified Code
A practical workflow for AI-assisted coding: give the right context, set constraints, generate in small steps, verify with tests, review and security checks, and iterate. Links to individual coding templates for each step.