Sub topic 3
Know Where Assistants Go Wrong
Assume you can read basic code, use an AI assistant, and run small programs locally. At this level, use the assistant to form hypotheses, then check those hypotheses against the project.
Know where assistants go wrong
An assistant may produce a fluent explanation that is still wrong. Common causes include:
- It guesses what an unfamiliar function or library call does.
- It overlooks a side effect, such as changing a global value or writing a file.
- It explains the usual behavior but misses a project-specific configuration.
- It assumes a particular Python, library, or operating-system version.
- It describes code that seems intended rather than code that actually runs.
Treat claims about execution, performance, security, and configuration as claims to verify.
Check the explanation against the code
Compare each important claim with the function body, its callers, and its tests. For the fib example, the assistant should explain that lru_cache stores results for previous arguments. You can check that claim directly:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
print(fib(30))
print(fib.cache_info())The result should be 832040. The cache information should report hits and misses, providing evidence that repeated calls reused stored results. For behavior that depends on a library, read that library's documentation. For behavior that depends on your application, write a small test or inspect an existing one.
Explaining code that spans many files
Do not paste an entire repository without a question. Start with the entry point and share only the relevant path:
- Name the behavior you want to understand.
- Include the entry function, its direct callers, and the types or configuration it uses.
- Add tests, interfaces, or documentation that constrain the behavior.
- Ask the assistant to identify missing context before reaching a conclusion.
This makes the explanation easier to audit and reduces exposure of private code.
Record what you learned
Keep a short note containing the behavior, important dependencies, evidence, and remaining questions. Add a concise comment only when it explains a non-obvious constraint. Update the note when the code changes.
Exercise
What should you do after an assistant claims that a decorator improves performance?
Show answer
Identify the claim, inspect the decorator's documentation and code behavior, then run a small benchmark or test that measures the relevant case.