MAX guide 12 min read

Prompt Engineering Examples: Weak and Better Prompts for Five Developer Tasks

Max holds a sheet of paper in each hand, glances sideways with a slight smile, beside a prompt-to-JSON-answer sketch

What do good prompt engineering examples look like?

Good prompt engineering examples show one task twice: a weak prompt (the text you send the model) that leaves the output format (the answer’s shape) open, and a better one that states the task, marks the input and fixes that format; in three of the five examples it also shows a sample answer.

Use them to get answers your code can parse, such as a JSON triage note from a bug report. We wrote the prompts for this guide and did not run them.

Prompt engineering is writing what you send a language model so the answer comes back in a shape your code can use. It starts once you can call a model and comes before testing and versioning.

This guide is its hands-on side; three explainers cover which technique to use, the parts of a prompt, and when wording is not enough.

The running example: a bug report

Your team gets bug reports through a web form. Each should become a triage note for the issue tracker: a one-line summary, a severity (critical, major or minor) and the affected component, as JSON. The reports here are made up:

The dashboard export downloads an empty CSV file. Copying the table by hand works.

Sent with “Triage this bug report”, the answer can open with “Sure! Here’s a triage note” and a severity of “High”. The prompt never said what the answer looks like.

What you need

An API key or a chat window. A model call (API call) is one request: prompt in, answer out.

Where we name a source, it is vendor advice or a published result, not a test of these prompts. Before you ship, test on your own inputs (prompt testing) and record changes (prompt versioning).

Step 1: a bug report becomes a JSON triage note

Weak ({report} is filled in by your code):

Triage this bug report: {report}

It never names the keys, the allowed severity words or JSON, and the report runs straight into the instruction.

Better:

Turn the bug report below into a triage note for our issue tracker.

Answer with one JSON object and nothing else. Use exactly these keys:
- "summary": one line that says what is broken
- "severity": "critical", "major" or "minor"
- "component": the part of the app the report is about, or "unknown"

Severity:
- critical: users lose data, or nobody can finish the task
- major: a feature is broken, but there is a way around it
- minor: looks or wording only

<example>
<report>The Save button on the profile page does nothing in Firefox. Chrome works.</report>
<note>{"summary": "Profile Save button does nothing in Firefox", "severity": "major", "component": "profile page"}</note>
</example>

<report>
{report}
</report>

The note you want back:

{"summary": "Dashboard export downloads an empty CSV file", "severity": "major", "component": "dashboard export"}

Three parts that the vendors’ guides recommend: a fixed output format (Anthropic’s guide), tags such as <report> around the input (OpenAI’s guide), and one example (a sample input with its wanted answer); a few such examples make it few-shot prompting.

Better prompt: a fixed format, tags around the report, one example.

Step 2: a long bug thread becomes a release note

Weak:

Summarize this thread: {thread}

It never says for whom, so the answer can retell the whole thread, wrong guesses included.

Better:

Write one release-note entry from the bug thread below.
The readers are users of our app, not developers, so use no internal names, ticket numbers or code.

The entry has two sentences:
1. What was broken, as the user saw it.
2. What works now.

Leave out the discussion and the guesses that turned out wrong.
If the thread does not say the bug is fixed, write only: NOT FIXED YET

<thread>
{thread}
</thread>

The difference: a named reader (our advice), a reason after the first rule, and a description of what to write instead of a list of what to avoid; Anthropic’s guide recommends the last two. For threads longer than the context window (all the model reads in one call, counted in tokens, pieces of words), see context window management.

Step 3: a log line becomes fields

Weak:

What's important in this log line? {line}

“Important” is your call, and key names can drift (service, then app), breaking your parser.

Better:

Extract fields from the log line below. Answer with one JSON object with these keys:
- "time": the timestamp exactly as written
- "level": "ERROR", "WARN" or "INFO"
- "service": the service name
- "request_id": the value after req=, or null if there is none
- "message": the rest of the line

<example>
<line>2026-11-27T09:14:02Z ERROR image-resizer req=8f3a timeout after 30000 ms</line>
<fields>{"time": "2026-11-27T09:14:02Z", "level": "ERROR", "service": "image-resizer", "request_id": "8f3a", "message": "timeout after 30000 ms"}</fields>
</example>

<example>
<line>2026-11-27T09:15:40Z WARN search-api slow query on index products</line>
<fields>{"time": "2026-11-27T09:15:40Z", "level": "WARN", "service": "search-api", "request_id": null, "message": "slow query on index products"}</fields>
</example>

<line>
{line}
</line>

The difference: two unlike examples, one without a request id (our advice). Without examples this is zero-shot (instruction only). Anthropic asks for examples that cover edge cases; OpenAI’s guide for its reasoning models warns that examples disagreeing with the instructions may produce poor results.

Step 4: a code diff gets checked for one kind of bug

Weak:

You are a senior engineer. Review this diff. {diff}

The role says who to be, not what to look for, so style notes can bury the bug. See role prompting.

Better:

Check the diff below for one kind of problem only: a file, network connection or
database connection that is opened and not closed on every path, including error paths.

First, inside <check> tags, go through each function the diff changes and write
down what it opens and where it closes it.
Then, inside <answer> tags, list each problem: the file, the line, and one sentence
on the path that leaks. If there is no problem, write NONE.

<diff>
{diff}
</diff>

The difference: one narrow question and a chain-of-thought step (the model writes its steps before the answer), Anthropic’s fallback for when Claude’s built-in thinking setting is off. OpenAI says asking its reasoning models (models that work through steps by themselves) to think step by step is unnecessary, so on such a model we would delete the “First” line.

Step 5: a diff becomes a commit message

Weak:

Write a commit message for this diff. {diff}

It can narrate every line, in Markdown, in no format your team uses.

Better:

Write a commit message for the diff below, in the format our team uses.
The first line is type(scope): what changed, in the imperative, under 72 characters.
After a blank line, write two or three sentences on why the change was made.
Write plain text only.

Two messages from our history show the style:

<example>
fix(export): send the CSV header before the rows

The dashboard export wrote rows before the header, so some spreadsheet apps opened an empty sheet.
</example>

<example>
feat(search): add a filter for closed issues

Users asked to hide closed issues. The filter stays off until they turn it on.
</example>

<diff>
{diff}
</diff>

The difference: examples from your history, and plain-sentence rules: Anthropic says matching the prompt’s style to the wanted output steers formatting. If your app sends fixed rules as a system message (instructions sent before the user’s text), put them there; see system prompts.

Common mistakes

  • No output format. The format can change from call to call.
  • Examples that disagree with the instruction. priority in the example, severity in the text.
  • Task mixed with data. OpenAI’s guide says XML tags help mark where one piece of content begins and ends.
  • Too many examples. Anthropic suggests 3 to 5; Google warns that too many can make the model copy them too closely.

If you only wanted weak and better prompts, you can stop here.

JSON output: when the prompt is enough

For small JSON, a format line is often enough. For complex schemas, Google’s Gemini guide recommends structured output mode: a JSON Schema (a machine-readable list of keys and types) goes with the call.

  • OpenAI: in a Responses API call, the request field text.format with type: "json_schema" and strict: true (OpenAI’s guide).
  • Anthropic: the request field output_config.format with type: "json_schema"; the older output_format is deprecated (Anthropic’s page).

Neither means “valid every time”: OpenAI applies the schema only to finished answers, so your code still handles refusals (the model declines) and cut-offs (the answer stops early). More in structured output.

What the published measurements say

The advice above has published research next to it. None of it measured our prompts. Each result holds for its own models, tasks and year, and models from 2020 to 2025 are not the models you call today.

The vendors’ own before-and-after pairs. Anthropic’s guide rates “NEVER use ellipses” as less effective than “Your response will be read aloud by a text-to-speech engine, so never use ellipses since the text-to-speech engine will not know how to pronounce them.”

It also suggests “Your response should be composed of smoothly flowing prose paragraphs” instead of “Do not use markdown in your response.” Step 2 uses both moves once.

Examples raise accuracy without retraining. In the GPT-3 paper (Brown et al., 2020), the largest GPT-3 answered trivia questions with 64.3% accuracy and no examples, and 71.2% with a few (as many as fit into its small context window). Anthropic suggests 3 to 5 examples for current Claude models.

Examples teach the shape more than the labels. Min et al. (2022) tested GPT-3 and other models on classification and multiple-choice tasks. Randomly swapping the labels (each example’s wanted answer) in the examples “barely hurts”; the label set, the kind of input and the format mattered more.

For step 1, our reading is that the severity list and the shape of the note carry much of the weight. Keep the labels correct anyway: this is a 2022 result on older models.

Small format changes move results. Sclar et al. (2024) changed only the format of few-shot prompts (separators, spacing, casing), never their meaning. With GPT-3.5-Turbo across 320 formats and 53 tasks, the gap between the best and worst format reached 56 accuracy points on one task; the median gap was 6.4 points.

Google’s Gemini guide also asks for one consistent format across all examples.

Forcing JSON can cost reasoning. Tam et al. (2024) asked models to solve math word problems in free text or with a prompt that asked for JSON, averaged over nine prompt wordings. gpt-3.5-turbo scored 76.6% in free text and 49.3% in JSON.

In another condition, JSON mode on a letter puzzle, every gpt-3.5-turbo answer put the “answer” key before the “reason” key, so the model answered before it reasoned. With gpt-4o-mini and a JSON schema the gap was small (94.57 vs 91.71), and on classification tasks JSON helped.

For the triage note, whose severity field is a classification, our reading is that JSON is the safer case. For the diff check, our advice is to keep the reasoning in text first (the <check> block), or to put a reason key before the verdict key.

OpenAI’s own test of the schema mode. In its 2024 launch post, OpenAI reported that gpt-4o-2024-08-06 with Structured Outputs scored 100% on its evals of complex JSON schema following, while the older gpt-4-0613 scored under 40%. It is a vendor-run test that compares two different models, so it shows the mode works on that eval, not that it never fails.

Step-by-step adds little on reasoning models. The Prompting Science Report 2 from Wharton’s Generative AI Labs (Meincke et al., 2025) compared “Think step by step” with “answer directly” on 198 hard multiple-choice science questions, 25 runs each.

Reasoning models moved by about 3 points either way: o3-mini and o4-mini up, Gemini 2.5 Flash down, while requests took 20% to 80% longer.

The authors add that telling a non-reasoning model to give only the answer can hurt, because it stops the model reasoning first.

On Claude 4.6 and newer, the old prefill trick is gone. Anthropic’s guide says prefilling (writing the start of the model’s reply yourself, such as {, to force JSON) returns an error on Claude 4.6 models and newer; use structured outputs instead. Its list of models that support structured outputs starts at the Claude 4.5 models (Sonnet, Opus and Haiku).

A template to copy

Fill the angle brackets, keep the tags, and run it on a few real inputs before you trust it.

<One sentence: what goes in, what comes out, and who reads the result.>

Answer with one JSON object and nothing else. Use exactly these keys:
- "<key>": <what it holds; list the allowed values if there is a fixed set>
- "<key>": <what it holds>, or null if the input does not say

<Each rule on its own line, with its reason.>
<What to write when the input does not fit the task.>

<example>
<input><a real input, typical of your traffic></input>
<output><the exact answer you want for it></output>
</example>

<example>
<input><a real input with the edge case you see most often></input>
<output><the exact answer you want for it></output>
</example>

<input>
{input}
</input>

When it breaks: when the answer needs facts the model cannot see, such as the rest of your codebase for a diff check or your team’s past severity calls for a triage note. Better wording does not give the model facts it cannot see.

Adding them is context engineering (choosing everything the model reads besides your request), and for coding agents context engineering for code shows how.

Cheat sheet

The article on one page: open it full size, save it or share it.

Cheat sheet: what the better prompt adds in five developer tasks, common prompt mistakes with fixes, a template to copy
PNG

AI-assisted content, human-reviewed. Images AI-generated. Editorial Standards · Our Editors