What Is Context

What a model's context is, which sources feed into it, why a chat only seems to remember, and how missing context causes generic or wrong answers.

12 minLesson 1 of 8
On this page
  1. What the model knows from training and from context
  2. What goes into the context
  3. Why a chat seems to remember
  4. The same question with and without the needed context
  5. Pitfalls when deciding what goes into the context
  6. What this changes in practice
  7. Try it yourself
  8. Check yourself
  9. What to practise next

The context is all the text a language model reads when it handles one request. About your files, your company and your task, the model knows only what is in that text, because it keeps nothing from earlier requests. Most of the quality of an answer is therefore decided by what you and the application put into the context before the model starts to write.

Suppose you ask an assistant about your company's holiday policy and the policy is not in the context. The model does not tell you it is missing. It writes an answer from the general patterns it learned in training, and that answer can be fluent, plausible and wrong for your company.

What the model knows from training and from context

A model has two sources of knowledge. The first is training, which gave it language, general facts about the world and a sense of how code and documents usually look. Training knowledge is broad, but it stops at a fixed date and contains nothing private, such as your files, your internal rules or yesterday's news.

The second source is the context, which is the text sent with the current request. It is narrow, but it can be current and specific, and you control it. When an answer is generic, outdated or wrong about your situation, the usual cause is that the needed fact was not in the context and the model filled the gap from training. This is the main route to hallucinations, and it is why the answers in Prompting Basics improve when you add background.

What goes into the context

Your own message is only one part of what the model reads. The application stacks several sources into one block of text and sends that block as a single request.

the context instructions (system prompt) tool descriptions retrieved documents saved notes / memory conversation so far your new message model reply training knowledge general, frozen
One request: the application stacks several sources into one block of text, and the model reads all of it. Training knowledge is separate and does not change between requests.

To the model this is one long text that it reads from top to bottom, with markers showing who wrote each part. Each source has its own purpose and its own way of going wrong, so the next subsections take them one at a time.

Instructions

The instructions, usually called the system prompt, are written by whoever built the application. They give the model its role, its rules and its tone, and they are sent at the start of every request. Use them for things that should hold for the whole conversation, such as "answer only from the supplied documents". They fail when they grow into a long list of rules that contradict each other, because the model then follows some and quietly ignores others. System Prompts covers how to write them.

Tool descriptions

If the model can search the web, run code or call a service, the application describes each of those tools in the context, so the model knows what exists and how to ask for it. The results of tool calls are also added to the context afterwards. Every tool description takes space and gives the model another option to choose from, so an application with many overlapping tools makes worse choices than one with a few clear ones. See Tools and MCP.

Retrieved documents

For questions about private or recent information, the application can search a document collection and paste the best matches into the context. This is retrieval-augmented generation, covered in RAG Basics. It works when the search finds the right passages. It fails when the search returns the wrong ones, and then the model answers confidently from irrelevant text.

Saved notes

A memory feature stores facts from earlier sessions, such as your preferred language or the project you are working on, and loads the relevant ones into the context of a new chat. The model itself does not remember anything; the application is reading its notes back to it. Notes can go stale or be wrong, and the model will treat them as true. See Memory.

The conversation so far

The earlier messages in the chat are part of the context because the application resends them with every request. This is the source that makes a chat feel continuous, and the next section shows how it works.

Why a chat seems to remember

The model keeps nothing between requests. A chat feels continuous because the application stores the conversation and sends the whole of it again each time you write a message. The tracer below follows an order-taking assistant for a bakery over two turns, and then shows what happens in a new chat.

What the model reads on each callUse the arrows or ← → keys
request = [system]request += historyrequest += [new message]reply = model(request)history += [new message, reply]
  1. request
    0system: bakery orders
    history (kept by the app)
    turn
    1

    1Turn 1. Every request starts with the application's instructions, and the history is still empty.

  2. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    history (kept by the app)
    turn
    1

    2There is no history to copy, so the new message comes next. Lena has ordered 12 rolls for Friday.

  3. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    history (kept by the app)
    turn
    1
    reply
    noted

    3The model reads both items and replies that the order is noted.

  4. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    history (kept by the app)
    0user: Lena, 12 rolls, Fri
    1model: noted
    turn
    1

    4The application saves the message and the reply in its history. The model saves nothing.

  5. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    2model: noted
    history (kept by the app)
    0user: Lena, 12 rolls, Fri
    1model: noted
    turn
    2

    5Turn 2. Lena asks whether she can make it 20. The application rebuilds the request from the instructions and both saved messages.

  6. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    2model: noted
    3user: make it 20?
    history (kept by the app)
    0user: Lena, 12 rolls, Fri
    1model: noted
    turn
    2

    6The new message is added last. The word "it" can only mean the rolls, because turn 1 is in the text.

  7. request
    0system: bakery orders
    1user: Lena, 12 rolls, Fri
    2model: noted
    3user: make it 20?
    history (kept by the app)
    0user: Lena, 12 rolls, Fri
    1model: noted
    turn
    2
    reply
    20 rolls

    7The model answers that the order is now 20 rolls. It read four items to write one short reply, and the application then adds this turn to its history.

  8. request
    0system: bakery orders
    1user: make it 20?
    history (kept by the app)
    turn
    1

    8In a new chat Lena types the same question. The history is empty, so "it" refers to nothing, and the model has to ask what she means or guess.

1 / 8

The model did not forget Lena in the last step. It never remembered her, and it could only use her first message while that message was in the text it was given.

The code below is the application's side of the same process. The history list is the only memory, and it lives in the application.

// The app keeps the conversation. The model keeps nothing.
function buildRequest(system, history, newMessage) {
  return [
    { role: "system", content: system },
    ...history,
    { role: "user", content: newMessage },
  ];
}
 
const system = "You take orders for a small bakery.";
const history = [];
 
const first = buildRequest(system, history, "I'm Lena. 12 rolls for Friday.");
history.push(first.at(-1), { role: "assistant", content: "Noted: 12 rolls, Friday." });
 
const second = buildRequest(system, history, "Can I make it 20?");
console.log(second.length); // 4: system, two saved turns, new message
 
const freshChat = buildRequest(system, [], "Can I make it 20?");
console.log(freshChat.length); // 2: nothing says what "it" is
# The app keeps the conversation. The model keeps nothing.
def build_request(system, history, new_message):
    return (
        [{"role": "system", "content": system}]
        + history
        + [{"role": "user", "content": new_message}]
    )
 
system = "You take orders for a small bakery."
history = []
 
first = build_request(system, history, "I'm Lena. 12 rolls for Friday.")
history += [first[-1], {"role": "assistant", "content": "Noted: 12 rolls, Friday."}]
 
second = build_request(system, history, "Can I make it 20?")
print(len(second))  # 4: system, two saved turns, new message
 
fresh_chat = build_request(system, [], "Can I make it 20?")
print(len(fresh_chat))  # 2: nothing says what "it" is

A real application sends this list through an API, but the shape is the same. The list is rebuilt and sent again on every call, which also means that a long conversation makes every later request longer. The Context Window explains the limit on that length.

The same question with and without the needed context

The two prompts below ask the same question in almost the same words. The only real difference is that the second one contains the information needed to answer.

Missing contextIllustrative example. Real replies vary.
You
Is my flight affected by the strike?
Model
I don't have information about your specific flight. Strikes can affect airlines, airports or air traffic control. I'd recommend checking your airline's website or app for updates on your booking.
Context suppliedIllustrative example. Real replies vary.
You
Is my flight affected by the strike? Answer from the notice below only. My flight: leaves Thursday 07:40 from Terminal 2. <notice> Ground staff at Terminal 2 will strike from 06:00 to 10:00 on Thursday. Flights in that window may be delayed by up to 3 hours. Terminal 1 is not affected. </notice>
Model
Yes, probably. Your flight leaves at 07:40 from Terminal 2, which falls inside the 06:00 to 10:00 strike window. The notice says flights in that window may be delayed by up to 3 hours.

The first reply is what an honest model does when it has nothing to work with. Rewording the question would not have improved it, whereas adding the notice did. The instruction "answer from the notice below only" also matters, because it tells the model to prefer the supplied text over whatever it remembers from training.

Pitfalls when deciding what goes into the context

What this changes in practice

When an answer is wrong or generic, the first question to ask is what the model was given, before asking whether the model is capable enough. Read the full text that was sent, if your tool lets you see it, and check whether the fact the answer depended on is there.

When you write a request, include the facts the model cannot know: who the answer is for, what you have already tried, the text you are working on and the constraints that apply. Put the question and these facts in the same request instead of expecting an earlier chat to carry them. When you build an application, decide for each source in the figure what should go in, how it is kept up to date, and what gets removed when it stops being relevant. Context Engineering turns this into a method.

Try it yourself

Try it: What would it need to know

Someone asks an assistant, "Should I accept this meeting invite?" List what the model would need in its context to give a useful answer, and where each piece could come from (the user, a calendar, a document or an earlier conversation).

Show a sample answer

One reasonable list:

  • The invite itself, with its sender, topic, time and length. The user can paste it, or a calendar tool can supply it.
  • The user's calendar for that day, so the model can spot a clash. This comes from a calendar tool.
  • The user's priorities, for example that mornings are reserved for focused work this month. This comes from the user or from saved notes.
  • Who the sender is to the user, such as a manager, a vendor or a stranger. This comes from the user or a contacts lookup.
  • Whether the user is needed in the meeting, which depends on the agenda and on who else is attending. This comes from the invite or from the user.

Without these, the only answer the model can give is generic advice about meetings.

Check yourself

Quick check

In a long chat, the assistant correctly refers to something you said 10 messages ago. Why?

An assistant gives an outdated answer about your company's holiday policy. What is the most likely cause?

Which of these does the model not see unless the application adds it to the context?

What to practise next

The context has a size limit. The Context Window explains how much fits and what happens when it overflows, and Context Engineering shows how to choose what goes in.