Sub topic 1
What Context Is and Why It Matters
Prerequisites
This chapter assumes you have:
- Basic programming experience in any language.
- Some experience with an editor or terminal.
- Used an AI chat or coding assistant at least a few times.
You do not need to know how language models work internally.
What context is
Context is everything the assistant can use when it writes an answer. It has two parts:
- The text you send: your question, pasted code, error output, and earlier messages in the conversation.
- Anything the assistant can read on its own, such as files it opens in your project or standing instructions that your tool loads automatically.
The assistant has no view of your screen, your editor, or your machine beyond that. If a fact is not in the context, the assistant has to guess it. Guesses are often plausible, which makes them easy to miss.
Why answer quality depends on context
Consider the small file used throughout this tutorial:
def average(values):
return sum(values) / len(values)
print(average([]))Suppose you send only this message: "My average function crashes. Fix it." The assistant does not know which function, which language, what "crashes" means, or what the fixed behavior should be. It may rewrite the function, invent a different bug, or ask questions. Each outcome costs you time.
Now compare a request that carries the right context:
Context: stats.py (attached), selection: the average function (lines 1-2).
Error: ZeroDivisionError: division by zero when average([]) is called.
Task: Change average so an empty list returns None instead of raising. Keep the function signature and do not change other code.This request names the file, points at the relevant lines, gives the exact error, and states the task and its limits. The assistant can answer it directly.
The difference is not cleverness or wording. The second request contains the facts needed to answer. A model that is good at coding still cannot recover facts you never gave it.
The main kinds of context
This tutorial covers three kinds of context you supply, plus the task that ties them together.
| Kind | What it is | Example |
|---|---|---|
| File | A whole file or several files | `stats.py` |
| Selection | A specific range of lines | The `average` function, lines 1-2 |
| Error | Output that shows what went wrong | A traceback ending in `ZeroDivisionError` |
| Task | What you want done with the above | "Return `None` for an empty list" |
Each kind answers a different question for the assistant. A file shows where the code lives and how it is written. A selection shows where to look. An error shows what actually happened. The task shows what you want.
Too little, too much, and the right amount
Context can fail in two directions.
- Too little: the assistant guesses. It may assume the wrong language version, the wrong library, or the wrong behavior.
- Too much: relevant facts are buried among irrelevant ones. The assistant may follow a detail that has nothing to do with your problem, or ignore the part that matters. Large inputs also use up the space the assistant has available, which a later chapter covers.
The goal is the smallest set of context that still lets someone else solve the problem without asking you anything. A useful check is to imagine handing your request to a colleague who has never seen your project. If they would need to ask "which file?" or "what was the error?", the request is missing context.
A common mistake: assuming the assistant sees what you see
You have your editor open, the failing test in a terminal, and a mental picture of the project. It is easy to write as if the assistant shares all of that. Typical symptoms:
- Saying "this function" or "the error above" when nothing was attached.
- Describing an error from memory ("it says something about division") instead of pasting it.
- Pasting a fix attempt without the original code, so the assistant cannot tell what changed.
When an answer seems oddly off, first ask what the assistant could actually see. The cause is often a missing file or a paraphrased error, not a weak model.
What comes next
The rest of the tutorial treats context as something you choose deliberately. You will learn how much the assistant can hold, how to decide what is relevant, and how to share files, selections, and errors. You will then learn how to state the task, combine everything in one request, and keep the result clean and safe. The last chapter covers checking answers and refining your context when the first attempt misses.
Exercise
A teammate sends this to an assistant: "The login function throws an error, can you fix it?" Nothing is attached. Name three pieces of context that are missing and say which kind of context (file, selection, error, or task) each belongs to.
Show answer
Possible answers: (1) The file containing the login function, which is file context. (2) The lines of the function that fail, or the part to change, which is selection context. (3) The exact error message and stack trace, which is error context. A fourth gap is the task: "fix it" does not say what correct behavior should be, such as returning an error code or showing a message. Any three of these four are correct.
Exercise
Why can a very long request with many pasted files give a worse answer than a short, focused one?
Show answer
Irrelevant material buries the facts that matter. The assistant may follow unrelated details or overlook the key lines, and large inputs also consume the limited space available for context. A focused request keeps only what is needed to solve the problem.