Chapter 2 of 6 · 4 practices · 3 min · 4-question quiz
Prompt structure and long context
A prompt that mixes instructions, documents and examples needs clear boundaries. These practices make each part easy for the model to find and hard to confuse.
Start: Separate instructions, context, examples and input with consistent delimiters4 practices in this chapter
- 1Separate instructions, context, examples and input with consistent delimitersWhen a prompt mixes several kinds of content, the model has to work out where each one starts and stops. Give it clear boundaries.
- 2Put long documents first and the question last, then confirm with testsWhere long context sits in a prompt changes results. Anthropic recommends placing long documents near the top, above the query, instructions and examples. Its guide reports that putting the query at…
- 3Label each document with its source and metadataWhen you pass several documents, the model needs to tell them apart and refer back to them. Anthropic's guide recommends wrapping each one in
<document>tags with<source>and… - 4Order prompt parts so the stable prefix can be cachedPrompt caching works on an exact prefix, so the order you choose also decides your cost and latency. OpenAI's guide says to put reusable content at the start of the prompt to benefit from caching.
Check yourself on this chapter
4 questions, right here once you are signed in. Your progress is saved as you read.