LearnThatStack Ace your next interview
AI in Engineering Teams · question
Question 6 of 49

What is a hallucinated API, and how do you catch one before it causes damage?

beginner
← All AI in Engineering Teams questions
Re-explain

A hallucinated API is an invented method, option, or endpoint whose plausible name makes it look real. Models invent whole packages the same way.

  • Let the compiler, type checker, or language server flag unknown symbols.
  • In dynamic code, run a focused experiment instead of trusting an explanation.
  • Check unfamiliar calls in the official documentation for the version the project installs.
  • Review a package's registry entry, publisher, and source before installing it. Invented names are a supply-chain risk, because an attacker can publish a real package under one.
  • Keep new dependencies behind human approval.

When sources conflict, trust the executable project and authoritative documentation over the model's confidence.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for AI in Engineering Teams One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why do models invent API names that look so plausible? They predict likely text from patterns across many libraries and versions, so a name that fits the conventions scores high whether or not it exists.
  • Your type checker passes, yet the code uses an option that doesn't exist. How did it get through? Name the gaps: untyped option bags or kwargs, any-casts, dynamic lookups, and type definitions that don't match the installed version.
  • An agent adds a dependency you've never heard of. What do you check before approving it? Registry entry, publisher and history, a source repo that matches the package, install scripts, and whether an existing dependency already covers it.
  • How would you catch invented packages automatically in CI instead of relying on reviewers? Flag new lockfile entries for approval, resolve against an allowlist or internal registry proxy, and fail the build on unresolved imports.
  • Beyond invented packages, what security problems are typical in AI-generated code? Injection, missing input validation, hardcoded secrets, outdated insecure patterns, and how review and scanning should change to catch them.

What you can say

  1. A hallucinated API is a method, option or endpoint the model made up, with a name plausible enough to look real, and models invent whole packages the same way.
  2. The cheapest check comes first, because the compiler, type checker or language server flags a symbol that doesn't exist.
  3. In dynamic code nothing flags it for me, so I run a small focused experiment instead of trusting the model's explanation.
  4. For any unfamiliar call I check the official docs for the version the project actually installs, not the latest one.
  5. Packages are worse, because an attacker can publish a real package under an invented name, so I check the registry entry, publisher and source, and new dependencies need human approval.
  6. The limit is that the model sounds just as sure when it's wrong, so when sources disagree I trust the project that runs and the official docs over the model.

Weak answers to avoid

  • Asks the model whether it's sure The model is just as confident when it's wrong. Name a check outside the model instead, like the type checker, a quick experiment, or the docs for the installed version.
  • Treats it as a bug the tests will catch Misses the package case. Installing an attacker's package can run their code before any test does, so cover registry checks and human approval of new dependencies.
  • Checks the docs but not the installed version A method can exist in the latest release and be missing from the one the project pins. Say you check the docs for the version the project actually installs.
  • Stops at the definition The question asks how you catch one. Walk through the actual checks, from the compiler to dependency approval, and say which source you trust when they disagree.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the AI in Engineering Teams cheatsheet.

← Back to all AI in Engineering Teams questions
Pro · $10/mo

42 of 49 AI in Engineering Teams answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime