Sub topic 10
Common failure modes and how to spot them
This chapter assumes you can write and run tests in at least one language and have used a chat or editor-based AI assistant. You have already seen how goals, context, constraints, and examples shape a prompt. Here you learn what goes wrong even with a decent prompt, and how to notice it quickly.
Why failures look convincing
An assistant produces text that is likely to follow your prompt. It does not run the code unless you give it a tool to do so. A wrong answer therefore reads as fluently as a right one. Confident tone tells you nothing about correctness. The checks you learned in the verification chapter are what separate good output from bad.
The common failure modes
| Failure mode | What it looks like | Typical cause |
|---|---|---|
| Invented API | A function or parameter that does not exist in the library | Missing version or context |
| Wrong version | Code that works on another release but fails on yours | Version not stated |
| Ignored constraint | Third-party import when you said standard library only | Constraint buried or vague |
| Scope creep | Unrequested rewrites, renamed functions, extra features | No limit on what to change |
| Edge-case gaps | Passes the obvious case, fails on empty or odd input | No examples of edge cases |
| Plausible but wrong logic | Reads well, returns wrong values | Goal not testable |
| Stale or drifting context | Later answers contradict earlier decisions | Long conversation |
Spotting each one
Invented APIs and wrong versions
Look at every import and every method call you do not recognize. Check them against the official documentation for the version you use. An AttributeError or ImportError on first run is the usual symptom. Paste the exact error back into the next prompt, along with the version.
Ignored constraints
Read the imports and compare them to your constraint list. A quick search is enough:
grep -nE "^(import|from) " slugify_module.pyIf you asked for the standard library only, every line should name a standard module.
Scope creep
Always ask for a diff, then read it. Lines that change code you never mentioned are a warning sign. In the next prompt, state what must not change, for example "Do not modify any function other than slugify."
Edge-case gaps
Code can pass your examples and still fail on inputs you did not list. Try the awkward cases yourself. Here is a quick probe for the slugify function from earlier chapters:
import re
def slugify(text: str) -> str:
text = text.strip().lower()
text = re.sub(r"[^a-z0-9]+", "-", text)
return text.strip("-")
for sample in ["", "!!!", "Café au lait", "a" * 5 + "---" + "b"]:
print(repr(sample), "->", repr(slugify(sample)))The output shows that "Café au lait" becomes "caf-au-lait". The accented letter is dropped. That is correct for the stated "plain ASCII" context, but it would be a bug if titles could contain accents. The failure is in the prompt's context, not only in the code. Empty and symbol-only input return an empty string, which may or may not be what you want. Decide, then add an example for it.
Drift in long conversations
After many turns, the assistant may forget a constraint from the first message. Restate the key constraints when you notice contradictions, or start a fresh conversation with a clean, complete prompt.
A habit that catches most failures
- Run the code before reading it closely.
- Run tests that you wrote or approved, not tests the assistant wrote to match its own code.
- Read the diff for changes outside your scope.
- Try three inputs you did not put in the prompt: empty, very large, and unusual characters.
Exercise
An assistant returns a function that imports a third-party library, although your prompt said "standard library only." Tests pass. Name the failure mode, say how you would detect it, and say how you would fix the prompt.
Show answer
This is an ignored constraint. Passing tests do not catch it, because the tests check behavior, not imports. You detect it by reading the import lines, for example with grep. To fix it, repeat the constraint in the next prompt, put it in a clearly labeled Constraints line, and ask the assistant to rewrite the function using only the standard library and to list the modules it imports.
Exercise
You asked for a small change to one function. The response renames two other functions and adds a logging feature. What is this failure called, and what should you add to the next prompt?
Show answer
This is scope creep. Add an explicit limit such as "Change only the function named parse_row. Do not rename or modify anything else," and ask for the output as a diff so you can review every changed line.