The parts of a prompt (role, context, task, and format)
Learn the parts of a prompt (role, context, task, format, and examples) and how to combine them, with ready-to-copy examples you can adapt.
A good prompt isn't magic text: it's a well-built request. Once you understand the parts of a prompt, you stop writing blind and start knowing what's missing when an answer goes wrong. In this article we take a prompt apart piece by piece (role, context, task, format, and examples), see what each one is for, and how to put them together without overwriting.
If you haven't written your first prompt yet, start with the guide on how to write a prompt and come back here afterward.
The parts of a prompt according to the official guides
The three big AI providers describe very similar structures:
- Google, in its help page about Gems, talks about four areas: persona (the role it should take on), task, context, and format. It notes that you don't need all four, but using some of them helps.
- OpenAI, in its prompt engineering guide, suggests organizing instructions into identity, instructions, examples, and context, usually in that order.
- Anthropic, in its best practices for Claude, has sections on being clear and direct, giving context, using examples, separating sections, and assigning a role.
Based on that overlap, we use five pieces here. They don't always all appear, or always in the same order, but it's worth checking them one by one.
1. Role: the perspective the AI should answer from
The role tells the AI what perspective to adopt: "act as an editor," "you're a high school math teacher," "answer like an accountant explaining things to someone with no financial background."
Anthropic explains that assigning a role focuses Claude's behavior and tone, and that even a single sentence makes a difference. Google frames it the same way for Gems: tell it what role to play and how to respond.
An example from the catalog: Dale claridad a cualquier texto (bring clarity to any text) starts with "Act as a copy editor" and right away says for what audience and with what tone.
What the role does not do is replace context. "Act as a nutritionist" without saying your age, your habits, or your goal still gets you generic advice.
Before: Act as an expert and give me tips on saving money.
After: Act as a financial advisor who explains things in plain words to people who have never kept a budget.
2. Context: what only you know
Context is the information the AI doesn't have and needs: what the result is for, who will read it, what country you're in, what you've already tried, what data it should use.
It's the piece people forget most, and the one that matters most. Anthropic recommends explaining the reason behind your instructions, because with that information the model understands your goals better and gives more precise answers. Google asks you to provide the information the model needs instead of relying on generic answers.
Some questions to find the missing context:
- What am I going to use this answer for?
- Who's going to read or hear it?
- What specific data do I have (numbers, dates, names, texts)?
- What conditions in my country or situation change the answer?
Context: I live in {{city and country}}, I earn {{monthly income}}, and I have two credit card debts. I want to stop using my card for everyday expenses. I've never kept track of my spending.
3. Task: what it has to do, with a clear verb
The task is the heart of the prompt. It should start with an action verb and say exactly what you expect: summarize, compare, draft, fix, classify, explain, suggest.
Anthropic advises that if you want the model to do more than strictly what you asked, you should ask explicitly instead of expecting it to infer it. And when order matters, it recommends giving instructions as numbered steps.
Before: Help me with my budget.
After:
1. Suggest five spending categories that make sense for my situation.
2. Suggest a percentage of my income for each one.
3. Tell me which debt I should pay off first and why.
4. Format: how you want to get the answer
The format defines the shape of the result: a list, a paragraph, a table, an email, a script, a word count, sections. Google mentions it as a core part of a good prompt: specify whether you want a table, a bulleted list, a sentence, or a paragraph.
Limits also go here: maximum length, tone, what it shouldn't include. A practical tip from Anthropic: say what to do instead of what not to do. Instead of "don't use bullet points," write "answer in flowing paragraphs."
Format: a table with three columns (category, percentage, example expense) and below it a paragraph of 80 words max with the recommendation about the debts. Friendly tone, no jargon.
5. Examples: show what you expect
When style or shape really matters, one example is worth more than any explanation. Anthropic describes examples as one of the most reliable ways to steer the format, tone, and structure of the answer. Google goes further and recommends always including examples in prompts.
Examples should resemble your real case and be varied, so the AI doesn't copy a detail you didn't want. There's a risk: if you give too many, the model can stick to them so closely that it loses flexibility, as Google's guide warns. We go deeper into this technique in prompting techniques made simple.
Example of the tone I'm looking for:
"You spend 20% on eating out. If you bring it down to 12%, you'll have enough for the card's minimum payment without touching the rent."
What a complete prompt looks like
Let's put all five pieces into one prompt. The labels "Role," "Context," "Task," and "Format" aren't required; we include them so you can see each part.
Role: Act as a financial advisor who explains things in plain words.
Context: I live in {{city and country}}, I earn {{monthly income}}, and I have {{debts I have}}. I've never kept track of my spending and I want to stop using my card for everyday expenses.
Task:
1. Suggest five spending categories for my situation.
2. Suggest a percentage of my income for each one.
3. Tell me which debt I should pay off first and why.
Format: a table with category, percentage, and example; below it, a paragraph of 80 words max about the debts. If you're missing any information to make a good recommendation, ask me before answering.
This prompt fits on one screen and leaves almost nothing to the imagination. If you want a tested one for this case, check out Un presupuesto doméstico que puedas comprobar (a household budget you can double-check).
Keep the parts clearly separated
When a prompt mixes instructions with a long text (a document, an email, meeting notes), the AI may get confused about where your request ends and the material begins. All three guides recommend separating the sections:
- OpenAI suggests using Markdown headings and lists, and XML-style tags to mark where each piece of content starts and ends.
- Anthropic explains that XML-style tags, like
<instructions>or<context>, help Claude interpret prompts that mix instructions, context, examples, and data without ambiguity. - Google recommends clear delimiters and using a single style per prompt.
In practice, something like this is enough:
Summarize the notes below into five action items, each with an owner and a date.
<notes>
{{paste the meeting notes here}}
</notes>
If you want a tested prompt for this case, Reuniones que terminan en acciones (meetings that end in action) turns your notes into decisions and an action table with owners and dates.
Where does each part go?
Order matters less than clarity, but there are two recommendations backed by the providers:
- With long texts, put the question at the end. Anthropic says it's best to put long documents at the top and the query at the end, and that in its tests this improved answer quality by up to 30%, especially with multiple documents. Google gives the same advice for Gemini: all the context first, and the specific question or instruction at the end.
- What doesn't change goes at the top; what changes goes at the bottom. OpenAI suggests keeping variable context near the end of the prompt.
Common mistakes with the parts of a prompt
- Only a role, no context. "You're a marketing expert" and nothing else.
- A task with two or three requests mixed together. Better to number them or split them into separate messages.
- No format. The AI picks the length and shape, and it almost never matches what you need.
- Examples that don't resemble your case. The AI copies what it sees.
There are more common slip-ups (and their fixes) in common mistakes when writing prompts.
Frequently asked questions
What are the parts of a prompt?
The most useful ones are five: role, context, task, format, and examples. Google sums up the first four as persona, task, context, and format, and notes you don't always need all of them.
Do I have to include a role?
No. It helps guide the tone and focus, but a prompt with no role and good context works better than one with a role and no details.
How many examples should I include?
It depends on the task. Anthropic suggests three to five examples for best results when format matters; its blog also suggests starting with one and adding more only if the result still isn't right.
Do I have to write the labels "Role," "Task," "Format"?
You don't have to. They help you organize your thinking and help the AI tell the parts apart, but a well-written prompt in paragraphs works just as well.