THE GITHTML FIELD GUIDE
Write README examples that show input, output, and limits
A useful README example shows the input, the expected output, and the specific behavior being demonstrated. Label illustrative values and disclose omitted setup. Keep each example small enough to verify independently, then check it against the documented version so readers do not mistake a plausible snippet for a working contract.
Choose one behavior per example
An example that simultaneously introduces authentication, pagination, retries, and data transformation forces readers to guess which part matters. Start with the central operation and use the smallest safe input that reveals its result. Name the lesson explicitly, such as validating one record or constructing a request without sending it. Follow with a separate edge case when that teaches a different rule. Avoid a large impressive sample whose output cannot be checked quickly. If the project's behavior depends on external state, say so and identify which portions of the output are stable versus variable. Readers need to know what comparison is meaningful.
Present the whole relevant contract
Place the required setup, input, invocation, and expected observation together. Distinguish executable code from pseudocode and identify the language or shell. Use placeholder values that clearly indicate replacement rather than realistic-looking credentials. Explain any omitted error handling or production considerations instead of silently implying the snippet is deployment-ready. The scaffold below is a structure for documenting an example, not an executable program. When output contains timestamps or identifiers, describe the expected shape without pretending an exact sample value will recur. Include a small negative example if it prevents a common misuse, but keep it separate from the successful path.
## Example: [one behavior]
Requires: [setup]
Input: [small safe fixture]
Invocation: [verified code]
Expected: [observable result]
Not demonstrated: [important omitted behavior]Verify examples as maintained assets
Run safe examples in the supported test environment and compare the observed result with the documented contract. Preserve the fixture or test that makes future verification inexpensive. A screenshot of output can supplement the explanation but should not replace searchable text. When an API changes, update the example's setup and expected output together; changing only the call signature can leave a misleading result. Ask a reader to copy the example without extra context and record what they must infer. If the example intentionally omits a dependency or step, disclose that omission prominently. The goal is trustworthy transfer, not merely attractive code formatting. Keep fixture changes reviewable alongside the prose. A new input dataset can alter the expected lesson even when the code snippet remains byte-for-byte identical to its previous version.
- State the single behavior the example demonstrates and remove unrelated features.
- Provide setup, input, invocation, and expected observation in one coherent sequence.
- Label pseudocode, placeholders, and variable output explicitly.
- Keep a safe repeatable fixture so future releases can verify the example instead of relying on memory.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.