$ fssg build --deterministic --validate |

How FACET Turns AI Tests into Executable Contracts

FACET

A prompt test that only compares final text is already too late.

By the time an answer reaches a snapshot, the system may have assembled the wrong messages, spent the wrong context budget, called an interface that should have been blocked, or evaluated policy under assumptions the test never recorded. The output can look acceptable while the execution contract is broken.

This is why I treat FACET @test blocks as part of the contract, not as a separate QA layer. A test supplies fixed inputs, replaces external effects with explicit mocks, and asserts against artifacts produced before and during execution. It tests the machine around the model.

The unit under test is the compiled request

In ordinary prompt testing, the natural unit is a string: input goes in, generated text comes out. That unit is unstable because generation remains probabilistic. It also hides the deterministic work that should be testable without judging prose.

FACET gives us better boundaries. The compiler runs a defined pipeline—normalization, resolution, type checking, computation, layout, and rendering—and produces canonical structure. The runtime can additionally expose telemetry and an execution artifact. Those are engineering surfaces.

A compact test can look like this:

@test "support-query-contract"
  input:
    query: "Where is my order?"
  mock:
    Orders.lookup: { status: "in_transit" }
  assert:
    - canonical.messages[1].role == "user"
    - canonical contains "Where is my order?"
    - telemetry.gas_used < 5000

The interesting part is not the syntax. It is the separation of responsibilities:

Surface What the test proves
input Runtime values are explicit and type-checked
mock External behavior is replaced at a named interface boundary
canonical The compiled request has the intended structure
telemetry Resource behavior remains inside a declared envelope
execution The runtime can be checked through its execution record

The test does not claim that a model will always answer correctly. It proves that the deterministic preparation and control layers behave as specified.

Mocks are effect boundaries, not convenient fake data

A mock becomes dangerous when it is just a loose dictionary that happens to satisfy a test. FACET identifies mocked calls by fully qualified interface name. That matters because the replacement is attached to a declared boundary, not silently injected somewhere in application code.

This connects directly to the distinction I made in why an effect class is not a permission. Describing an operation as network, filesystem, or process activity tells us what kind of effect it may produce. It does not authorize that effect. In a test, the interface mock removes the real effect; policy and guard behavior still need their own assertions.

The useful test matrix is therefore not “one happy mock, one expected string.” It is closer to:

fixed input
  ├─ allowed policy   -> canonical + execution assertions
  ├─ denied policy    -> F454
  ├─ undecidable guard-> F455
  ├─ pure cache hit   -> deterministic result
  └─ pure cache miss  -> F803

Failures are outcomes of the contract. They are not exceptions to testing.

Isolation makes a test portable

The FACET testing model says each @test runs in isolation. Variables supplied by a test remain type-checked; runtime inputs are explicit; external calls can be intercepted. This gives a test a chance to travel with the .facet document instead of depending on a developer’s shell history, warm cache, or local service.

That property is more important than convenience. A contract-local test can serve several roles:

  1. Executable example. A reader sees a valid scenario near the declaration it exercises.
  2. Regression boundary. A compiler or policy change can be checked against the same expected artifacts.
  3. Conformance evidence. Another implementation can run the scenario and compare deterministic surfaces.
  4. Integration handoff. A host runtime receives not only a document, but examples of acceptable and rejected behavior.

This complements the FACET conformance ladder. A label such as L2 or L3 is useful only when implementations can demonstrate the relevant semantics. Contract-local tests turn part of that claim into runnable evidence.

Assert structure before meaning

AI evaluation often starts with semantic scoring: did the answer help, was it grounded, did a judge prefer it? Those questions matter, but they should not absorb checks that can be exact.

I use a strict order:

  1. Compile-time invariants: types, imports, placement, and policy structure.
  2. Canonical request invariants: message roles, ordering, required content, and stable fields.
  3. Runtime invariants: guard decisions, effect boundaries, budget use, and execution records.
  4. Model-quality evaluation: factuality, usefulness, style, or task success.

The first three layers should fail deterministically. Only the fourth needs probabilistic evaluation. Mixing them creates noisy diagnosis: a judge score drops, but nobody knows whether the cause was retrieval, layout, authorization, or the model.

The same separation explains why audits need both a request artifact and an execution artifact. The compiled request records what was prepared. The execution artifact records what actually happened. Tests can make assertions across that boundary instead of inferring execution from the final answer.

What @test does not prove

Contract-local tests have precise limits. A passing test does not prove model correctness, provider availability, external API truth, production latency, or safety outside the asserted scenarios. Mocks can also conceal an inaccurate interface assumption if they drift from the real service.

The answer is not to weaken deterministic tests. It is to layer them with schema checks, integration tests, model evaluations, and production observability. FACET owns the part it can make explicit: inputs, compilation, declared effects, policy decisions, bounded resource signals, and inspectable artifacts.

I do not want a prompt file that merely describes intended behavior. I want it to carry small, executable counterexamples to its own failure modes. When a contract can say both “this is what must happen” and “this is how to prove it,” AI engineering becomes less dependent on trust—and much easier to change without guessing.

Sources

FACET AI CLI Terminal
facet@ai:~$