Manage context and break down tasks
Lay out long documents for the best results, ground answers in quotes, and chain prompts for complex work.
- Order long-context prompts: documents first, question last
- Ground answers in verifiable quotes
- Split complex work into a chain of checkable prompts
When a prompt includes long material - contracts, transcripts, several reports - layout matters. Anthropic’s best practices recommend:
- Long documents at the top, the instructions and question at the end - in their tests, queries at the end improved quality by up to 30% on complex, multi-document inputs.
- Each document in its own
<document>tag with<source>and<document_content>. - Ground the answer in quotes: ask for the relevant passages first, then the answer based on them. Quotes are easy to check against the source.
Try it
Up to 15 XPBudget the context
A research assistant must answer a question from three long reports. Try the window sizes: what has to give when everything doesn’t fit? (Then think about whether retrieving only the relevant sections would be better than truncating.)
Using 4,520 of 8,000 tokens (1,500 reserved for the answer) · the full conversation is 25,020 tokens.
- Instructions400
- Report A (2024)7,000
- Report B (2025)9,000
- Report C (2026)6,000
- Earlier chat2,500
- Question120
Prompt chaining
Some tasks are better as several prompts, each with one job and an output you can inspect - prompt chaining. The most common pattern is self-correction: draft → review against criteria → refine. Because each step is a separate call, you can log, test and branch at every stage.
Try it
Up to 15 XPA draft-review-refine chain
Step through a chain that writes release notes. Predict the marked step.
Key takeaways
Long documents first, question last; tag each document with its source.
Ask for supporting quotes before the answer, and check them.
Chain prompts when steps need inspection: extract → draft → review → refine.
Lesson quiz
6 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write Python
Write Python in the editor and run it against sample inputs. Python runs locally in your browser using a WebAssembly runtime.
Lay out a long-context prompt
Lines before --- are documents: source|text. The line after is the question. Print:
1<documents>
2<document index="1"><source>SOURCE</source><document_content>TEXT</document_content></document>
3…
4</documents>
5
6First quote the passages relevant to the question in <quotes> tags, then answer in <answer> tags.
7
8Question: QUESTION- Two reports
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Verify quoted evidence
Line 1 is the source document. Each following line is a quote a model claims is from it. Collapse runs of whitespace in both, then print found: QUOTE if the quote appears exactly in the source, otherwise NOT FOUND: QUOTE. Finish with verified N of M quotes.
- One paraphrase slips in
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…