$ fssg build --deterministic --validate |

Typed Runtime Inputs: The ABI of a FACET Contract

FACET

An AI contract should not discover its inputs by accident. If a user query, tenant identifier, or tool result enters the request through an untyped template hole, the compiler has already surrendered the most useful boundary in the system.

I think of FACET's @input(...) as an application binary interface for an AI request. The analogy is not perfect, but it forces the right question: what values may cross from the host application into the compiled contract, in what form, and at which phase?

FACET v2.1.3 answers that question with a small mechanism. An input declares a type, may declare a default, is legal only in a constrained position, and is materialized before the reactive dependency graph runs. That order matters more than the syntax.

The host should supply values, not rewrite architecture

Consider a minimal contract:

@vars
  query: @input(type="string") |> trim()
  limit: @input(type="int", default=5)
  request: "Return at most $limit results for: $query"

@user
  content: $request

The host provides data:

{
  "query": "  deterministic AI contracts  ",
  "limit": 3
}

It does not splice text into the source file. It does not choose where the query appears. It does not alter the lens pipeline or the dependency graph. Architecture remains in NADL; runtime values cross a declared interface.

This is the same separation I described in What Is NADL?: a prompt is one value, while an AI request is a system assembled through explicit compiler phases. Typed inputs make the boundary between that system and its caller visible.

Materialization is a phase boundary

The crucial operation is input materialization. Before FACET evaluates the R-DAG, each @input must resolve to either a supplied runtime value or its declared default. The resolved value must satisfy its FACET Type System expression. A mismatch produces F453.

The resulting sequence is:

Phase Responsibility What must not happen
Host call Supply named runtime values Rewrite the contract
Materialization Resolve supplied value or default; check input type Coerce an incompatible value silently
R-DAG evaluation Compute dependent variables in stable order Fetch undeclared data
Layout Allocate the already computed message sections Invent missing inputs
Render Produce canonical request data Repair semantic errors

This is a temporal contract. A string cannot become “valid later” because a downstream template happens to stringify it. A missing required value cannot survive until model invocation. Layout cannot compensate for an input that never materialized.

FACET therefore turns a common runtime surprise into an earlier, classifiable failure. That does not prove the value is true, current, or safe. It proves something narrower and useful: the value crossed the declared boundary in an admissible shape.

Placement prevents hidden dependencies

FACET permits @input(...) as the whole value of an @vars entry, optionally followed by a lens pipeline. It rejects an input buried inside a composite literal:

@vars
  # valid
  query: @input(type="string") |> trim()

  # invalid: F452
  envelope: { query: @input(type="string") }

At first this may look restrictive. I see the restriction as an observability feature.

When every runtime input has a named variable node, the dependency graph can expose what depends on external data. Tests can inject the value directly. Diagnostics can identify the boundary that failed. An inspector does not need to search arbitrary nested expressions for concealed host dependencies.

The rule also blocks a subtle form of architectural drift. Without placement constraints, runtime reads can spread through structures, conditions, and message blocks until the contract looks declarative but behaves like code with ambient state. A narrow input position keeps impurity at the edge.

The type declaration is executable documentation

The type parameter is required. FACET supports primitive, composite, union, and multimodal types; defaults and supplied values must satisfy the declared input type. The compiler repository documents F453 specifically for runtime input mismatch, while broader static type mismatches use F451 and invalid placement or unsupported constraints use F452.

Those distinctions give an integrator a practical routing table:

F451 -> contract values or pipelines are statically incompatible
F452 -> the input/type construct itself is invalid or misplaced
F453 -> runtime data does not satisfy the declared input interface

A generic “render failed” error cannot tell the application whether to reject a client payload, repair the contract, or inspect a lens pipeline. Stable phase-aware diagnostics can. That is why I treat FACET error codes as a control plane, not merely prettier compiler output.

Types still have boundaries. type="string" cannot establish that a query is honest. A structured type cannot prove that a tool response came from the expected service. Semantic validation, authorization, and provenance remain separate responsibilities. The input contract should not claim more than shape and placement.

Tests become callers of the same interface

FACET @test blocks can provide an input map:

@test "trimmed-query"
  input:
    query: "  FACET  "
    limit: 2
  assert:
    - canonical contains "FACET"

This is more important than convenient fixture syntax. Production calls and tests address the same named boundary. A test does not need a special templating path that bypasses materialization.

A useful conformance set should cover at least four cases:

  1. a valid supplied value;
  2. a missing value resolved by a default;
  3. a supplied value rejected with F453;
  4. an illegally nested @input rejected with F452.

These tests do not evaluate model quality. They verify that request construction obeys its interface before any probabilistic component runs. That follows the broader principle behind executable FACET tests: assert deterministic structure before judging meaning.

An ABI is a promise of separation

Calling @input an ABI is my engineering interpretation, not terminology required by the FACET specification. The comparison is useful because an ABI is valuable precisely when two sides can evolve without sharing hidden assumptions.

The host may change how it obtains a query. The contract may change how it trims, combines, budgets, and renders that query. As long as both preserve the named typed boundary, the integration remains inspectable.

There are limits. FACET v2.1.3 defines contract compilation and execution boundaries; it does not make model generation deterministic, validate the truth of runtime data, or replace host-side authentication. The reference compiler is the implementation evidence for the behavior described here, not evidence of universal interoperability across independent compilers.

Still, this small boundary changes the architecture. Runtime data stops being template material and becomes an explicit dependency. Once that dependency is named, typed, materialized, and testable, the model call begins later—and engineering begins earlier.

Sources

FACET AI CLI Terminal
facet@ai:~$