← IndexEntry № 179·coding

Write clear API reference docs straight from source code

Generates accurate API reference documentation from source code without inventing behavior, flagging ambiguities.

Optimized for
ChatGPTClaude
§ When to use this

Documentation drifts from code the moment it's written by hand. Generating reference docs directly from source keeps them anchored to reality—provided the model documents only what's actually there. That's the discipline this prompt enforces: describe behavior present in the code, and mark anything ambiguous as TODO instead of inventing it. It produces structured docs (purpose, parameters with types and constraints, return values, errors/status codes, a minimal example) in whatever format your project uses—Markdown, JSDoc, docstrings, or OpenAPI-style prose. Tell it the audience so the tone and examples fit: internal teammates need different detail than external API consumers. The closing list of undocumented behaviors and edge cases is the most valuable part for a reviewer—it surfaces the gaps a human should fill. Feed it one module or set of related endpoints at a time for accuracy, and always read the examples it generates against the real signatures before publishing.

§ The Prompt— fill in the fields, then copy or open in a tool
§ Customize0/3 fields filled
your prompt — fill the fields above
You are an expert technical writer who documents code accurately and never invents behavior. From the source below, generate reference documentation for the public API in [DOC_STYLE] format. For each public function, class, or endpoint, document its purpose, parameters with types and constraints, return value, thrown errors or status codes, and a minimal runnable example. Only describe behavior that is actually present in the code—if something is ambiguous, mark it with TODO rather than guessing. Audience: [AUDIENCE]. Here is the source:

[SOURCE_CODE]

Return the docs in the requested format, followed by a list of any undocumented behaviors or edge cases the author should clarify.
Open with your prompt →ChatGPTClaudeSends your filled-in prompt straight into a new chat.
§ Example Output

What you can expect back

### `createUser(input)`

Creates a new user record and returns the persisted user.

| Parameter | Type | Required | Notes |
|-----------|------|----------|-------|
| `input.email` | string | yes | Must contain '@'; otherwise throws. No further format validation. |
| `input.age` | number | no | Defaults to `null` when omitted. |

**Returns:** `Promise<User>` — the inserted user record.

**Throws:** `ValidationError('invalid email')` when `email` has no '@'.

**Example:**
```ts
const user = await createUser({ email: '[email protected]', age: 31 });
```

Needs clarification:
- TODO: Behavior on duplicate email is not handled here—does `db.users.insert` reject?
- TODO: Email check is minimal ('@' only); is stricter validation expected upstream?
- TODO: No constraint documented for `age` range (negative numbers accepted as written).

Illustrative example — your results will vary by tool and inputs.

§ Pro Tips

Get sharper results

  • 01Document one module or endpoint group at a time so the model can be precise instead of broad.
  • 02Treat every TODO it emits as a real action item—those are the genuine doc gaps.
  • 03Verify generated examples compile/run; the model can produce plausible-but-wrong example calls.
  • 04Set [AUDIENCE] explicitly so internal jargon is either kept or explained appropriately.
§ Variations

Adapt it for your case

OpenAPI fragment

Set [DOC_STYLE] to 'an OpenAPI 3.1 paths fragment in YAML' to wire the docs into an existing spec.

Docstrings in place

Add 'Return the original code with documentation comments inserted directly above each declaration.'

Best For — Roles
Tags#documentation#api#developer-experience
§ FAQ

Common questions

Will it make up behavior that isn't in the code?

The prompt explicitly forbids that and asks it to mark ambiguous behavior as TODO, but spot-check the output against the source before publishing.

Can it output OpenAPI or JSDoc?

Yes—set [DOC_STYLE] to the exact format you want, including 'OpenAPI 3.1 YAML' or 'JSDoc comments'.

How much code can I paste at once?

Keep it to one cohesive module or a small group of endpoints; accuracy drops when the model has to summarize a sprawling codebase.

§ Related Entries

You may also need