$ fssg build --deterministic --validate |

Your AI Documentation Examples Must Compile

AI Engineering

I do not trust an AI infrastructure guide until its smallest example survives the real toolchain.

A README may describe the right architecture and still teach an invalid command, an obsolete field, or a syntax form removed two releases ago. That is not a cosmetic documentation bug. The first example is often the reader's first executable dependency on the product. If it lies, the release is already inconsistent.

I was reminded of this while reviewing FACET's own public specification and compiler. A minimal README example looked plausible but did not compile under the current reference implementation. It mixed old draft syntax with the current specification: a removed block, invalid attributes, an undeclared effect, and a message without required content. The repair was not to make the prose more persuasive. It was to replace the sample with a contract verified by the actual compiler and document the syntax traps that produced the drift.

The broader lesson is simple: documentation examples should be release tests.

Why AI documentation drifts faster

Documentation drift is old. AI systems make it more dangerous because their interfaces often combine several unstable layers:

  • a declarative contract or prompt format;
  • model and provider adapters;
  • tool schemas;
  • runtime policy;
  • environment configuration;
  • CLI commands and generated artifacts.

A sample can remain visually convincing while crossing those layers incorrectly. An old tool envelope may still resemble JSON. A renamed policy field may still sound reasonable. A model can even explain the broken example confidently, hiding the mismatch until a user tries to run it.

This is why review by reading is insufficient. Prose review can check clarity. Only execution can check whether the example still belongs to the released system.

Rust's documentation tests formalize the same principle: examples embedded in documentation can be compiled and executed so they stay current. Python's doctest turns interactive-looking examples into executable checks. The exact mechanism differs, but the contract is identical: a public example is not decoration; it is behavior that the project claims to support.

Give every example an owner and a mode

Not every code block should run. Some blocks are pseudocode, partial fragments, failure demonstrations, or provider responses. The mistake is leaving that distinction implicit.

I would classify each public example into one of four modes:

Mode CI behavior Reader promise
compile parse, validate, and compile syntax and static semantics are current
run execute in a hermetic or mocked environment the demonstrated path works
fail assert a named diagnostic the example intentionally demonstrates rejection
illustrative lint only; require an explicit label structure is explanatory, not copy-paste-ready

This small taxonomy removes a large ambiguity. Without it, CI either ignores documentation or tries to execute everything and accumulates exceptions. With it, every block has a declared promise.

An intentional failure is especially valuable. If the guide says an undeclared side effect must be rejected, the example should assert the exact error class or stable diagnostic ID. Otherwise a future parser may accept the invalid input while the prose continues to claim that the boundary exists.

Extract one source artifact, not two copies

The weakest implementation copies a README sample into a test file. Both copies then drift independently.

I prefer one source artifact rendered into documentation and consumed by tests:

examples/minimal-payment.facet
        ├── compiler fixture
        ├── CLI smoke test
        └── README include

The release pipeline can verify the artifact once, capture its expected output, and insert the same source into the guide. If the documentation system cannot include files directly, a synchronization check can compare the fenced block with the fixture and fail on a difference.

The important invariant is not the templating technology. It is that the reader and CI see the same bytes.

This pattern also makes versioning explicit. An example can declare the specification version, compiler version range, profile, host assumptions, and required mocks. A command copied from documentation should not depend on invisible state from the author's machine.

Test the path a new user actually takes

A unit test over the parser is not enough. Documentation usually promises a path, not a function.

For a minimal AI contract example, the useful smoke test might be:

write fixture
  -> validate source
  -> compile canonical artifact
  -> inspect policy and tool identity
  -> run with a recorded provider response
  -> assert the final execution artifact

That path crosses the same boundaries a reader crosses. It catches missing files, wrong CLI flags, stale defaults, packaging mistakes, adapter drift, and output paths that a narrow unit test will miss.

The test should remain bounded. It does not need a live model call if the claim is about compilation or guarded execution. A recorded response or scripted client is often stronger because it removes network and provider variance while preserving the real adapter, authorization, and artifact path.

This matches the principle behind the minimal FACET GitHub Actions gate: deterministic checks should prove the boundary they actually own. A documentation smoke test can prove that the public path compiles and produces the expected artifacts. It cannot prove model quality, provider availability, or production readiness.

Make drift fail with a useful receipt

A red documentation job should explain the broken promise. “Example failed” is not enough.

I want a receipt with:

{
  "example": "minimal-payment",
  "mode": "compile",
  "source_hash": "sha256:...",
  "spec_version": "2.1.3",
  "tool": "facet-fct",
  "tool_version": "0.1.2",
  "command": "facet-fct build examples/minimal-payment.facet",
  "expected": "success",
  "actual": "F456",
  "documentation": "README.md#minimal-example"
}

Now the failure has an owner, an identity, and a reproducible command. Reviewers can see whether the product changed intentionally, the example is stale, or the tool regressed.

For generated output, compare semantic artifacts when byte equality is not the product promise. For canonical JSON, exact hashes may be appropriate. For human-facing explanations, test required fields and invariants instead of punctuation. The assertion must match the guarantee.

Use documentation failures to improve the specification

A broken example is sometimes more than stale copy. It may expose ambiguity in the system itself.

FACET's second implementation experiment found specification questions that the reference compiler had silently answered. Documentation examples can play a similar role at a smaller scale. They force the project to answer what a beginner needs to know: which version applies, what is required, what is inferred, what may perform I/O, and what artifact should appear.

If an example needs five paragraphs of hidden assumptions to pass, the public interface may be carrying too much ambient state. If two maintainers repair it differently, the specification may be underspecified. If a supposedly minimal example requires a live account and several credentials, the onboarding boundary is too expensive.

The correct response is not always “fix the snippet.” Sometimes the example is telling us that the product contract needs repair.

The release gate I would use

For each release:

  1. inventory public executable examples;
  2. assign compile, run, fail, or illustrative mode;
  3. bind each example to one source fixture;
  4. execute the documented CLI path in a clean environment;
  5. assert stable diagnostics or output invariants;
  6. publish the tested version and assumptions beside the example;
  7. block the release when a copy-paste-ready example fails.

This is not heavy governance. It is dependency testing for the first artifact most users touch.

The canonical AI engineering runtime exists to turn claims into controlled state transitions. Documentation belongs in that model too. A guide proposes a transition from “I have the tool installed” to “I produced a valid artifact.” If the project does not test that transition, it does not know whether its onboarding contract still works.

I want documentation that can be read by a person and challenged by a machine.

The prose should explain the idea. The fixture should prove the path. The release should carry both.

Sources

FACET AI CLI Terminal
facet@ai:~$