Write clear API reference docs straight from source code
Generates accurate API reference documentation from source code without inventing behavior, flagging ambiguities.
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.
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.
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.
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.
Adapt it for your case
Set [DOC_STYLE] to 'an OpenAPI 3.1 paths fragment in YAML' to wire the docs into an existing spec.
Add 'Return the original code with documentation comments inserted directly above each declaration.'
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.
You may also need
Design a RESTful API Endpoint Schema
Design a complete REST API schema with request/response bodies, status codes, and error cases.
Write Clear Technical Documentation
Generate complete Markdown technical docs with params, examples, and error handling.
Refactor a long, tangled function into smaller, testable units
Breaks an overgrown function into smaller, single-responsibility units while preserving behavior and the public signature.
Turn a diff into a clear, reviewer-friendly PR description
Converts a diff and context into a structured, reviewer-friendly pull request description and title.