Automation9 min read

Prompt Engineering Best Practices from Official Guides

What Anthropic, OpenAI and Google's own prompting guides recommend: clear instructions, examples, XML tags, roles, reasoning models, chaining and evals.

By AI Agents DirectoryLast checked
Grey industrial equipment

The model vendors publish their own prompting guides, and they are a better starting point than collections of magic phrases: Anthropic’s prompting best practices, OpenAI’s prompt engineering guide plus its reasoning best practices, and Google’s prompt design strategies for Gemini. This article pulls out the techniques the three agree on, and flags the places where they give different advice.

Start with success criteria, not wording

Anthropic’s prompt engineering overview assumes you already have three things before you touch the prompt: a definition of success for your use case, a way to test against it, and a first draft. OpenAI makes a similar point from the other direction. Because model output is non-deterministic and even different snapshots of one model family can behave differently, it recommends pinning production apps to a specific snapshot and building an evaluation suite so you can see what changes when you edit a prompt or upgrade a model.

Be clear, specific and explain why

All three vendors open with the same idea. Anthropic suggests picturing Claude as a capable new hire with no background on your team’s conventions, and offers a simple test: if a colleague with little context would be confused by your prompt, the model probably will be too. Google’s guide frames it as giving the model clear, specific instructions plus any constraints, such as how long a summary should be.

Two refinements from Anthropic are worth adopting everywhere:

  • Give the reason behind a rule. Instead of a bare “never use ellipses”, Anthropic’s example explains that the text will be read by a text-to-speech engine that cannot pronounce them. The model can then apply the reasoning to cases you did not list.
  • Say what to do, not only what to avoid. Rather than banning markdown, describe the output you want, such as flowing prose paragraphs.

Anthropic also notes that its recent models are trained to follow instructions precisely. Asking “can you suggest some changes” tends to get suggestions; if you want the edits made, say “change this function”.

Before:

Summarize this support ticket.

After:

You are triaging tickets for a two-person support team.
Summarize the ticket below in at most three sentences for the on-call engineer.
State the product area, what the customer tried, and the exact error message.
If any of these are missing, write "not stated" rather than guessing,
because the engineer will act on this summary without reading the original.

<ticket>
{{TICKET_TEXT}}
</ticket>

The second version names the audience, length, required fields and a fallback with its reason, and keeps instructions apart from input.

Use examples, but know how many

Few-shot prompting means including a handful of input and output pairs so the model can copy the pattern. Every vendor endorses it, but the details differ:

Anthropic (Claude)OpenAIGoogle (Gemini)
Default stanceExamples are a dependable way to steer format and toneShow a diverse range of inputs with desired outputsRecommends always including few-shot examples
How manyThree to fiveA handfulExperiment; too many can cause overfitting
Reasoning modelsWorked examples shape how Claude thinksTry zero-shot first, add examples only if neededNot addressed separately
Formatting tipWrap them in <example> tagsPut them in the developer messageKeep the structure identical across examples

The common thread: make examples varied enough to cover edge cases, close to your real inputs, and consistent with your written instructions. OpenAI warns that when examples and instructions disagree, results can get worse.

Structure the prompt with tags or headings

Long prompts mix instructions, context, examples and user data. All three guides recommend delimiting them. Anthropic favours XML tags such as <instructions>, <context> and <input>, nested where the content has a hierarchy. OpenAI suggests a mix of Markdown headings and XML tags, and lays out a typical developer message as identity, instructions, examples, then context. Google says either XML-style tags or Markdown headings work for Gemini 3, but asks you to choose one style and stick with it inside a prompt.

Where to put long documents is a point of near-agreement. Anthropic advises placing long inputs near the top, above the question and instructions. Google says to supply the context first and ask the question at the very end, bridged with a phrase like “Based on the information above”. OpenAI says context usually sits best near the end of the developer message, while content you reuse across requests should go first so prompt caching can save cost and latency. For more on managing long inputs, see our guide to context window optimization.

Roles and system prompts

Each API has a privileged place for standing instructions, and each vendor suggests putting the role there:

  • Anthropic: the system parameter. Even a one-sentence role focuses Claude’s tone and behaviour.
  • OpenAI: the instructions parameter or developer messages, which take priority over user messages. OpenAI compares developer messages to a function definition and user messages to the arguments.
  • Google: the System Instruction, where Google suggests putting critical constraints, the persona and output format rules (or at the very start of the user prompt).

Anthropic’s own example is short:

client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    system="You are a helpful coding assistant specializing in Python.",
    messages=[
        {"role": "user", "content": "How do I sort a list of dictionaries by key?"}
    ],
)

Chain-of-thought versus reasoning models

This is where older advice has aged the most. “Think step by step” was a standard trick, but all three vendors now ship models that reason internally before answering.

  • OpenAI separates its reasoning models, such as o3 and o4-mini, from GPT models such as GPT-4.1. It tells you to keep prompts for reasoning models simple and to avoid chain-of-thought instructions, saying they can sometimes hinder performance. GPT models, by contrast, do better with precise, explicit instructions. OpenAI’s analogy: a reasoning model is a senior colleague you hand a goal; a GPT model is a junior one who needs explicit steps.
  • Anthropic says Claude 4.6 and later models use adaptive thinking, and that thinking cannot be switched off on Claude Fable 5.1, Claude Fable 5 or Claude Opus 5.5. It finds that a general nudge such as “think thoroughly” often beats a hand-written step list. Manual chain-of-thought is kept as a fallback for when thinking is off, and on several current models a request to write reasoning out in tags may be declined.
  • Google says Gemini 2.5 and 3 series models generate internal thinking, so you generally do not need the model to spell out its reasoning in the answer. For hard problems, a plain request like “Think very hard before answering” can help, at the cost of extra thinking tokens.

In practice: pick the model type first, then decide how much procedure to write. For a reasoning model, describe the goal and the success criteria. For a fast non-reasoning model, spell out the steps.

Sampling settings have moved too. Google now says Gemini 4 and Gemini 3.6+ ignore custom temperature, top_p and top_k, and it recommends keeping them at defaults on earlier Gemini 3 models.

Break big tasks into a chain

When one prompt is doing too much, split it. Google describes three patterns: one prompt per instruction, sequential chains where each output feeds the next prompt, and parallel runs over parts of the data whose results you then combine. Anthropic says its models now handle most multistep reasoning internally, but chaining is still worth it when you need to inspect intermediate output or force a fixed pipeline. Its most common pattern is self-correction: one call drafts, a second reviews the draft against criteria, a third revises. Because each step is its own API call, you can log and test them separately.

Chains often include tool calls; our comparison of function calling and tool use covers how OpenAI and Anthropic structure that loop.

Before (one overloaded prompt):

Read these 40 customer reviews, find the main complaints, rank them,
write a product memo and draft replies to the angriest customers.

After (a chain):

Step 1: For each review in <reviews>, output JSON with "complaint" and "severity" (1-3).
Step 2: Given the JSON list, group complaints by theme and count them.
Step 3: Using the grouped themes, write a one-page memo for the product lead.
Step 4: For reviews with severity 3, draft a reply in our support tone (see <tone_guide>).

Each step now has an output you can check with code before moving on.

Test prompts like code

A prompt change is a behaviour change, so treat it like one. Anthropic’s evaluation guide recommends test sets that mirror your real task mix and include edge cases, automated grading wherever possible, and more test cases with automated scoring rather than fewer hand-graded ones. It ranks graders by speed and reliability: code-based checks first, then a model acting as a judge with a clear rubric (and thinking enabled so it reasons before scoring), and human review only where needed. OpenAI describes the same loop in three steps: define the task as an eval, run it on test inputs, then analyze and iterate.

Two OpenAI changes matter if you build on its platform. It recommends keeping production prompts in your application code, with tests and normal code review, and it is deprecating reusable prompt objects, with v1/prompts scheduled to shut down on November 30, 2026. Its hosted Evals platform is scheduled to shut down on the same date, so plan to run evals in your own code or another tool. For metric choices such as exact match and model-graded scoring, see our guide to LLM evaluation metrics, and for tracing and test tooling browse the evaluation and monitoring category.

Where the vendors disagree, in short

  • Examples: Google says always include them; OpenAI says start without them on reasoning models; Anthropic suggests three to five.
  • Reasoning: none of the three wants step-by-step instructions on a model that already thinks, but Anthropic still documents manual chain-of-thought when thinking is off.
  • Delimiters: Anthropic leans on XML tags; OpenAI and Google accept XML or Markdown, and Google asks for consistency within a prompt.
  • Context order: Anthropic and Google put long context before the question; OpenAI puts per-request context late and reusable content early for caching.

Because each guide is tuned to its own models, a prompt that works well on one vendor is a starting point on another, not a finished product. Run it through your evals before you switch.

#Prompt engineering#LLMs#Claude#OpenAI#Gemini
AI

Written by AI Agents Directory

Editorial team

Facts in this guide are checked against official documentation and repositories, which are linked in the article.