Launch offer: the first 1,000 users get Settl free for a year* Claim your spot
settlbuilding in public

Why AI invents functions that never existed, and how to ground it

A model that calls a function nobody wrote is not malfunctioning. It is doing the one thing it was built to do: produce likely text. I build Settl, an expense-splitting app, solo with Claude, and I once lost an afternoon to a date helper that existed in exactly zero libraries. Here is the mechanism, and the three ways to shut it down.

Why plausible beats true

There is no symbol table inside the model. At every step it produces a probability distribution over its entire vocabulary and samples one token. Nothing in that step asks "does this identifier resolve". Existence is not a variable the sampler can read.

Two properties make invented names close to inevitable:

This is why the failure survives a quick read: the import, the argument order and the comment around the invented call are all correct. One token is wrong, surrounded by evidence that the block is right.

Where it invents the most

Density of training examples is the whole story. Expect fabrication where the data thins out:

The three grounds

Grounding is not a lookup bolted onto the model. It is putting the real answer into context so the true token outscores the invented one. Three sources, weakest to strongest:

The docs. Paste the actual API reference for the version in your lockfile. Not a link, the text. A link is a promise the model cannot check.

The code. Point it at the file that defines the thing. Real exports in context outrank imagined ones, and being precise about which file matters (settl.fyi/social/tip-point-at-code).

Execution. Let it run the code and read the error. A failed import is a fact, and facts have no probability distribution. This is the only ground that catches what you forgot to paste.

Copy these prompts

1. Inventory before it writes

Before writing any code, list every export available to me from date-fns at
the exact version in my lockfile, with full signatures. Read the installed
package under node_modules, not your memory of the library.
Do not suggest fixes yet. Do not write any calling code.

2. Make it cite every symbol

For every library function, method and config key you use, add a trailing
comment naming the file where you verified it exists, like:
  formatISO(d)  // verified: node_modules/date-fns/formatISO.d.ts
If you cannot verify one against a real file on disk, do not use it. Write
UNVERIFIED next to it and stop rather than guessing an alternative.

3. Make it run

Write the smallest script that imports every symbol you just used and prints
the type of each. Run it, then paste the raw output back here unedited
before continuing with the actual task.

The cheapest checks in your editor

When grounding is not worth the ceremony

Skip it while sketching: invented names in a throwaway plan get replaced anyway. Skip it on tiny ancient surfaces, because JSON.parse is not going to be imaginary. Skip it when the compiler is already your grounding, since running the typechecker beats a paste-the-docs ritual.

Do the full ceremony where failure is silent: config files, SQL, CLI flags, dynamic languages, anywhere a wrong name surfaces in production at 3am instead of at build time.

Run this on your codebase

Paste this into a session, with the file you most recently let AI write:

Audit this file for symbols that do not exist.

1. List every imported symbol, library method, config key and CLI flag used
   in this file.
2. Verify each against a real file on disk: the package under node_modules,
   its type declarations, or my own source. State the exact path you checked.
3. Mark each item VERIFIED with that path, or UNVERIFIED.
4. Change no code yet. I want the list first.

Then, for every UNVERIFIED item, give me the shortest command I can run to
prove it exists or does not, and the one prompt I should use to regenerate
that line with the real API pasted into context.

Get the next one in your inbox