Long context, and the ordering rule with a number on it
If you memorise one number from this entire course, make it this one.
For prompts of roughly 20k tokens and up, put the longform data at the TOP, above the query, above the instructions, above the examples. The docs claim that queries at the end can improve response quality by up to 30 percent.
That is unusual. Almost all prompting advice is qualitative. This one arrives with a percentage attached, which makes it the single most quotable and most examinable fact in the prompt-engineering domain. It will be on the exam in some shape.
Why it feels wrong
Every instinct says the opposite. If you handed a human 200 pages and a question, you would give them the question first so they know what to look for. Front-loading the ask is basic courtesy.
Closer to home: it is the opposite of how you write a function. Signature first, body after. Guard clauses at the top. Every convention you have for laying out code says state the contract before the detail.
Prompting does not work like that at this scale, and the guidance is explicit: data first, query last.
The exam trap writes itself. An option that says “put the question first so the model reads with purpose” is a perfectly reasonable-sounding distractor, and it is the one most people pick.
The document envelope
Long context also has a documented structure for the data itself, and it is more specific than “paste it in”.
<documents>
<document index="1">
<source>2024-q3-earnings.pdf</source>
<document_content>
...the actual text...
</document_content>
</document>
<document index="2">
<source>internal-pricing-memo.md</source>
<document_content>
...the actual text...
</document_content>
</document>
</documents>Three things are doing work here.
The index gives the model a stable handle. It can say “document 2” and you can resolve that to a real file.
The <source> element is separate from the content on purpose. Provenance is metadata, and mixing it into the body means the model has to guess which lines are the document and which are your labelling.
The <document_content> wrapper gives an unambiguous end marker for text you did not write and cannot predict. This is the same boundary argument from Module 1, and at 60k tokens of pasted-in material it stops being pedantry.
Ground answers in quotes first
The last piece of long-context guidance is a technique rather than a layout: have the model pull relevant quotes out before it answers.
Ask for the quotes, then the answer built from them. You get two things out of it. The model’s answer is anchored to text that actually exists in the context rather than to a plausible-sounding blend. And you get an audit trail: when the answer is wrong, you can see whether it retrieved the wrong passage or reasoned badly from the right one.
That distinction is most of debugging a retrieval system, and it is free if you ask for the quotes. It is also the single change here most likely to pay for itself in your own work this month, because it converts an unfalsifiable answer into one with a citation you can go and check.
What this costs you
Nothing, structurally. There is no long-context pricing premium: the tokens cost what tokens cost. The economics of long prompts are entirely a caching question, which is the next lesson.
Try it yourself
Where the query goes
You are building a prompt with 60k tokens of source documents plus a question about them. Where does the question go?
Show answer
Correct answer: C — At the end, after the longform data
For long context, put the longform data at the top and the query at the end. The docs claim queries at the end can improve response quality by up to 30 percent. Option 1 is the genuinely tempting one because it matches how a human would want the assignment framed before reading, and it is the intuition most people bring. The documented guidance is the opposite, and it is one of the few prompt-engineering claims that ships with a percentage attached.
Spot the bug in this prompt
A retrieval prompt, abridged. The envelope is correct and the tags are all closed properly. Something else is wrong.
<instructions>
Answer the question using only the documents provided.
</instructions>
<query>Which supplier raised prices in Q3, and by how much?</query>
<examples>
<example>...three worked examples, about 900 tokens...</example>
</examples>
<documents>
<document index="1">
<source>supplier-contracts-2024.pdf</source>
<document_content>...48k tokens...</document_content>
</document>
<document index="2">
<source>q3-price-changes.md</source>
<document_content>...12k tokens...</document_content>
</document>
</documents>What is the defect?
Show answer
Correct answer: C — The longform data belongs above the query, the instructions and the examples, and here it sits below all three
At roughly 20k tokens and above, the longform data goes at the very top: above the query, above the instructions, above the examples. This prompt has it last. Option 2 is the genuinely tempting distractor because it captures the famous half of the rule, the part everyone quotes, and stops there. Data-first is not only about the query; the examples and the instructions sit below the data too. Getting half the rule right is the most common way to get this question wrong.
The document envelope
Four element names and one attribute. This is the kind of detail that is trivially lookup-able and still worth holding, because you write it far more often than you look it up.
What is the documented XML structure for supplying multiple documents in a long-context prompt?
Reveal answer
An outer documents element. Inside it, one document element per source, each carrying an index attribute. Inside each document, a source element naming where it came from and a document_content element holding the text.
The threshold
There is a number attached to this guidance and a number attached to its payoff. This card is about the first one, the point where the advice switches on.
At roughly what prompt size does the long-context ordering guidance apply, and what changes?
Reveal answer
About 20k tokens and up. At that size, longform data moves to the top of the prompt, above the query, the instructions and the examples. Below that threshold the ordering matters much less and normal prompt structure applies.
What the big window costs
You move a feature from a 15k-token prompt to a 300k-token prompt. Same model, same output length, no caching in play. What happens to the input cost per call?
Show answer
Correct answer: A — It scales with the token count at the same rate, because there is no long-context surcharge
There is no long-context pricing premium. A token near the end of a huge prompt costs the same as a token near the start of a small one, so the bill goes up twentyfold purely because you sent twenty times as many tokens. Option 3 is the tempting one because usage tiers above a threshold are the standard shape for capacity products and it sounds like something you half-remember reading. The consequence matters: since the rate never changes, the only cost lever you have on long context is caching, which is the next lesson.
Grounding in quotes
Look at a retrieval-augmented prompt you have actually written. This one is a habit worth stealing for your own work regardless of the exam.
Your instructions ask the model to pull relevant quotes out of the supplied documents before it answers, rather than answering directly from the documents. If they do not, you have skipped the grounding step that makes long-context answers checkable.