What belongs in context?
8 min read
The model only knows what is in front of it
A language model does not look anything up while it answers. It reads the text it was given and writes the most likely continuation. Everything it learned in training is in its weights, but that knowledge ends at a cutoff date and it knows nothing about your customers, your policies or your files.
So the quality of an answer depends on two things. One is the model. The other is the text you put in front of it. Teams often spend weeks choosing a model and an hour on the context, then wonder why answers are wrong. Most wrong answers from a good model come from missing, buried or contradictory context.
The Context windowThe maximum number of tokens a model can process in its context. Depending on the model, the limit can include the answer as well as the input. is the limit on how much text fits in one request, counting both what you send and what the model writes back. Everything in this path is about spending that space well.
The six parts of a context
Almost every application builds its context from the same six parts.
| What it holds | Who supplies it | How often it changes | |
|---|---|---|---|
| Instructions | Role, rules, tone, output format | The developer | Rarely |
| Examples | Sample inputs with the right outputs | The developer | Rarely |
| Knowledge | Policies, documents, customer records | Retrieval or a lookup | Every request |
| History | Earlier messages in the conversation | The conversation | Every turn |
| Tool results | Output from searches, calculations and APIs | Tools the model called | Every step |
| Request | The user's current question | The user | Every turn |
Notice the split. Instructions and examples are written once and reused, so you can test them before launch. Knowledge, history and tool results arrive at run time, so they are where surprises come from. Most of the engineering effort goes into those three.
Assemble a context in code
The program below builds a small support context from named parts, then reports how large each part is. Labelling every part, here with a name in square brackets, keeps the context readable for you and for the model.
parts = {
"instructions": "You are a support assistant for Riverside Bikes. Answer only from the policy.",
"knowledge": "Policy: unused bikes can be returned within 30 days for a refund.",
"history": "Customer: I bought a bike on 2 March.",
"request": "Can I still return it on 25 March?",
}
context = "\n\n".join(f"[{name}]\n{text}" for name, text in parts.items())
print(context)
print()
for name, text in parts.items():
print(f"{name:<13}{len(text.split()):>3} words")
print(f"{'total':<13}{sum(len(text.split()) for text in parts.values()):>3} words")It prints:
[instructions]
You are a support assistant for Riverside Bikes. Answer only from the policy.
[knowledge]
Policy: unused bikes can be returned within 30 days for a refund.
[history]
Customer: I bought a bike on 2 March.
[request]
Can I still return it on 25 March?
instructions 13 words
knowledge 12 words
history 8 words
request 8 words
total 41 wordsThe assistant now has what it needs: a rule, a date and a question. It can work out that 25 March is 23 days after 2 March, which is inside the 30 days. Take away the policy and the same model has to guess. Take away the history and it cannot tell how long ago the purchase was. Each part earns its place by changing the answer.
Check that nothing essential is missing
A missing part rarely causes an error. The model just answers anyway, and the answer looks plausible. So check for the essentials in code before you send the request.
required = ["instructions", "knowledge", "request"]
def missing(parts):
return [name for name in required if not parts.get(name)]
print(missing({"instructions": "Be brief.", "knowledge": "30 day returns.", "request": "Can I return it?"}))
print(missing({"instructions": "Be brief.", "request": "Can I return it?"}))It prints:
[]
['knowledge']The second request has no knowledge, so the check reports it. At that point the application can search again, ask the user for more detail, or say that it cannot answer. Any of those is better than sending the question to the model with nothing to work from.
What does not belong
A fuller context is not a better one. Leave out anything that does not help with the current request.
- Unrelated history. A conversation about shipping adds noise to a question about warranty.
- Private records the user may not see. If a person cannot read a document, it must never enter their prompt, as the Lesson Metadata, filters and permissions in RAG explains.
- Duplicates and old versions. Two copies of a policy cost twice the space and can disagree.
- Instructions buried in data. A web page or email can contain text that tries to give the model orders. Treat retrieved text as material to read, not commands to follow.
The model does not warn you when the context is poor. It writes a fluent answer from whatever it was given, and fluency hides the gap.
Where this path goes next
The rest of this path follows the same loop. Decide what the model needs, budget the space, select and order the material, keep long tasks under control, and test each change on questions with known answers. For a wider view of the practice, read Anthropic's guide to context engineering for agents. The next Lesson, Context is a budget, covers how to spend the space.
Which part of a context changes on every request?
You are listing the six parts of a support assistant's context.
Instructions and examples are written once and reused. Knowledge, history and the request arrive at run time, so that is where surprises come from.
What should the application do when it finds no policy for the question?
The check reports that the knowledge part is empty.
A model answers fluently even with nothing to go on, so a gap must be caught in code before the request is sent.
Which item does not belong in the context?
A customer asks about a warranty. The history also holds a long chat about shipping.
Every part must change the answer. Unrelated history only adds noise and cost.
Your reading position is saved
0 of 11 complete
Lesson complete
What belongs in context?
Up next