Tutorial
Prompting fundamentals: clear tasks, examples and formats
How to write a good prompt: frame the task, say who the output is for, show an example and specify the format, so a model's answers are useful and repeatable.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Most disappointing answers from a language model come from prompts that leave out something a human colleague would have asked about: who the output is for, what good looks like, and what shape it should come back in. This tutorial walks through one realistic task and improves the prompt in four passes. By the end you will have a reusable prompt template and a habit for spotting what is missing.
You can follow along in any chat assistant. The last step shows the same prompt sent from code, because that is where repeatability starts to matter.
The task we will improve
You have a page of raw customer feedback from a product survey and you want a summary for the weekly product meeting. Here is the first attempt most people write:
Summarise this feedback.
[paste 40 survey comments]
Try it. You will probably get a tidy paragraph that sounds reasonable and tells you very little. It might lead with whatever theme appeared first, mix praise with bug reports and skip the one comment that mentions a data-loss bug. Nothing is wrong with the model. The prompt did not say what the summary is for.
1. State the job, the reader and the purpose
A good prompt answers three questions before it asks for anything:
- What is the job? “Summarise” is a verb, not a job. “Find the three problems that most affect retention” is a job.
- Who will read the result? A product manager skimming in a meeting needs different output from an engineer triaging bugs.
- What will they do with it? If the summary feeds a prioritisation decision, it needs counts and severity, not adjectives.
Second pass:
I'm a product manager preparing for Thursday's prioritisation meeting.
Below are 40 free-text answers to "What almost made you stop using the app this month?"
Find the recurring problems. For each one, tell me how many comments mention it
and quote one representative comment word for word. Put anything that sounds like
data loss or a security issue at the top, even if only one person mentioned it.
This is already far better, and notice that nothing in it is a trick. It is the brief you would give a new colleague.
2. Separate instructions from material
When a prompt mixes your instructions with pasted content, the model has to guess where one ends and the other begins. Long pasted text can also contain sentences that look like instructions (“Please ignore the previous message…”). Wrap the material in clear delimiters. XML-style tags work well with every major model, and Anthropic’s prompting guidance recommends them:
<feedback>
1. The sync kept failing on my phone and I lost two days of notes.
2. Too many notifications, I turned them all off.
...
</feedback>
Using only the comments inside <feedback>, find the recurring problems...
Delimiters also let you refer to the material by name (“the comments inside feedback”), which reduces confusion when the prompt grows.
3. Show an example of the output you want
Describing a format in words works up to a point. Showing it works better. One or two examples of the output (often called few-shot prompting) pin down length, tone and structure in a way adjectives cannot.
Format each problem like this example, and nothing else:
### Sync failures (7 comments)
Severity: high, two people mention losing data.
> "The sync kept failing on my phone and I lost two days of notes."
A few practical rules for examples:
- Make examples realistic but not copied from the real input, or the model may treat them as answers.
- If you give more than one, vary them. Three examples that all have exactly two bullet points teach the model that everything has two bullet points.
- Keep examples short. Their job is to show shape, not content.
4. Specify the format and the edges
The last pass handles what happens at the edges: empty input, ambiguous comments, things the model should not do.
Rules:
- Count a comment towards a problem only if it clearly describes that problem.
- If a comment fits no group, list it under "Other" rather than forcing it in.
- Do not suggest solutions. The meeting decides those.
- If fewer than 5 comments mention anything, say so instead of inventing themes.
Each rule here exists because a model will otherwise make a reasonable but unwanted choice. “Do not suggest solutions” stops the helpful extra section you did not ask for. “Say so instead of inventing themes” gives the model a permitted way out, which is the most effective guard against made-up answers. Models are much less likely to fabricate when the prompt explicitly allows “I don’t know” or “not enough data”.
The finished prompt
Put together, the prompt reads like a short brief:
I'm a product manager preparing for Thursday's prioritisation meeting.
The comments below answer "What almost made you stop using the app this month?"
<feedback>
{paste comments here}
</feedback>
Using only the comments inside <feedback>, find the recurring problems.
For each problem give the number of comments that mention it and quote one
representative comment word for word. Order by severity: anything that sounds
like data loss or a security issue goes first, even with a single mention.
Format each problem exactly like this:
### Sync failures (7 comments)
Severity: high, two people mention losing data.
> "The sync kept failing on my phone and I lost two days of notes."
Rules:
- Count a comment only if it clearly describes that problem.
- Comments that fit no group go under "Other".
- Do not suggest solutions.
- If fewer than 5 comments mention anything, say so instead of inventing themes.
Run both versions on the same feedback and compare. The difference is not that the second prompt is longer. Every added line removes a decision the model would otherwise make on your behalf.
5. Run it from code so it is repeatable
Once a prompt works in a chat window, moving it into a script makes it repeatable, versionable and testable. This example uses the Anthropic Python SDK. Install it and set your key first:
pip install anthropic
export ANTHROPIC_API_KEY="your-key"
# summarise_feedback.py
from pathlib import Path
import anthropic
SYSTEM = """You help product managers make sense of customer feedback.
You only use the material you are given, you quote exactly, and when the data
is too thin to support a conclusion you say so."""
TEMPLATE = """The comments below answer "What almost made you stop using the app this month?"
<feedback>
{feedback}
</feedback>
Using only the comments inside <feedback>, find the recurring problems.
For each problem give the number of comments that mention it and quote one
representative comment word for word. Order by severity: data loss or security first.
Format each problem exactly like this:
### Sync failures (7 comments)
Severity: high, two people mention losing data.
> "The sync kept failing on my phone and I lost two days of notes."
Rules:
- Count a comment only if it clearly describes that problem.
- Comments that fit no group go under "Other".
- Do not suggest solutions.
- If fewer than 5 comments mention anything, say so instead of inventing themes."""
client = anthropic.Anthropic()
def summarise(feedback: str) -> str:
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=4000,
system=SYSTEM,
messages=[{"role": "user", "content": TEMPLATE.format(feedback=feedback)}],
)
return "".join(block.text for block in response.content if block.type == "text")
if __name__ == "__main__":
print(summarise(Path("feedback.txt").read_text(encoding="utf-8")))
Two details are worth noticing. The stable part of the instructions moved into the system parameter, which is where you describe the role and standing rules. The per-run material goes in the user message through a template, so you can change the feedback without touching the instructions. Keep the template in version control and you can see exactly which wording produced which output.
Common pitfalls
Asking for everything at once. “Summarise, prioritise, suggest fixes and draft an email” produces four mediocre answers. Split the job into steps and feed each output into the next prompt.
Vague quality words. “Make it concise and professional” means different things to different readers. Give a length (“under 150 words”) or an example instead.
Fixing one bad output by adding a rule. If you add a new rule every time something goes wrong, the prompt turns into a pile of special cases that contradict each other. When an output is wrong, first ask what information the model was missing. Often the fix is context, not a rule. That is the subject of the context engineering tutorial.
Trusting the counts. Language models are unreliable at exact counting over long lists. If the numbers matter, ask the model to label each comment with a category and count the labels in code or a spreadsheet. The structured outputs tutorial shows how.
Role-play as a substitute for a brief. “You are a world-class analyst” adds little on its own. Describing the reader, the purpose and the format does the real work. A short role line in the system prompt is fine; it just isn’t the important part.
Check your prompt
Before you send a prompt that matters, run through this list:
- Could a new colleague start the job without asking a question?
- Is the pasted material clearly separated from the instructions?
- Have you shown the output format, ideally with one example?
- Does the model have a permitted way to say “not enough information”?
- If you need exact numbers, are you counting in code rather than trusting the model?
Next steps
- Read Context engineering basics to learn what the model should see beyond the prompt itself.
- Get machine-readable answers with Structured outputs.
- Keep the prompt patterns cheat sheet open while you practise.
- Measure whether a prompt change actually helped with Write your first LLM eval.
- Adjust these habits for thinking models in how to prompt reasoning models.
- Follow the topic end to end with the prompt and context engineering learning path.
- Let an optimiser tune a prompt against a metric, and compare it with hand-tuning, in optimise a prompt automatically with DSPy.
Covers
Check your understanding
Prompting fundamentals quiz
Check that you can frame a task, use examples well and ask for an output format you can rely on.
6 questions · pass mark 70%
Review
Related
- Context engineering techniques: what the model should see
What to put in a model's context at each step, what to leave out, and how instruction files, retrieval and tools fit.
- Get reliable JSON from an LLM with structured outputs
Describe the output as a schema, let the provider enforce it, validate it with Pydantic AI or the AI SDK, and handle failures.
- Prompt patterns cheat sheet
Copyable prompt patterns for Claude, ChatGPT and Gemini: briefing, examples, output formats, long documents, checking the work and avoiding made-up answers.
- Context window
The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.
- Prompting reasoning models
What changes when a model thinks before it answers: write goals instead of steps, choose an effort level, use fewer examples and check the answer properly.