Fundamentals

Prompt engineering guide: a step-by-step method

A practical prompt engineering guide. Seven steps to go from a rough request to a tested, production-ready prompt, with a worked example at each step.

This guide is a method, not a list of tips. Follow the seven steps in order and you will end up with a prompt that states its task, carries the right context, returns a predictable format, and has been checked against real inputs.

The running example is a prompt that turns customer feedback into a product report.

Step 1: Write the objective as one sentence

Start with a single imperative sentence that names the outcome. If you cannot write it, the task is not defined yet.

Classify each piece of customer feedback by product area and sentiment.

Lead with a verb: classify, summarize, extract, draft, compare, review. A prompt that only describes material (“here is our feedback data”) forces the model to guess what you want done with it.

Step 2: Add the context the model lacks

List what a capable new colleague would need to know: who the output is for, what the product areas are, and what counts as negative.

The feedback comes from in-app surveys for a project management tool.
Product areas: Boards, Timeline, Reports, Integrations, Billing.
The report is read by product managers who decide what to fix next.

Include only context that changes the answer. Background that does not affect the output costs tokens and dilutes the instructions.

Step 3: State requirements and constraints

Turn expectations into a short list. Use numbers where a size is involved, and say what to do in the awkward cases.

Requirements:
- Assign exactly one product area per item. Use "Other" if none fits.
- Sentiment is one of: positive, neutral, negative.
- Quote the phrase that justifies the sentiment, 12 words at most.
- If an item is not in English, classify it and add "language": "<code>".

Prefer telling the model what to do over what to avoid. “Use plain language” works better than “don’t use jargon”, because a prohibition names the thing you want gone and gives no alternative.

Step 4: Define the output format

If code will read the answer, specify the format exactly. If a person will read it, specify the structure and the length.

Return a JSON array. Each element:
{"id": string, "area": string, "sentiment": string, "evidence": string}
Return only the JSON, with no commentary.

A missing output format is among the most common reasons for inconsistent results. The guide to structured output prompting covers schemas and validation.

Step 5: Separate instructions from data

Put variable input inside delimiters so the model cannot mistake it for instructions. This also blocks the simplest form of prompt injection.

<feedback>
{{feedback_items}}
</feedback>

Step 6: Add examples if the task needs them

If the rules are easy to state, skip examples. If the task depends on judgment, such as what counts as “neutral”, show two or three input and output pairs that cover the borderline cases. See zero-shot, one-shot, and few-shot prompting for how to choose them.

Step 7: Test, measure, and revise

Run the prompt on inputs that represent real use, including the awkward ones: empty input, very long input, mixed languages, and hostile text. Write down what fails, change one thing, and run again. This loop is covered in iterative prompt optimization and prompt evaluation.

Before you test against a model, remove the problems that do not need a model to find. The PromptFlowEngine prompt analyzer checks for a missing objective, vague wording, unquantified sizes, conflicting instructions, a missing format, and undelimited variables.

The finished prompt

You are a product analyst.

## Task
Classify each piece of customer feedback by product area and sentiment.

## Context
The feedback comes from in-app surveys for a project management tool.
Product areas: Boards, Timeline, Reports, Integrations, Billing.
The report is read by product managers who decide what to fix next.

## Requirements
- Assign exactly one product area per item. Use "Other" if none fits.
- Sentiment is one of: positive, neutral, negative.
- Quote the phrase that justifies the sentiment, 12 words at most.

## Output format
Return a JSON array. Each element:
{"id": string, "area": string, "sentiment": string, "evidence": string}
Return only the JSON.

## Input
<feedback>
{{feedback_items}}
</feedback>

A checklist to keep

Question If the answer is no
Does the first line say what to do? Add an objective.
Would a new colleague have enough context? Add audience, domain, and definitions.
Are sizes given as numbers? Replace “short” and “a few”.
Is the output format specified? Add a format and a length.
Is input separated from instructions? Wrap variables in tags.
Has it run on difficult inputs? Build a small test set.

For ready-made starting points that already pass these checks, see the prompt templates. For the habits behind the steps, continue to prompt engineering best practices.