Techniques · 10 min read

8 prompt engineering techniques, with examples

Zero-shot, few-shot, step-by-step reasoning, roles, decomposition, self-critique, structured output and delimiters, each with a copy-ready example.

Prompt engineering techniques are repeatable patterns for getting more reliable answers from language models. None of them are secret tricks; they are ways of giving the model better information or a better process. This guide covers the eight techniques that matter most in everyday work, explains when each one helps, and gives an example you can adapt. If you are new to prompting, start with our framework for writing AI prompts, then come back here.

TechniqueBest for
Zero-shotClear, common tasks
Few-shotMatching a style, label set or format
Step-by-step reasoningMath, logic, multi-factor decisions
Role promptingExpert vocabulary and priorities
DecompositionLarge tasks with several stages
Self-critiqueCatching errors and unmet requirements
Structured outputResults that feed other tools
Delimiters and XML tagsSeparating instructions from material

Zero-shot prompting: a clear instruction, no examples

Zero-shot means asking for the result directly without showing any examples. Modern models handle a wide range of tasks this way, so it should be your default. It works best when the task is common (summarize, translate, classify by sentiment) and when you are precise about the output.

Classify the sentiment of each customer review below as Positive, Negative
or Mixed. Return one line per review in the format: number - label.

1. Fast delivery, but the box was crushed.
2. Exactly what I needed. Would buy again.
3. Stopped working after two days.

If zero-shot answers are inconsistent (different labels, drifting formats, wrong level of detail), that is the signal to add examples.

Few-shot prompting: teach by showing

Few-shot prompting includes a handful of input/output pairs before the real input. The model infers the pattern: your labels, your tone, your formatting. Two to five examples are usually enough. Make them varied, so the model learns the rule rather than copying one example, and keep them in the exact format you want back.

Turn product features into one-line benefits for busy parents.

Feature: Dishwasher-safe lid
Benefit: One less thing to scrub after dinner.

Feature: Holds 1.5 liters
Benefit: Enough soup for the whole family in one go.

Feature: Locks with one click
Benefit: No spills in the car on the way to practice.

Feature: Keeps food hot for 6 hours
Benefit:

A common mistake is using examples that are all the same length or topic. The model then assumes length and topic are part of the rule. Vary everything except the thing you want copied.

Step-by-step reasoning (chain of thought)

For problems with several steps, such as calculations, scheduling, comparisons with trade-offs or debugging, asking the model to work through the problem before answering can reduce mistakes. You can ask for visible reasoning or, if you only want a clean answer, ask it to reason first and then present just the conclusion.

A team of 4 people each works 6 focused hours a day. A project needs about
180 focused hours, and one person is on leave for 3 of the working days.

Work through this step by step: calculate the available hours per day,
account for the leave, and estimate how many working days the project takes.
Then give the final answer on its own line, starting with "Answer:".

A note on reasoning models: some current models already think internally before answering, and their providers say explicit "think step by step" instructions are unnecessary for them. With those models, describe the goal and constraints clearly and let them reason on their own; save the step-by-step instruction for standard chat models or for when you need to see the working.

Role prompting: borrow an expert's point of view

A role tells the model which expertise, vocabulary and priorities to apply. "You are a tax accountant" and "You are a startup founder" will review the same budget very differently. The role works best when it is specific and paired with an audience, because expertise only helps if the answer is pitched at the right level.

You are a senior UX researcher who has run usability tests for e-commerce
checkouts. Review the checkout steps below and list the five issues most
likely to cause abandoned carts, ordered by impact. For each, explain the
problem in one sentence and suggest one fix. Write for a small shop owner
with no design background.

Steps:
1. Cart page with a coupon field at the top
2. Mandatory account creation
3. Shipping costs shown only on the final step
4. Payment form with 14 fields

Roles do not grant knowledge the model does not have, and they do not make facts more reliable. Treat them as a way to set perspective and tone, not as a quality guarantee.

Decomposition: break big tasks into stages

Asking for a complex deliverable in one shot ("write my whole marketing plan") tends to produce shallow coverage of everything. Decomposition splits the job into stages and handles each one separately, either in a single prompt with numbered steps or across several messages, where the output of one step becomes the input of the next (often called prompt chaining).

Message 1:
List the 5 main questions a first-time buyer has before choosing a
standing desk. One line each, no answers yet.

Message 2:
For each question, write a 2-sentence answer for a beginner. Keep the
numbering.

Message 3:
Using the questions and answers above, draft a buying-guide outline with
an H2 for each question and one comparison table.

Decomposition also lets you review and correct each stage before moving on, which is much easier than fixing a long final answer.

Self-critique: ask the model to check its own work

Self-critique adds a review pass. After a draft, the model compares its output with your requirements and revises. It is particularly useful when you have several constraints that are easy to miss, like word limits, mandatory points or banned phrases.

Write a 120-word product announcement for our new offline mode.

Requirements:
- Mention that it works on Android and iOS
- Include one concrete use case
- No exclamation marks
- End with a link placeholder [LINK]

After writing, check the draft against each requirement, list any that
are not met, and output a corrected final version.

Self-critique catches format and requirement errors well. It is less reliable for factual errors, because a model can confidently confirm its own mistakes. For facts, check sources yourself.

Structured output: ask for a precise format

When an answer feeds a spreadsheet, a script or another prompt, ask for a strict structure: a Markdown table with fixed columns, CSV, or JSON with named keys. Describe the schema and say what to do with missing data, so the output stays parseable.

Extract the events from the email below. Return valid JSON only, no
commentary, as an array of objects with these keys:
"title" (string), "date" (YYYY-MM-DD or null), "location" (string or null).
If a field is not mentioned, use null rather than guessing.

Email:
"""
Reminder: team lunch moves to Thursday the 14th at Rosa's. Also, the
quarterly review is still pending a date.
"""

Many APIs now offer a dedicated structured-output or JSON mode that enforces a schema. In a regular chat window, a clear schema plus "valid JSON only" is usually enough. Our image to JSON prompt tool applies the same idea to image descriptions.

Delimiters and XML tags: separate instructions from material

When a prompt mixes instructions with pasted content (an article, a contract, customer messages), the model can confuse the two. Delimiters such as triple quotes, Markdown headings or XML-style tags draw clear boundaries. They also make it easy to refer to parts of the prompt by name. Anthropic explicitly recommends XML tags for Claude, and other models handle them well too.

<instructions>
Compare the two policies below. Produce a table with columns:
Topic, Policy A, Policy B, Practical difference. Then add a 2-sentence
recommendation for a team of 10 remote employees.
</instructions>

<policy_a>
[paste first policy]
</policy_a>

<policy_b>
[paste second policy]
</policy_b>

Tag names do not need to follow a special vocabulary; descriptive names work. What matters is consistency: open and close each tag, and refer to the same names in your instructions.

Combining techniques

Real prompts usually mix several techniques: a role, delimited material, a few examples, a structured output and a self-check. You do not have to assemble that by hand every time. The AI prompt generator builds role, context, task, requirements and format sections automatically, and its Expert mode adds an example slot plus a quality-check list. Choose Claude as the target and it wraps each section in XML tags. To see which techniques an existing prompt is missing, run it through the prompt checker, and look up unfamiliar terms in the prompt engineering glossary.

Frequently asked questions

What is the difference between zero-shot and few-shot prompting?

Zero-shot gives only an instruction. Few-shot adds a few worked examples of input and output before the real input, so the model can copy the pattern. Start zero-shot and switch to few-shot when the output format or style is inconsistent.

Does "think step by step" still help?

With standard chat models it can improve multi-step problems such as calculations and planning. Some reasoning models already deliberate internally, and their providers advise against adding that instruction. For those, focus on a clear goal and constraints.

Are XML tags only for Claude?

No. Anthropic recommends them for Claude, but XML-style tags are simply clear delimiters, and other models generally follow them well. Markdown headings and triple quotes do the same job; pick one style and use it consistently within a prompt.

How many examples should a few-shot prompt include?

Usually two to five. More examples cost more tokens and rarely help unless the task has many categories. Varied examples teach the rule better than many similar ones. You can estimate the added length with the token counter.

Related tools