Course contents
Anatomy of a Prompt
The six working parts of a prompt, how each one fails, what they cost in tokens, and the order vendors recommend when the input is long.
Most production prompts are built from the same six parts. Few prompts need all six, but naming them changes how you debug: when an output goes wrong, you ask which part failed instead of rewriting everything blind.
| Part | Its job | What goes wrong without it |
|---|---|---|
| Role | Sets focus, audience and tone in a sentence, usually in the system prompt | Right content in the wrong register |
| Task | Says what to do and what done looks like | A good answer to a different question |
| Context | Facts, audience, earlier decisions and the reasons behind rules | Confident claims about your product that aren't true |
| Input | The text to process, fenced in tags | Instructions hidden in pasted text get followed |
| Examples | Show the output shape and the hard judgment calls | Format drift and inconsistent edge cases |
| Output contract | The exact shape of the answer, including the empty case | Correct answers your code can't parse |
Match each symptom to the part of the prompt that failed.
Pick one on the left, then its partner on the right.
A prompt is a stream of tokens
Models read and bill in tokens, not words. A token is a chunk of text, often a whole word or part of one, and punctuation usually splits off on its own. Context limits, output caps and prices are all counted in tokens, so the size of each part matters.
Edit the text and watch the count. Try deleting the tags, or pasting in a paragraph of plain prose.
Move the controls and watch what changes.
In the widget, which kind of text packed the fewest characters into each token?
Order: long data first, question last
For long inputs, Anthropic and Google give the same advice: put the documents first and the instructions and question at the end. Anthropic reports that placing the query at the end improved response quality by up to 30% in its tests, especially with several documents. Google suggests a bridge after the data, such as “Based on the information above…”, followed by the specific task.
The role, standing rules and output format belong in the system prompt, which Gemini calls the system instruction. That layout also suits prompt caching, which bills a repeated prefix at a fraction of the normal price: the stable system prompt comes first, and the per-request documents and question follow.
SYSTEM
You are a contracts analyst for a 40-person software company.
You explain risks in plain English to founders who aren't lawyers.
USER
<documents>
<document index="1">
<source>msa_acme_2026.pdf</source>
<document_content>{{CONTRACT_TEXT}}</document_content>
</document>
</documents>
Based on the contract above:
1. Quote the clauses on termination and on the liability cap.
2. Explain each risk in two sentences.
If a topic isn't covered, write "Not in this contract."Put this long-document prompt in the order the vendors recommend.
- The documents, each in its own tags with a source line
- System prompt: role, audience and standing rules
- The task and the specific question
- A bridge line: “Based on the documents above…”
- What to say when the answer isn't in the documents
Fence the input
Anything a user pastes or a tool returns is data, not instructions, but the model can't tell unless you mark the boundary. Anthropic recommends XML tags with consistent, descriptive names, nested when the content has a hierarchy. Google says XML tags and Markdown headings both work, as long as you pick one and use it throughout the prompt.
For text that users paste into a chat, Anthropic's Opus 5.5 guide goes further: wrap each pasted block in <pasted_content> tags that carry the same short random ID on the opening and closing tag, and tell the model in the system prompt that instructions inside those tags weren't written by the user. Tags are plain text and can be imitated, so treat them as one guardrail among several. Module 6 covers the rest.
This triage prompt shipped last month. Find the three lines that cause trouble.
Plain-English definitions from the AI Coding Dictionary.