Skip to main content

Prompt Engineering Guide: Techniques From the Vendor Docs

A prompt engineering guide built on what OpenAI, Anthropic and Google publish: the six parts of a prompt, seven techniques, a rewrite and how to test it.

Founder of IImagined.ai

Published
Feb 28, 2026
Updated
Oct 13, 2026
Reading time
11 min read
Quick answer

Prompt engineering is writing instructions so a model gives you what you need every time, not just once. A reliable prompt has six parts: a role, instructions with their reasons, a few examples, the context, an output format and the request itself, placed last. OpenAI, Anthropic and Google agree on most of it. The part people skip is testing: write down what good looks like, collect real inputs, and rerun them after every change.

Prompt engineering is writing instructions for a language model so that it produces what you need consistently, not just once. A reliable prompt has six parts: a one-line role, clear instructions with the reason behind them, a few examples, the context the model cannot know, the output format, and the request itself, placed last. Then you test it on real inputs, because one good answer proves very little.

Everything here comes from the model makers' own documentation, checked on 13 October 2026: Anthropic's prompting best practices, prompt engineering overview and evaluations guide, OpenAI's prompt engineering guide and Structured Outputs guide, and Google's prompt design strategies for Gemini. Where the three disagree, the table further down says so.

This guide is for text models: ChatGPT, Claude, Gemini and the APIs behind them. Image prompts follow different rules, covered in our Midjourney prompts guide. For the one-paragraph definition, see prompt engineering in the glossary.

What is prompt engineering, and when is it the wrong fix?

OpenAI's definition is the most useful one: "the process of writing effective instructions for a model, such that it consistently generates content that meets your requirements". The word that matters is consistently. Model output is not deterministic, so a prompt is only good if it holds up across many inputs.

It is not always the right tool. Anthropic's overview says plainly that not every failing result is best solved by prompt engineering, and gives the example that latency and cost can be easier to improve by choosing a different model. If the model lacks facts, the fix is to supply them, which is what retrieval does: see RAG vs fine-tuning. If you need valid JSON every time, the fix is a schema, not stronger wording.

The six parts of a prompt that works

The three vendors describe nearly the same skeleton. OpenAI lists four sections for its developer message, in the order Identity, Instructions, Examples, Context. Anthropic and Google add where long material and the question should sit. Put together, that gives six parts.

Prompt anatomy, top to bottom
  1. 01
    Role

    Who the model is for this task. One sentence.

  2. 02
    Instructions

    What to do, the rules, and why the rules exist.

  3. 03
    Examples

    A few inputs with the exact outputs you want.

  4. 04
    Context

    Documents and data, wrapped in tags so they cannot be mistaken for instructions.

  5. 05
    Output format

    Structure, length and tone of the answer.

  6. 06
    The request

    The input or question for this run, at the very end.

PartWhat goes in itVendor note
RoleOne sentence on who the model is for this task and how it should soundOpenAI calls this Identity and puts it first
InstructionsThe task, the rules and the reason behind any rule that is not obviousNumbered steps when order matters (Anthropic)
ExamplesThree to five inputs with the exact outputs you wantIdentical formatting across examples (Google)
ContextThe documents, data or background the model cannot knowLong material goes above the question (Anthropic, Google)
Output formatLength, structure, fields, tone, what to leave outA schema when code will read the result (OpenAI, Google)
The requestThe specific input for this runLast, after the context

Short prompts do not need all six. A one-line question to a chat app is fine as a one-line question. The skeleton earns its keep when a prompt will be reused: in a custom instruction, an automation or an app.

Seven prompt engineering techniques the vendors agree on

1. Be clear and direct

Anthropic's test is the best one in any of the guides: show your prompt to a colleague with minimal context on the task and ask them to follow it. If they would be confused, the model will be too. Google says the same in fewer words: state the goal clearly and avoid unnecessary or overly persuasive language.

2. Explain why, not just what

A rule with a reason generalises; a bare rule does not. Anthropic's example: "NEVER use ellipses" works less well than explaining that the response will be read aloud by a text-to-speech engine that cannot pronounce them. With the reason, the model also avoids other things a speech engine would trip over.

3. Show examples

Examples are the most reliable way to fix format and tone. Google goes furthest, recommending that you always include few-shot examples and noting that clear examples can replace some instructions entirely. Anthropic suggests three to five, relevant to the real task and varied enough that the model does not copy an accident. Google adds the warning that too many examples can make the model overfit to them.

4. Separate the parts with tags or headings

When a prompt mixes instructions, examples and pasted data, mark where each begins and ends. Anthropic recommends XML tags such as <instructions> and <context>. OpenAI suggests Markdown headings for sections and XML tags around supporting material. Google accepts either and asks for one format per prompt. The tag names are not magic; consistency is the point.

5. Put long material first and the question last

For long inputs, Anthropic and Google both say to supply the documents first and ask at the end. Anthropic's docs state that queries at the end "can improve response quality by up to 30 percent in tests", especially with several documents (figure from Anthropic's prompting best practices page, read 13 October 2026). Anthropic also suggests asking the model to quote the relevant passages before answering.

6. Say what to do, not what to avoid

"Do not use markdown" is weaker than "write in flowing prose paragraphs", per Anthropic's formatting guidance. The style of the prompt leaks into the answer too: a prompt written as bullet points tends to get bullet points back.

7. Use a schema when code reads the output

If another program will parse the result, do not rely on pleading for valid JSON. OpenAI's Structured Outputs feature makes responses adhere to a JSON Schema you supply, and Google recommends Gemini's structured output feature for anything beyond a simple object. Our Claude tool use guide shows the same idea through tool definitions.

A worked example: rewriting a weak prompt

The task: turn 60 survey responses into something a founder can act on. This example is illustrative. Here is the prompt most people would write first.

Summarize this customer feedback and tell me what to fix.

[60 pasted survey responses]

It will return a summary. It will also choose its own length, invent its own categories, and give different categories next week, so you cannot compare one week with the next. Here is the same request with the six parts filled in.

You are a product analyst writing for a founder who reads this on Monday morning.

<feedback>
[60 pasted survey responses, one per line, each starting with its ID]
</feedback>

<instructions>
1. Group the responses into themes. A theme needs at least three responses.
2. For each theme, count the responses and pick the two quotes that state it most plainly.
3. Rank themes by count, highest first.
4. Recommend one fix for each of the top three themes. Say what you would need to know to be sure.
Use only the responses above. If a response is unclear, put its ID under "Unsorted" instead of guessing.
</instructions>

<example>
Theme: Checkout fails on mobile (7 responses)
Quotes: "Paid twice because the button did nothing" (ID 14); "Gave up at the card form" (ID 31)
Fix: Test the card form on small screens. Need to know: which browsers.
</example>

<format>
Plain text, no tables. One block per theme in the layout of the example. Finish with one line: the single change you would ship first, and why.
</format>
What changed
First draft
  • No reader, so no sense of length or tone
  • Data and request run together
  • "What to fix" left to interpretation
  • No rule for unclear responses, so the model guesses
  • Format differs on every run
Rewrite
  • One-line role names the reader
  • Data sits in its own tag, above the instructions
  • Numbered steps with a threshold for a theme
  • An explicit place for anything unclear
  • One example and a format block fix the layout

The rewrite is longer, and that is fine. Every added line removes a decision the model was making on your behalf. Because the data sits in a tag at the top and the rules below it, the same prompt works next week with new responses pasted in.

How prompting differs between ChatGPT, Claude and Gemini

The fundamentals transfer. The details below are where each vendor's current guide says something specific, as of October 2026. Model behaviour changes with each release, so treat this as a snapshot and check the linked guide for the model you use.

OpenAIAnthropic (Claude)Google (Gemini)
StructureMarkdown headings plus XML tags; sections in the order Identity, Instructions, Examples, ContextXML tags, one per content type, named consistently and nested where the content is nestedXML-style tags or Markdown headings; pick one and stay with it inside a prompt
How much to spell outGPT models want precise instructions; reasoning models do better with a high-level goalBe explicit. Ask for the extra effort you want instead of expecting it to be inferredBe precise and direct; avoid unnecessary or overly persuasive language
ExamplesA diverse range of inputs with the desired outputsThree to five, relevant and varied, inside example tagsAlways include them; too many can make the model overfit to them
Long documentsReusable content first, which helps prompt caching; request-specific context near the endDocuments at the top, question at the endAll context first, question last, with a bridging phrase such as "Based on the information above"
Settings to knowPin production apps to a dated model snapshotPrefilled responses are not supported from Claude 4.6 models onKeep temperature, top_p and top_k at their defaults on Gemini 3 models

Three points are worth pulling out. First, OpenAI splits its own lineup: it describes a reasoning model as a senior co-worker you give a goal to, and a GPT model as a junior one who needs explicit instructions. Second, Anthropic warns that recent Claude models are more responsive to the system prompt, so wording like "CRITICAL: You MUST" can now cause overuse of a tool where plain wording works. Third, Google says lowering temperature on Gemini 3 can cause looping or degraded performance, which reverses a habit many people carried over from older models.

If you are choosing between assistants, Claude vs ChatGPT compares them, and our LLM API pricing comparison covers what long prompts cost per call.

How to test a prompt

This is the step that separates prompt engineering from prompt writing. Anthropic's guide assumes you have three things before you start tuning: a clear definition of success, a way to test against it, and a first draft. OpenAI recommends building evaluations that measure prompt behaviour so you can track it as you iterate or change model versions.

A test loop you can run in a spreadsheet
  1. 1
    Write down what good means

    Specific and measurable. "Every theme has a count and two quotes" can be checked. "A good summary" cannot.

  2. 2
    Collect 10 to 20 real inputs

    Include the awkward ones: empty fields, very long entries, off-topic messages. The Anthropic guide says not to forget edge cases.

  3. 3
    Run the prompt on all of them

    Read every output against your criteria and mark pass or fail. Note why each failure failed.

  4. 4
    Change one thing

    Fix the most common failure with one edit, then rerun the whole set. An edit that fixes one case often breaks another.

  5. 5
    Hold some inputs back

    Keep a few inputs you never tune against, and check them at the end. They tell you whether you improved the prompt or memorised the test.

  6. 6
    Rerun when the model changes

    A new model version is a new test. OpenAI advises pinning production apps to a dated snapshot for this reason.

Where the prompt lives matters as well. OpenAI now recommends keeping production prompts in your application code, where they get review, tests and your normal deployment process, and is retiring its saved prompt objects: the v1/prompts endpoint is scheduled to shut down on 30 November 2026. If you build on an API, our Claude API tutorial and ChatGPT API workflows show prompts inside real code.

Past a single prompt, the same discipline scales up. A tool definition is a prompt, a system message for an agent is a prompt, and a spec for a coding assistant is a long prompt with tests attached, which is the subject of spec-driven development. Our AI SaaS Builder program picks up from here with a prompt engineering lesson inside its Claude API module, followed by tool use and structured output.

Common prompt engineering mistakes

  • Tuning on one input. A prompt that works on your favourite example has been tested once.
  • Emphasis as a fix. Capitals and repeated warnings are a sign the instruction is unclear. Rewrite it and add the reason.
  • Examples that all look alike. The model copies whatever they share, including things you did not intend.
  • Pasting data with no boundary. If a document contains a sentence that reads like an instruction, an untagged prompt gives the model no way to tell the two apart.
  • Asking the prompt to supply facts. No wording makes a model know your pricing or your policy. Put the facts in the context.
  • Changing model without retesting. The vendors' own migration notes exist because prompts behave differently across versions.

Once single prompts are reliable, the next step is linking them: agentic AI workflows covers the five patterns for doing that.

Prompt engineering: FAQ

What is prompt engineering?

Prompt engineering is the work of writing instructions for a language model so that it produces what you need consistently, not just once. OpenAI defines it as writing effective instructions so a model consistently generates content that meets your requirements. In practice it means stating the task, the context, the format and a few examples clearly, then testing the prompt against real inputs.

Is prompt engineering still worth learning in 2026?

Yes, though the skill has changed. OpenAI, Anthropic and Google all still publish and update prompting guides for their current models. The old tricks, such as shouting in capitals or prefilling the start of the answer, are being retired: Anthropic says recent Claude models can overreact to aggressive wording and no longer accept prefilled responses. What remains is clear writing plus testing.

What is the difference between a system prompt and a user prompt?

The system prompt, which OpenAI calls the developer message, holds the standing rules: the role, the instructions, the examples and the format. The user prompt holds the input for this one request. OpenAI compares them to a function definition and its arguments, and states that developer messages are prioritised ahead of user messages.

What is few-shot prompting?

Few-shot prompting means including a handful of example inputs with the outputs you want, so the model copies the pattern. Zero-shot means no examples. Google recommends always including few-shot examples, Anthropic suggests three to five wrapped in example tags, and OpenAI advises showing a diverse range of inputs. Keep the format identical across examples, because the format is the main thing the model learns from them.

How long should a prompt be?

As long as it needs to be to remove guesswork, and no longer. None of the three vendors sets a recommended length. They do agree on order for long prompts: put documents and data first and the question last. Length is measured in tokens; Google gives a rule of thumb of about four characters per token, so 100 tokens is roughly 60 to 80 English words.

Do the same prompts work on ChatGPT, Claude and Gemini?

The fundamentals carry over: clear instructions, context, examples and a stated format help on all three. The details differ. OpenAI says its reasoning models do better with high-level goals while its GPT models want precise instructions. Google recommends leaving temperature at the default on Gemini 3. Anthropic recommends XML tags for structure. Retest a prompt whenever you change model.

Should I tell the AI to act as an expert?

A role helps, but one sentence is enough. Anthropic says setting a role in the system prompt focuses behaviour and tone and that even a single sentence makes a difference. OpenAI puts identity first in its suggested prompt structure. A role does not replace the rest: an expert persona with no context, examples or format still has to guess what you want.

Free · no card needed

Start with the free Starter Kit.

A unit economics calculator from AI SaaS Builder, plus four more working files.

Starter Kit5 files · free
All Access · all four programs · $99/mo

Prompts working in the chat window? Put them inside a product.

AI SaaS Builder, included in All Access, has a prompt engineering lesson in its Claude API module, then tool use and structured output, prompt caching, MCP servers and a research agent built step by step, followed by Supabase, Vercel and Stripe to ship it. The other three programs, weekly coaching and the community come with the same subscription.

See All Access: $99/mo →30-day money-back guarantee
Free

Stuck on a prompt that will not behave?

Post the prompt, one input and the output you wanted in the free Discord. A second reader usually spots the missing instruction faster than another rewrite does.