Lesson 30 of 1570
When AI Writes Buggy Code — How to Read It Critically
The AI will hand you code that looks right but isn't. Here are the most common bugs and the habits that catch them before they bite.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1Confident and Wrong
- 2hallucination
- 3off-by-one
- 4fake APIs
Concept cluster
Terms to connect while reading
Section 1
Confident and Wrong
Here is the single most important thing to know: AI-generated code can be completely convincing and completely broken. The code compiles, reads smoothly, and does not match reality. Your job is to assume this happens and check for it.
The big five AI coding bugs
- 1Fabricated APIs: calling a function or library method that does not exist
- 2Wrong library version: using syntax from an older or newer release
- 3Off-by-one errors: loops that skip the first or last item
- 4Missing edge cases: empty inputs, null values, zero-length arrays
- 5Silent type mismatches: string where a number was expected
Example of a fabricated API
A totally plausible-looking function call that will fail at runtime. This is the #1 AI coding bug.
# AI often writes this when you ask to get JSON from a URL:
import requests
data = requests.get_json("https://api.example.com/data")
# Problem: requests.get_json() does not exist.
# The real API is:
data = requests.get("https://api.example.com/data").json()The four-question review
- 1Does every function call exist in the real library?
- 2Is there a test or example that proves this works?
- 3What does the code do if every input is empty?
- 4What does the code do if every input is wrong?
Running code is the ultimate test
Reading catches some bugs. Running catches the rest. The moment you have code you think works, execute it with real inputs, then try weird ones. Nothing builds your instincts faster than watching AI code crash on inputs it clearly did not think about.
What to do when you catch a bug
- Tell the AI exactly what went wrong — paste the error
- Say what you expected to happen
- Ask it to fix only that issue, not rewrite everything
- Re-run to confirm the fix
“AI will lie to you about code. Not because it wants to, but because it has seen too many confident answers.”
Key terms in this lesson
The big idea: treat AI code like code from a very fast, very confident intern. Read it, test it, challenge it. Never ship what you have not run.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “When AI Writes Buggy Code — How to Read It Critically”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
Builders · 45 min
Your First Capstone — Ship a Small Project
Bring it all together. Pick one of three starter projects, plan it, build it with AI, and deploy it. You are now a builder who ships.
Builders · 30 min
Your First Copilot-Style Completion
Let's actually feel what autocomplete is like. Write a comment, pause, and watch a full function appear. Then learn what to do next.
