Sub topic 2
Sharing a Selection
Assume you know basic programming, can use an editor or terminal, and have used an AI coding assistant. Give the assistant the smallest context that still explains the problem.
Share the Relevant Selection
Share a whole file when the task depends on imports, shared state, or several related functions. Otherwise, share the relevant selection and identify its file and line range.
A selection should include enough surrounding code to show inputs, outputs, and nearby dependencies.
# stats.py
def average(values):
return sum(values) / len(values)
print(average([]))Do not paste an isolated line such as return sum(values) / len(values) without explaining where it came from. The assistant may miss how the function is called.
Share Errors and Stack Traces
Copy the complete error output when possible. A stack trace is a report of the calls that led to a failure. It usually includes the file, line number, call chain, and exception type.
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 zeroKeep the command, input, and first error occurrence. Do not replace the traceback with “it crashes.” The exact exception often determines the fix.
Tell the Assistant What to Do
State the task after the context. Include the desired behavior and constraints. This prevents the assistant from guessing whether you want an explanation, a fix, or a redesign.
Context: stats.py, 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.A focused request combines the selection, error, and task:
Use constraints such as “keep the public function signature,” “change only this file,” or “explain the trade-off.” If the answer is vague, add the missing input, expected output, or constraint instead of pasting unrelated files.
Exercise
What should you provide when an assistant must diagnose a failure in one function?
Show answer
Provide the file and selection, the complete traceback with its input, and a task stating the desired behavior and constraints.