Sub topic 3
Deciding What Is Relevant
This chapter assumes you can read Python, use an editor or terminal, and have used an AI chat or coding assistant before. It builds on the idea that the assistant answers only from its context, and that context has a limited size. Here you learn how to decide what goes in.
Relevance is a test, not a feeling
Relevant context is anything the assistant needs in order to do the task correctly. Everything else is noise. Noise costs you in two ways. It uses up space in the context window, and it can pull the assistant toward details that have nothing to do with your problem.
A practical test is to ask one question about each piece of context: "If I removed this, could the assistant still get the answer right?" If yes, leave it out. If no, keep it.
Three questions to ask
Before you send a request, answer these in order.
- What is the task? A bug fix, a new feature, an explanation, and a rename each need different material.
- Where does the task happen? Find the specific function, file, or line where the change will be made or the failure appears.
- What does that code depend on? Look for the definitions, types, or calls the assistant must see to avoid guessing.
The answers set the boundary. Include the place where the work happens, plus the nearest things it depends on. Stop there.
A worked example
Take the small file used in this tutorial.
def average(values):
return sum(values) / len(values)
print(average([]))Running it produces this error.
Traceback (most recent call last):
File "stats.py", line 4, in <module>
print(average([]))
File "stats.py", line 2, in average
return sum(values) / len(values)
ZeroDivisionError: division by zeroThe task is to make average handle an empty list. Apply the three questions.
- The task is a small bug fix.
- The work happens in
average, lines 1-2. - The function depends only on built-in
sumandlen, so nothing else is needed.
The relevant context is the function, the error, and the task. Here is how different choices compare.
| Context you could send | Relevant? | Reason |
|---|---|---|
| The `average` function | Yes | It is where the change happens. |
| The `ZeroDivisionError` line | Yes | It names the failure and the cause. |
| The full traceback | Yes | It shows which call triggered the error. |
| An unrelated `utils.py` with 400 lines | No | Nothing in it affects `average`. |
| Your whole project folder | No | It buries the three lines that matter. |
| The last hour of chat about another bug | No | It can mislead the assistant. |
Too little and too much
Both mistakes lead to weak answers, but they fail in different ways.
- Too little context makes the assistant guess. It may invent a function signature, assume the wrong library, or fix a different problem than yours. Answers sound confident but do not fit your code.
- Too much context hides the important part. The assistant may edit code you did not ask about, or follow a pattern from an unrelated file.
A common mistake is sending a whole file "just in case." Include a whole file only when the task depends on how its parts fit together, such as reorganizing functions or adding a feature that touches several of them.
Signs you chose badly
- The answer changes code you did not mention. You probably shared too much, or the task was too loose.
- The answer refers to names that do not exist in your project. You probably shared too little.
- The answer solves a nearby problem. The error or the task description was missing or unclear.
Each sign points to a specific fix, which later chapters cover in detail.
Exercise
You want the assistant to add a type hint to one function in a 600-line file. The function calls a helper defined 200 lines above it, and the helper's return type decides the hint. What context do you send?
Show answer
Send the function and the helper's definition (or just its signature and return type), plus a one-line task. Leave out the rest of the 600-line file. The function is where the change happens, and the helper is the one dependency the assistant needs to avoid guessing the type.
Exercise
You paste a traceback, three unrelated files, and notes from yesterday's debugging session. The answer edits a file you never mentioned. Name the likely cause and one fix.
Show answer
The extra files and old notes gave the assistant material outside the task, so it acted on it. Remove everything except the failing code, the traceback, and a task that says which code may be changed.