Skip to content
mentoor

Topic 5 of 5 · 5 min read

Invented details in AI-written docs

Goal: Check an AI-generated API doc against the code and find the invented parameter, default or example.

An AI-written doc is a draft of claims, and each claim about a parameter, default, return value or error must be checked against the code before it ships. Models write docs the way they write everything: fluent, complete-looking and sometimes wrong.

Check yourself · 1 of 3

An AI-generated doc lists a timeout option that is not in the function signature. What is the likely cause?

Choose one answer

Why it matters

Generated docs often look more polished than hand-written ones. That is the danger. A missing parameter tells the reader to look elsewhere. An invented one sends them to write code that fails. The usual culprits are the details that look standard: a timeout option because most clients have one, a default of 10 because it is a round number, an error code that sounds right. The model fills gaps with what is typical, not what is true for your code.

How to do it

  1. Generate from the code, not from memory. Give the agent the actual function, route or schema, and say "document only what appears here".
  2. Ask for a source line per claim. Each parameter and default should point to where it is defined. Claims without a line are suspects.
  3. Compare the list of parameters. Count the parameters in the signature and in the doc. Extra names are inventions; missing ones are omissions.
  4. Check every default and type against the code, not against a test.
  5. Run every example. Paste it, execute it, and read the output. An example that was never run is the likeliest place for a made-up field.
  6. Mark the unknown. Tell the agent to write "unknown" instead of guessing, and treat each "unknown" as a question for the owner.

Before and after

Code:

export function listOrders(userId: string, limit = 20, cursor?: string): Promise<Page<Order>>

Weak generated doc: "listOrders(userId, limit = 50, status?, sort?). Returns an array of orders. status filters by state; sort is asc or desc."

Fixed doc: "listOrders(userId, limit = 20, cursor?). Returns a page of orders; pass cursor from the previous page to continue." The weak version has the wrong default, two invented parameters and the wrong return shape. The fixed one is shorter and true.

What goes wrong

  • Invented parameters that match the conventions of other libraries.
  • Wrong defaults copied from a similar project or a round number.
  • Examples that never ran, with plausible field names and made-up output.
  • Over-explaining behaviour the code does not show, such as claimed retries or caching.

Examples

Finding the invented parameter

The doc for createUser lists email, name and role. The function in users.ts takes only email and name; role is set server-side. The agent added role because user APIs usually have one. The fix removes it, and a note says roles are assigned by an admin endpoint.

Asking for evidence per claim

Document this function. For every parameter, default and error, add
(source: path:line). If the code does not show it, write "unknown".

The reviewer then opens each cited line. Missing citations and "unknown" entries become the list of questions.

Key points

  • Treat every claim in an AI-written doc as unverified until it is matched to the code.
  • Tell the agent to document only what appears in the supplied source and to write 'unknown' otherwise.
  • Compare the doc's parameter list to the real signature; extra names are inventions.
  • Check each default and return type in the code itself, not from memory or tests.
  • Run every example; an example that never ran is the most likely place for invented details.

Common mistakes

  • Reading the doc for style and tone instead of comparing it with the code.
  • Assuming a default is right because it is a normal value such as 10 or 30 seconds.
  • Publishing examples that were never executed.
  • Asking the agent to 'verify itself' without a second source such as the code or a test run.

Check yourself · 2 of 3

Which prompt instruction best reduces invented details in a generated API doc?

Choose one answer

Check yourself · 3 of 3

A generated doc says limit defaults to 50. The function declares limit = 20. What do you do?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic