Sub topic 1
Read the Error Before You Ask
Prerequisites
This chapter assumes basic programming, terminal or IDE use, and version control such as Git. You should also know how to run code and tests and have some experience with an AI assistant.
Read the Error Before You Ask
Read the error message and traceback before copying them into a prompt. A traceback is a record of the calls that led to the failure. Start at the bottom for the error type and message. Then find the first line that points into your code.
def average(values):
return sum(values) / len(values)
print(average([]))The final line is ZeroDivisionError: division by zero. The traceback also shows that len(values) is zero inside average. This gives you a useful first hypothesis: the function received an empty list.
Do not ask only, “Why does this fail?” State what the evidence says. The assistant should help test your hypothesis, not replace your reading.
Reproduce the Failure and Shrink It
Reproduce the failure with the same input and command. Then remove unrelated code until the smallest example still fails. This is a minimal reproduction. It makes causes easier to see and gives the assistant less irrelevant context.
Record the exact command, input, and environment. Include the language version, library versions, and operating system when they could affect behavior.
Gather the Context the Assistant Needs
Provide the relevant function, the complete traceback, the command you ran, and the expected and actual behavior. Ask for reasoning from the evidence before asking for a fix.
A useful prompt explains that average([]) should produce a clear input error, includes the unchanged traceback, and asks for the smallest safe change. Mention recent changes if they might matter.
Keep Secrets and Private Data Out of Prompts
Inspect code and output before sharing them. Remove passwords, access tokens, private keys, connection strings, customer data, and internal identifiers. Replace them with placeholders while preserving the behavior that causes the failure. If a secret appeared in a prompt, revoke or rotate it.
Exercise
What should you inspect first in a traceback?
Show answer
Read the final error type and message, then locate the relevant line in your code and form a hypothesis from that evidence.