Sub topic 3
Deciding What Is Relevant
This chapter assumes you have basic programming experience in any language, that you use an editor or terminal, and that you have used an AI chat or coding assistant before. It builds on the idea that an assistant works only from the context it receives. Here you learn how to decide which pieces of that context belong in a request and which do not.
Why relevance is the central skill
An assistant has a limited amount of space for your request, and it pays attention to everything inside that space. Adding more text does not always help. Extra material gives the assistant more things to weigh, and some of it can pull the answer in the wrong direction.
Relevant context is information the assistant needs to produce a correct answer for this specific task. Irrelevant context is information that is true but does not change what a good answer looks like. Misleading context is information that looks relevant but is stale, wrong, or about a different problem.
Both extremes cause failures:
- Too little context. The assistant fills gaps with guesses. It may invent function names, assume a different library version, or solve a simpler problem than the one you have.
- Too much context. The important lines are buried. The assistant may follow a detail from an unrelated part of the code, or give a vague answer that tries to cover everything.
Your goal is the smallest set of context that still lets a careful colleague do the task without asking you questions.
A test for each piece of context
For every candidate piece of context, ask three questions.
- Would the answer change without it? If a competent person could give the same answer without seeing it, leave it out.
- Is it about this task? A file can be important to your project and still have nothing to do with the bug in front of you.
- Is it current? Code you changed an hour ago, or an error from before your last fix, can send the assistant after a problem that no longer exists.
If a piece passes all three, include it. If you are unsure, start without it. Adding a missing piece in a follow-up message is cheap. Untangling a muddled answer is not.
Working through an example
Take the small file used throughout this tutorial. It fails on an empty list.
def average(values):
return sum(values) / len(values)
print(average([]))Running it produces this traceback.
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 zeroSuppose your task is: "Make average return None for an empty list." Imagine the project around this file is large. It has a web server, a database layer, a test suite, a build script, and a README. Here is how the relevance test sorts the candidates.
| Candidate context | Include? | Reason |
|---|---|---|
| The `average` function | Yes | It is the code to change. |
| The error and traceback | Yes | It shows exactly how the failure happens. |
| The call `average([])` | Yes | It reproduces the failure. |
| The database layer | No | Nothing in the task touches it. |
| The build script | No | It does not affect the function's behavior. |
| The README | No | It does not change the answer. |
| Callers of `average` in other files | Maybe | Include them if returning `None` could break them. |
| The existing tests for `average` | Maybe | Include them if you want the assistant to keep them passing. |
Notice the "Maybe" rows. They depend on how much risk the change carries. If average is called in twenty places and each expects a number, the callers matter a great deal, because a None return value can cause a new TypeError downstream. If it is called in one place, they matter less.
Three kinds of relevance
It helps to separate what makes context relevant. Each kind answers a different question.
Relevance to the change
This context is the code you want edited or explained. It is almost always required. In the example, it is the average function.
Relevance to the evidence
This context shows the problem happening: error messages, failing test output, logs, or the input that triggers the failure. Without it, the assistant has to guess what "not working" means. The traceback above says the failure is a ZeroDivisionError on line 2, and that it is reached from line 4.
Relevance to the boundaries
This context tells the assistant what must not break. It includes function signatures other code depends on, tests that must keep passing, and style rules. These items are easy to forget because nothing is visibly wrong yet. The assistant cannot respect a constraint it has never been told about.
When you prepare a request, check all three kinds. Many weak requests include the change and the evidence but leave out the boundaries, and the assistant then makes a reasonable but unwanted change, such as renaming a function or adding a dependency.
Signs that you have included too much
Watch for these symptoms in the answer.
- The assistant changes code you did not ask about.
- The reply discusses several unrelated problems.
- The answer mentions details from a file that has nothing to do with the task.
- The answer is generic, as if the assistant could not tell which part mattered.
If you see these, remove material and ask again. A shorter request with a clearer focus often fixes the problem without any other change.
Signs that you have included too little
These symptoms point the other way.
- The assistant refers to functions, files, or variables that do not exist in your code.
- It asks which library version or language version you use.
- It solves a general version of your problem and ignores your specific setup.
- The proposed fix would break a caller or a test that you know about.
If you see these, add the missing facts. Name the version, the surrounding function, or the constraint, and ask again.
Practical heuristics
These rules of thumb help you decide quickly.
- Start from the failure and work outward. Begin with the line where the error occurs. Add the function that contains it. Add the code that produces its inputs only if the problem seems to originate there.
- Follow the data. If a bad value reaches the failing line, the code that created that value is relevant. Code that never touches it usually is not.
- Prefer exact text over summaries. A pasted error message is more useful than "it crashes with a math error." A summary hides details that you may not know are important.
- Describe what you leave out. If a function calls a helper you are not sharing, one sentence such as "
load_datareturns a list of floats" gives the assistant what it needs without the helper's code. - State what you already tried. A short note like "I checked that the list is empty because the filter removed everything" prevents the assistant from suggesting steps you have completed.
Common mistakes
- Pasting everything "just in case." This feels safe but dilutes the request. Choose deliberately instead.
- Sending an old error. After you change code, run it again and share the new output. An outdated traceback describes a program that no longer exists.
- Leaving out the goal. Context without a task forces the assistant to guess what you want. The task statement is covered in a later chapter, but keep in mind that context is only useful in relation to a goal.
- Trusting your own summary. If you describe a bug from memory, you may leave out the detail that explains it. When in doubt, share the original text.
- Forgetting constraints. If the function signature must not change, say so. The assistant cannot see your other callers.
Summary of the decision process
Use this short sequence each time you prepare a request.
- Write the task in one sentence.
- List the change: the code to be edited or explained.
- List the evidence: the error, output, or input that shows the problem.
- List the boundaries: signatures, tests, and rules that must hold.
- Remove anything that does not pass the three questions: would the answer change, is it about this task, is it current.
- Send the request, and add missing context only if the answer shows a gap.
Exercise
You are asked to make average in stats.py return None for an empty list. Your project also has db.py (database access), server.py (which calls average on user data), test_stats.py (tests for average), and a README.md. Which of these would you share along with stats.py and the traceback, and why would you leave out the others?
Show answer
Share test_stats.py, because it shows what behavior must keep working, and share the part of server.py that calls average, because returning None could break that caller. Leave out db.py and README.md. Neither changes what a correct answer looks like, so they would only add noise. If server.py is large, share only the lines around the call to average and describe the rest in a sentence.
Exercise
An assistant replies to your request with a fix that renames average to mean and adds a new third-party package. Which kind of relevance did your request most likely lack, and how would you repair it?
Show answer
It lacked relevance to the boundaries. The assistant was never told that the function name and the dependency list must stay the same. Repair the request by adding constraints such as "Keep the function name and signature, and do not add dependencies," then ask again.
Exercise
You fixed a bug an hour ago, but you still paste the original traceback into a new request about a different failure in the same file. What is the risk, and what should you do instead?
Show answer
The traceback is stale. It describes a failure that no longer happens, so the assistant may try to fix the old problem or mix it up with the new one. Run the code again and paste the current error output.