Papa Programmer
Lesson 01 of 11

What belongs in context?

8 min read

Optional

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 holdsWho supplies itHow often it changes
InstructionsRole, rules, tone, output formatThe developerRarely
ExamplesSample inputs with the right outputsThe developerRarely
KnowledgePolicies, documents, customer recordsRetrieval or a lookupEvery request
HistoryEarlier messages in the conversationThe conversationEvery turn
Tool resultsOutput from searches, calculations and APIsTools the model calledEvery step
RequestThe user's current questionThe userEvery turn
The six parts of a context

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.

python
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:

text
[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 words

The 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.

python
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:

text
[]
['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.

Six partsInstructions, examples, knowledge, history, tool results and the request.
Fetch what changesKnowledge, history and tool results arrive at run time, so check them first.
Leave out noiseEach part must change the answer, or it does not belong.

Your reading position is saved

0%

0 of 11 complete

Contents

Learning tools