Lesson 1150 of 1570
Why ChatGPT Confidently Suggests Code That Doesn't Run
AI chatbots can't actually run your code — they pattern-match what code usually looks like, which sometimes invents APIs that don't exist.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The big idea
- 2hallucination
- 3API invention
- 4verify code
Concept cluster
Terms to connect while reading
Section 1
The big idea
When ChatGPT or Claude writes code, it's predicting tokens, not executing them. It's seen millions of similar snippets and stitches together what looks right. That means imported functions might not exist and library versions might be wrong — confidently.
Some examples
- Claude suggests `array.sortBy()` in JavaScript — but that method doesn't exist in vanilla JS, only in Lodash.
- ChatGPT writes `from openai import ChatCompletion` using an old API style that broke in v1.0.
- Copilot autocompletes a `df.merge_asof_unique()` pandas call that isn't real.
- Cursor invents a Tailwind class like `bg-gradient-rainbow` that doesn't ship with the framework.
Try it!
Ask an AI for a small script using a library you know well. Read carefully — try to catch one made-up function before you run the code.
Key terms in this lesson
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Why ChatGPT Confidently Suggests Code That Doesn't Run”?
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 · 35 min
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.
Builders · 35 min
Tests as Prompts — an Unexpected Superpower
Writing a test first is not just good engineering. It is the clearest possible prompt for an AI. Let's use tests to make AI code reliable.
Builders · 30 min
Python File I/O
Reading and writing files is where real scripts start. Learn the with-statement, path handling, and JSON round-trips.
