Verified against GitHub Copilot Chat · 2026-07-31
Generate docstrings that describe what the code actually does, not what its name implies
A documentation-generation prompt that requires each docstring claim to be checked against the real function body first, so documentation does not quietly repeat a misleading name or a stale comment instead of the real behavior.
The prompt
Ready to copy — highlighted parts are example details you can swap.
Write documentation for the getUserTier function in lib/billing/tier.ts in TSDoc, matching the /** */ block style already used elsewhere in lib/billing/ format. Before writing anything, read the actual function body — every branch, every early return, every thrown error — and check whether its name and any existing comment already describe that behavior accurately, because a docstring generated from the name and surrounding comments alone just restates whatever those already claim, right or wrong, and a wrong claim documented confidently is worse than no documentation at all. AUDIENCE Other engineers on this team calling this function from a new feature, not external API consumers. KNOWN NON-OBVIOUS BEHAVIOR TO MAKE SURE IS SURFACED getUserTier returns 'free' for a user with a cancelled subscription still inside its paid billing period, not 'paid' — this surprises people. FOR EACH FUNCTION OR EXPORT, DOCUMENT 1. What it actually does, in one sentence, checked against the real logic — not the name. If the name suggests something the code does not actually do, say so as a separate note rather than writing around the discrepancy silently. 2. Every parameter, with its real constraint as enforced by the code, not just its type — if a parameter's type allows a value the function will actually throw on or silently misbehave for, document that constraint explicitly rather than letting the type signature imply it is always safe to pass. 3. What it returns in every branch, not just the main one — including what happens on an empty result, an error path, or an early return, since a docstring that only describes the success path is describing a fraction of the function's real contract. 4. Any side effect beyond the return value — a mutation of an argument, a write to storage, a network call, a thrown exception — stated explicitly, since a caller reading only the return type has no way to know about a side effect the code performs but the signature does not surface. CONSTRAINTS - Do not describe an implementation detail that could change without changing the contract, such as which specific loop construct is used internally, as if it were part of the guaranteed behavior — document what callers can rely on, not how today's version happens to achieve it. - If getUserTier returns 'free' for a user with a cancelled subscription still inside its paid billing period, not 'paid' — this surprises people. names something the current code does not actually do, or does differently than described, flag the mismatch explicitly rather than writing the docstring to match the gotcha note over the real code — the note might itself be stale. - Match TSDoc, matching the /** */ block style already used elsewhere in lib/billing/ exactly, including whether examples are expected inline — a generated block that is close to the right format but not quite in the project's actual convention creates visible inconsistency across a codebase where every other function follows the real convention.
Customize
Optional — swap in your own details for the highlighted parts above.
Why this works
Reading every branch and early return before writing anything counters the specific and common failure mode of documentation generation: pattern-matching from a function's name and any existing comment, which reproduces whatever those already claim, correct or not, because nothing forces the generation step to check the claim against the actual logic first. Documenting every return branch and every side effect beyond the signature targets a real gap between what a TypeScript type signature guarantees and what a function actually does — types capture shape, not behavior, so they say nothing about which branch returns what, whether an argument gets mutated, or whether a network call happens along the way, and a docstring that only restates the type signature in prose has added no information a caller could not already see. The distinction between a documented contract and an incidental implementation detail matters because it determines what stays true across a future refactor — a docstring describing an internal loop construct as guaranteed behavior goes stale the moment someone rewrites that loop for an unrelated performance reason, even though nothing about the function's actual contract changed, while a docstring scoped to what callers can rely on survives exactly the kind of internal change it should be indifferent to. Cross-checking known_gotchas against the real code rather than writing the docstring to match the gotcha note on faith closes a specific risk in any tribal-knowledge input: the note itself might be stale, describing a behavior from a version of the function that has since changed, and a documentation pass that trusts it uncritically can bake an outdated claim into a freshly generated docstring with the same false confidence as if it had been verified.
Verified against
GitHub Copilot Chat Copilot Chat 1.269 (VS Code) · 2026-07-31
Changelog
- 2026-07-31 — Initial publish, verified against Copilot Chat 1.269 (VS Code).
Need this built into your business?
If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.
EXPLORE CUSTOM SOFTWARE
