Sub topic 8
Know where assistants go wrong
This chapter assumes you can read Python, have used a chat or editor assistant, and can run small snippets locally. It covers the kinds of mistakes assistants make when they explain code, so you know which claims to distrust.
Why fluent answers can still be wrong
An assistant predicts likely text. It does not run your code or look up the library version you use. An explanation can therefore read well and still be false. The tone stays confident whether the claim is solid or invented, so tone tells you nothing about accuracy.
Common failure modes
| Failure mode | What it looks like | Why it happens |
|---|---|---|
| Invented details | A parameter, function, or flag that does not exist | The name looks plausible given similar libraries |
| Version drift | Describes behavior from an older or newer release | Training data mixes many versions |
| Missing context | Guesses what a helper or caller does | It sees only the code you pasted |
| Overgeneralizing | "This makes it fast" with no limits stated | Common advice gets applied to your case |
| Wrong tracing | An off-by-one error or wrong count in a step-by-step walkthrough | Simulating execution in prose is error-prone |
| Agreeing with you | Confirms a wrong guess in your question | Models tend to go along with the framing |
A worked example
Suppose you asked about this function:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)A typical answer says the decorator stores results so each value is computed once. That is correct. The same answer may add a claim like "so this works for any n." That claim is overgeneralized, and you can test it:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
try:
fib(5000)
except RecursionError:
print("RecursionError: caching does not remove recursion depth limits")
print(fib(30))
print(fib.cache_info())With a cold cache, fib(5000) recurses about 5000 levels deep before any result is stored. That exceeds Python's default limit of 1000, so it raises RecursionError. The cache speeds up repeated work but does not change the call depth. The last line prints CacheInfo(hits=28, misses=31, maxsize=None, currsize=31), which matches the idea that each value from 0 to 30 is computed once.
Spotting risky claims
Not every sentence in an answer carries the same risk. Sort claims by how they could be checked.
Watch for these warning signs:
- Specific names, such as parameters, config keys, or error messages, that you cannot find in your code or the docs.
- Words like "always," "never," or "guaranteed" about behavior that depends on configuration.
- References to files, functions, or callers that you did not paste.
- Numeric claims, such as "runs in O(n)" or "uses 3 calls," given without a trace.
- A walkthrough whose final value differs from what you get when you run the code.
Reducing the chance of errors
You cannot remove these failures, but your prompt can make them easier to catch:
- State the language and library versions you use.
- Ask the assistant to separate what it is certain of from what depends on version or configuration, as the example prompt in this tutorial does.
- Ask it to say when it is guessing about code it cannot see.
- Ask for claims you can test, such as "give me a call to run that would confirm this."
When the assistant is most likely wrong
Be most careful in these situations:
- The code uses a recent or little-known library.
- Behavior depends on runtime state, such as environment variables, data, or concurrency.
- The code is long and the assistant summarizes it from memory of the beginning.
- Your question includes an assumption. Ask neutral questions instead of "this is thread-safe, right?"
The next chapter covers how to check an explanation against the code itself.
Exercise
An assistant explains a decorated function and says, "The cache makes this safe for any input size, and it only keeps the most recent 128 results." You see @lru_cache(maxsize=None) in the code. Identify two problems with the claim and one way to check each.
Show answer
First, the 128 limit is wrong for this code. maxsize=None means the cache is unbounded and never evicts entries (128 is the default only when you write @lrucache with no maxsize argument). Check by reading the decorator arguments and the functools documentation, or by calling cacheinfo() and confirming maxsize=None. Second, "any input size" is overgeneralized. A recursive function still hits Python's recursion limit on a cold cache, so fib(5000) raises RecursionError. Check by running that call. Unbounded growth in memory is also a concern, which you can see by watching currsize grow in cache_info().