Skip to content

Menu

Playbooks

Write trustworthy usage documentation from code

Draft README usage and parameter documentation from source code and run results, removing every behavioral claim that lacks evidence.

min read
18
Level
Intermediate
Last verified

This playbook helps you write verifiable README “Usage” and “Parameters” sections for a small JavaScript module. When you finish, every behavioral claim should point to source code, a test, or actual output. Gemini drafts and organizes; the source and run results decide what is true.

Current Gemini Apps guidance says you can import a code folder or GitHub repository, but entry points, eligibility, and limits may change. With large inputs, details may also be missed. If you cannot use the import feature, provide only the directory tree and files relevant to the task. If you use a terminal tool, note that since 2026-06-18, Gemini CLI no longer processes requests for Gemini Code Assist for individuals, Google AI Pro, and Ultra accounts. Affected users should migrate to Antigravity CLI; deprecation for Gemini Code Assist Standard and Enterprise is being handled separately. This playbook does not depend on any particular CLI command. See CLI transition guide for the current path.

In plain English: Documentation is a set of claims you can verify one by one

Section titled “In plain English: Documentation is a set of claims you can verify one by one”

“uppercase is enabled by default” is not a stylistic choice. It is a claim about program behavior. To check it, return to the default parameters, branches, and tests. A parameter the source never reads does not belong in the README just because similar libraries commonly support it. Smooth prose from the model is only a draft; the evidence chain determines which sentences can stay.

Weak prompt:

Read the code and write a complete, professional README for me.

Better prompt:

Using only the source code and tests I provide, draft the README “Usage” and “Parameters” sections.
After every behavioral claim, list the evidence file and corresponding expression. For defaults, parameters, or exceptions not defined in the source, write “not found”; do not fill them in.
List the example code separately at the end, then wait until I actually run it before confirming the output.

Complete example: Add README documentation for a label-formatting module

Section titled “Complete example: Add README documentation for a label-formatting module”

The following is the complete synthetic practice repository. The module formats fictional batch names as labels:

label-kit/
├── package.json
├── README.md
├── src/
│ └── build-label.js
└── test/
└── build-label.test.js

package.json:

{
"type": "module",
"scripts": {
"test": "node --test"
}
}
src/build-label.js
/**
* @param {string} name
* @param {{ prefix?: string, uppercase?: boolean }} [options]
* @returns {string}
* @throws {TypeError} When name is not a non-empty string.
*/
export function buildLabel(name, options = {}) {
const { prefix = 'ITEM', uppercase = false } = options;
if (typeof name !== 'string' || name.trim() === '') {
throw new TypeError('name must be a non-empty string');
}
const normalizedName = uppercase
? name.trim().toUpperCase()
: name.trim();
return `${prefix}: ${normalizedName}`;
}
test/build-label.test.js
import test from 'node:test';
import assert from 'node:assert/strict';
import { buildLabel } from '../src/build-label.js';
test('uses the documented defaults', () => {
assert.equal(buildLabel(' amber-7 '), 'ITEM: amber-7');
});
test('applies explicit options', () => {
assert.equal(
buildLabel(' amber-7 ', { prefix: 'BATCH', uppercase: true }),
'BATCH: AMBER-7',
);
});
test('rejects an empty name', () => {
assert.throws(
() => buildLabel(' '),
{ name: 'TypeError', message: 'name must be a non-empty string' },
);
});
README.md
# label-kit
Add the “Usage” and “Parameters” sections; do not change the existing heading.

The known environment is Node.js 24 with ECMAScript modules, and the test command is node --test. The patch may change only the “Usage” and “Parameters” sections of README.md. During validation, you may temporarily create and run readme-example.js. Delete it afterward and do not include it in the patch. Do not modify src/build-label.js, the tests, dependencies, or any other file. The public interface that must not change is the named export buildLabel(name, options). Do not treat the README draft as a source requirement and change the implementation to match it.

Draft the README “Usage” and “Parameters” sections for this synthetic module. Start with a draft. Do not change the source or tests, and do not run commands.
[Material priority]
1. src/build-label.js: Primary evidence of current behavior;
2. test/build-label.test.js: Behavior that is explicitly covered;
3. README.md: Provides only the existing heading and does not prove program behavior.
[Allowed scope]
Output only the “Usage” and “Parameters” sections. Preserve the named export buildLabel(name, options). Do not introduce new parameters, defaults, dependencies, or commands.
[Writing requirements]
1. Provide a copy-and-paste-ready ES modules example using the fictional value amber-7;
2. State the expected output, but mark it as “not yet run”;
3. Explain name, options.prefix, and options.uppercase one by one;
4. Document the error for an empty name and the return-value format;
5. In the first pass, output only the README sections, then stop and wait for my line-by-line audit;
6. If you cannot find evidence, write “not found”; do not fill in gaps from experience;
7. Do not claim that you ran the tests or confirmed the example output.

Expected failure: The draft contains exactly two unsupported claims

Section titled “Expected failure: The draft contains exactly two unsupported claims”

To practice auditing, assume Gemini returned the draft below. The example and most of the documentation match the source, but the parameter list contains two errors. Do not paste it directly into the README.

## Usage
`buildLabel` trims whitespace from both ends of the name and returns a label with a prefix.
The output below has not yet been verified by an actual run.
```js
import { buildLabel } from './src/build-label.js';
const label = buildLabel(' amber-7 ', {
prefix: 'BATCH',
uppercase: true,
});
console.log(label);
// BATCH: AMBER-7
```
## Parameters
- `name`: Required string. After whitespace is trimmed from both ends, it cannot be empty; otherwise, a `TypeError` is thrown.
- `options`: Optional options object.
- `options.prefix`: Uses `ITEM` when omitted.
- `options.uppercase`: Defaults to `true`.
- `options.separator`: Label separator. Uses `: ` when omitted.
The return-value format is `<prefix>: <processed name>`.

The code example explicitly passes uppercase: true, so its expected output is correct. The errors appear only in two parameter claims: one default is reversed, and the other parameter does not exist. This section deliberately preserves both errors to test whether the line-by-line audit catches unsupported behavior.

Check each sentence against the source and run results

Section titled “Check each sentence against the source and run results”
Draft claim Direct evidence Decision and action
Import buildLabel from src/build-label.js The named export export function buildLabel in the file Keep
Trim whitespace from both ends of name Both branches call name.trim() Keep
Passing BATCH and uppercase: true produces BATCH: AMBER-7 prefix interpolation and the toUpperCase() branch; confirm with actual output Keep
name must be a non-empty string or the specified TypeError is thrown JSDoc @param {string} and @throws {TypeError}; typeof name !== 'string', name.trim() === '', and throw new TypeError(...); test “rejects an empty name” Keep
options is an optional options object The optional object shape in JSDoc; parameter default options = {} Keep
prefix is an optional string that defaults to ITEM JSDoc prefix?: string; destructuring default prefix = 'ITEM'; test “uses the documented defaults” Keep
uppercase defaults to true The source actually uses uppercase = false; the default test preserves lowercase Error 1: Change to false
separator exists and defaults to : Destructuring, branches, and tests never read separator; the separator is written directly into the return template Error 2: Delete this item
The return-value format is <prefix>: <processed name> Return template `${prefix}: ${normalizedName}` Keep

The audit table does not judge claims by whether they “sound reasonable.” There is no evidence for separator, so it should not be rewritten as “may be supported.” Remove it from the current usage documentation.

Expected output: Complete revised sections

Section titled “Expected output: Complete revised sections”
## Usage
`buildLabel` trims whitespace from both ends of the name and returns a label with a prefix.
```js
import { buildLabel } from './src/build-label.js';
const label = buildLabel(' amber-7 ', {
prefix: 'BATCH',
uppercase: true,
});
console.log(label);
// BATCH: AMBER-7
```
## Parameters
- `name`: Required string. After whitespace is trimmed from both ends, it cannot be empty; otherwise, a `TypeError` is thrown with the message `name must be a non-empty string`.
- `options`: Optional options object. If omitted, it defaults to an empty object.
- `options.prefix`: Optional prefix. Uses `ITEM` when omitted.
- `options.uppercase`: Optional switch. Defaults to `false`; when set to `true`, it converts the trimmed name to uppercase.
The return-value format is `<prefix>: <processed name>`; the colon and following space are inserted by the current implementation.

Verification: Check the claims, then run the example

Section titled “Verification: Check the claims, then run the example”
  1. Temporarily copy the JavaScript example from the revised “Usage” section verbatim into readme-example.js in the repository root. Do not change the input or import path. Delete the file after validation and do not include it in the patch.
  2. In a Node.js 24 environment using ECMAScript modules, run node readme-example.js and confirm that the only output is BATCH: AMBER-7.
  3. Run node --test and confirm that 3 tests pass and 0 fail.
  4. Check the README’s parameter names, defaults, error, and return format one by one, confirming that each points to a source expression or test.
  5. Inspect the diff and confirm that it changes only the approved README sections and does not modify the implementation to accommodate the documentation.

To verify the example on this page, the guidebook’s editor ran node --test and node readme-example.js in an isolated temporary directory using Node.js v24.14.1 and ECMAScript modules. The result was 3 passing tests, 0 failures, and the example output BATCH: AMBER-7. This record proves only that the synthetic example on this page is reproducible.

This page has not run the exercise repository for you. Its source-checked status means only that the product facts were verified; it does not mean your code, dependencies, or README are run-tested.

  • Every parameter name and default can be located in the current source.
  • The example import path, input, and expected output exactly match the actual run.
  • The test count is recorded as 3 passed and 0 failed; “not run” is never reported as “passed.”
  • The documentation distinguishes current source behavior, behavior covered by tests, and inferences still awaiting confirmation.
  • The incorrect true default for uppercase has been revised to false.
  • The nonexistent separator has been removed, and the source was not changed to accommodate the draft.
  • The diff contains only the approved README sections and no real accounts, keys, or production data.
  • The response fills in common parameters: Ask Gemini for a “claim | source expression | test” table. Delete any parameter without direct evidence first.
  • The example output does not match the comment: Preserve the failing output and check the import path, input, and Node.js version. Do not change the expected value until the cause is clear.
  • Tests pass but the documentation is still wrong: Existing tests may not cover every sentence. Check defaults and errors against the implementation one by one.
  • The materials are too long or files are missing: First ask for a list of files actually received. Provide only the target module, relevant tests, and README; mark unread content as unknown.
  • The source is changing: Record the branch, commit, or date of the materials. Do not mix source, tests, and documentation from different versions in one audit.
  • The model suggests changing the source to match the documentation: Stop and return to the allowed scope. If the public interface truly needs to change, open a separate implementation task and add tests and migration notes first.
  • The materials contain sensitive information: Remove keys, production configuration, customer data, and private logs. Provide only the minimum synthetic materials needed to complete the documentation.

Google explicitly warns that users are responsible for code generated with Gemini and that the code may be subject to open source licenses. Documentation needs human review too: it may be syntactically correct while presenting guesses as implemented behavior.

Next: If you do not yet understand the module’s entry point, start with Understand a codebase. If a documentation example exposes a defect, continue to Locate and fix a bug. To define boundaries in the prompt, read Define the task clearly.