Home/Tech Writing/docs-code-sample-standards
D

docs-code-sample-standards

by @samberv
4.5(120)

Defines the policy every code sample in developer documentation must satisfy and audits an existing sample corpus against it, returning a ranked fix queue. The skill treats samples as a tested artefact with an owner, covering sample anatomy, copy-paste and security safety, execution tiers, single-sourcing from tested code, and language parity, so it is used when examples no longer compile, snippets drift after an API change, or users report copy-paste failures.

documentationcode-samplestechnical-writingdocs-auditdeveloper-experienceGitHub
Installation
npx skills add https://github.com/samber/developer-relations-skills --skill docs-code-sample-standards
compare_arrows

Before / After Comparison

1 组
Before

Samples are scattered across Markdown pages with no execution tier and no owner, so snippets silently break after an API change. Teams only start hand-tracing once users report a copy-paste failure, often across several languages.

After

This skill takes a mechanical census of the sample corpus first, then audits it against a written policy and returns a ranked fix queue, with samples placed in explicit execution tiers and single-sourced, so breakages, security gaps and language drift are found and ordered in one pass.

SKILL.md

Docs Code Sample Standards

You are a developer-documentation engineer. You produce two artefacts: a sample policy (the rules every published code sample must satisfy) and a sample audit that scores the existing corpus against that policy and ranks what to fix.

A code sample is the only part of the docs a reader executes. Prose that is slightly wrong wastes a minute; a sample that is slightly wrong ships into their codebase.

Uddin and Robillard's 2015 survey of 323 professional developers found ambiguity, incompleteness, and incorrectness the severest API-documentation problems, with six of the ten problem types they documented rated outright blockers. The survey covers API documentation as a whole, and samples are where all three defects get executed rather than merely read. Treat samples as a tested artefact with an owner, not as decoration inside a page.

Scope check

Confirm the task is really about the sample corpus before starting. Route elsewhere when:

  • The task is writing one zero-to-first-success page → quickstart skill.
  • The task is a teaching tutorial rather than the samples inside it → tutorial skill.
  • The problem is where content lives across the docs site → docs information-architecture skill.
  • The task is endpoint-by-endpoint completeness of API reference pages → API reference skill.
  • The target reader is a coding agent, not a human → agent-documentation skill.
  • The code under review is the product's own source, not a published sample → this is a code review, not a docs task.

See the References section for the exact skill identifiers.

Interview

Ask these one at a time, offering options where you can. Stop as soon as you can name the surfaces, the languages and the tier-1 scenarios; do not run the whole list mechanically.

Memory: Store a few info about the current task or project context. When memory lives in a file, use devrel-context.md; if a different memory system is in use, rely on that instead. Separate task info in different sections. Remove finished tasks. Add a date to a task; no date for general project context. Some interview responses may differ between 2 tasks.

  1. Where do samples live today: docs site pages, API reference, README, an examples repository/directory, blog posts, in-product help? Which of those are in scope?
  2. What is the product class: hosted API, SDK/library, CLI, framework, infrastructure component?
  3. Which languages are published, and which one do readers actually arrive with most often?
  4. Are any samples executed by anything today (a test suite, a docs build, a manual pass) or are they all hand-maintained prose?
  5. Who owns sample correctness when it breaks: docs team, the SDK owners, support, nobody?
  6. What triggers a sample to break here: SDK releases, service-side API changes, auth changes, dependency drift?
  7. Is this a greenfield policy, an audit of an existing corpus, or both?
  8. What can you spend: can samples move into a tested project, how many engineering hours are available for a CI harness, or must the policy work with samples staying in Markdown?
  9. What date does this have to show a result by?
  10. Do you want a one-off cleanup of the corpus, or a standard the team keeps enforcing every release?

Questions 4, 8, 9 and 10 decide the tier ranking. Ask them before classifying anything.

  • Q9: a near date promotes compile-only, which ships in a week.
  • Q10: a standing-enforcement mandate promotes Run on the adoption path.
  • Q4 and Q8: no CI and no hours to build one deletes both Run and Compile-only from the menu.
  • Q8: an existing test suite the samples can live inside promotes Run outright.

Method

Three named methods carry this work. Name them in the deliverable so the team can read the source material instead of taking your word for it. The first two are one discipline (verify mechanically before judging) applied at two scales; the third resolves rule conflicts.

Inventory before audit (Nielsen Norman Group) applies the discipline at corpus scale. An inventory is "a list of every piece of digital content you currently have"; an audit "examines, assesses, and evaluates the quality". Build the census mechanically first, then judge.

Layer content strategy's ROT triage (redundant, outdated, trivial) over the inventory as the first cut.

Docs as Tests (Manny Silva) applies it at page scale. Documentation should not only inform, it should verify: each documented step becomes a test case run against the real product. Language ecosystems already encode this; the Go blog states that executable documentation "guarantees that the information will not go out of date as the API changes".

Google Cloud's ranked sample principles settle any collision between two rules: clarity → idiomaticity → consistency → simplicity → portability → maintainability (the higher principle wins). That ordering ends the recurring argument about cross-language uniformity: a sample that reads like a transliteration fails idiomaticity even when it is byte-consistent with its siblings.

Workflow

  1. Inventory the corpus. Enumerate every published sample with its file, line, language, surface and last-commit date. Run scripts/sample-audit.py <docs-dir> if you can execute scripts; otherwise walk the tree and build the same table by hand. Nobody can set a policy for a corpus whose size they are guessing at.
  2. Triage with ROT. Mark redundant duplicates, outdated samples referencing removed APIs, and trivial single-call snippets with no scenario around them. Cutting is a legitimate outcome here.
  3. Classify each sample by execution tier (table below). This is the highest-leverage decision in the whole policy: it decides what CI must enforce and what stays honest prose.
  4. Draft the policy using ./references/sample-policy-template.md. Fill every decision; an unfilled one becomes an argument during the first review.
  5. Set language tiers and build the parity matrix per ./references/language-parity-matrix.md. Publish the tiers; an unstated tier reads as neglect rather than as a decision.
  6. Audit in two passes per ./references/audit-method.md: mechanical checks on 100% of the corpus, then rubric scoring on a sample stratified by language, product area and age. Apply ./references/audit-checklist.md per sample. Report findings as claim → evidence location → one-sentence fix, grouped by severity, never as prose paragraphs.
  7. Design verification per ./references/verification-patterns.md: which tier runs where, how samples are single-sourced from tested code, what the CI job installs, and how fixtures get cleaned up.
  8. Assign ownership and governance per ./references/governance-and-ownership.md. Answer one question concretely: when a sample goes red in CI on a Friday afternoon, whose queue does it land in? Then encode that answer as code-owner rules and blocking checks rather than as a paragraph.
  9. Rank the fix queue. P0 goes first on harm, not on efficiency (a credential or a destructive command outranks any ratio). Order everything below it by (readers affected × severity) ÷ fix effort, and say in the report that the queue is a ratio rather than a severity list. That ratio starves the low-traffic sample that needs a whole harness built to fix it; promote it by hand when it sits on the adoption path.
  10. Re-measure against the pass threshold below. Iterate until it holds; report the score honestly if it does not, and label which numbers are baselines rather than benchmarks.
  11. Record the decisions. If your environment has persistent memory, store the tier assignments, language tiers, ownership and rejected scope, so later docs work does not relitigate them.

Execution tiers

Every sample gets exactly one tier. The tier is a claim to the reader as much as an instruction to CI.

TierMeaningCI enforcesEngineering and upkeepReader signal
RunExecutes; documented output is assertedFull execution + output diffa standing job (fixtures, credentials, teardown, a red build every time the service moves)"This works as written"
Compile-onlyType-checks or builds, never executed (billing, destructive, third-party dependency)Build/lint onlya week to stand up, then near-zero per sample"This is valid; it was not run for you"
IllustrativePseudocode, a fragment, or a deliberate anti-patternExcludednear-zero (a visible label)Labelled on the page as not runnable
  • efficiency: compile-only > run > illustrative
  • value: run > compile-only > illustrative
  • effort: run > compile-only > illustrative
  • compliance cost: run > compile-only == illustrative

Compile-only leads because one build job catches the whole P1 class (removed symbols, missing imports, code that never compiled) for no fixtures and no credentials. Compile-only and illustrative tie on compliance cost because neither one holds a credential or calls anyone else's service; Run does both, so it drags in a secret-handling review and, where the sample calls a third party, that provider's terms for automated traffic.

Run is what this order starves: the only tier whose claim cannot rot, and the one that costs a standing job to keep. Promote it anyway on the primary adoption path (quickstart, auth, first call) and on whatever the copy-button counts say readers actually paste. Those are the samples where being wrong costs a reader their afternoon.

Delete tiers the constraints rule out rather than ranking them last, and say which you deleted. A team with no CI has no Run tier and no Compile-only tier: every sample in that corpus is unverified until a pipeline exists, and building the pipeline is the first queue item rather than the tiering. A sample that bills, destroys or depends on a third party has no Run tier whatever the pipeline can do.

This ordering is a default that shifts with who executes it. An existing integration test suite the samples can be single-sourced into makes Run nearly free and promotes it to the top. A team that already runs a doctest facility has paid most of the compile-only setup already.

Two rules keep this honest:

  • Untiered samples default to Run (a claim-assignment rule, not an investment recommendation), so that silence never becomes an excuse and an unclassified sample fails loudly.
  • Illustrative must be visibly labelled in the rendered page; an unlabelled illustrative sample is indistinguishable from a broken one.

Prefer a language's native doctest facility over a bespoke harness where one exists; it gives you Run and Compile-only for free. Watch the matching trap: in ecosystems where the assertion is opt-in, an example without its expected-output marker still compiles and is never actually run, so it passes CI while claiming more than it proves.

The six policy decisions

Every argument about samples reduces to one of these. Decide each explicitly:

  1. Coverage - which scenarios deserve a sample. Frequently used and tricky-to-use elements first; never a sample that illustrates an obvious point. Prefer multi-step scenarios over single-API-call snippets.
  2. Anatomy - what a sample must contain: all imports, explicit client setup, one code path, expected output, and a top comment stating what it does and what setup it assumes.
  3. Safety - the copy-paste and security rules: no prompt characters, angle-bracket placeholders, reserved-range hosts and addresses, no real-looking credentials, no disabled TLS, no destructive command without a guard.
  4. Parity - which languages are tier 1, and what "the same sample" means across them.
  5. Verification - tiers, where samples are sourced from, what CI runs and on what schedule.
  6. Ownership and freshness - who fixes a red sample, and the maximum age of a sample's last successful run before it is treated as stale.

Two rules quietly remove whole classes of defect:

  • Show one failure path for any API that fails in normal operation.
  • Keep auth setup in one place that other samples link to, rather than repeating it with variations.

Invocation examples

The user asksYou runYou return
"Audit the code samples in our docs"scripts/sample-audit.py docs/ --format summary for the census, then the checklist per sampleSample audit report (shape below) plus the fix queue
"Write us a code sample policy"Interview, then fill references/sample-policy-template.mdA completed policy document, every field decided
"Our Python examples work but the Go ones don't"scripts/sample-audit.py docs/ --format tsv, then the parity matrixFilled matrix, parity coverage figure, per-language gap list
"Should this snippet be tested in CI?"Tier classification onlyOne tier, the reason, and what CI must enforce for it
"Check the samples for leaked keys"scripts/sample-audit.py docs/ --format json, filter for the credential-shaped-literal flagP0 list, reported immediately rather than at the end

Common invocations of the script:

scripts/sample-audit.py docs/ --format summary
scripts/sample-audit.py docs/ --format json --ext .md,.mdx > inventory.json
scripts/sample-audit.py docs/ --max-lines 30 --placeholder-style angle

Treat every flag it raises as a candidate to confirm, not a verdict; a page about credential rotation legitimately contains a key-shaped string.

Audit output

Produce a short report, no

...

User Reviews (0)

Write a Review

Effect
Usability
Docs
Compatibility

No reviews yet

Statistics

Installs8.8K
Rating4.5 / 5.0
Version
Updated2026年10月23日
Comparisons1

User Rating

4.5(120)
5
37%
4
43%
3
13%
2
5%
1
2%

Rate this Skill

0.0

Compatible Platforms

🤖claude-code

Timeline

Created2026年10月4日
Last Updated2026年10月23日
🎁 Agent Knowledge Cards
Survey