$ fssg build --deterministic --validate |

FACET's Type System Makes Model I/O a Compile-Time Boundary

FACET

A wrong value should not reach a model just because nobody bothered to type it. Most agent code hands a model a bag of strings, floats, and dicts, then asks a system prompt to keep them honest. FACET takes the opposite position: a value is checked against a declared type before it leaves the compiler, and the value a model returns is checked again on the way back in. The type system is the boundary, and the boundary is a fact, not a request.

FACET calls this the Facet Type System, or FTS. It is not a general-purpose programming-language type system bolted onto a prompt. It exists to answer one question at every edge of a model call: is this value legal for the contract this run declared?

Three moments, one set of rules

A value can cross the model boundary at three different moments, and FTS checks each with the same rules.

Moment Where it is declared What fails
Declared @var_types — the ordered map of variable names to types computed value must satisfy the declared type
Computed pipeline steps — `$raw > trim()
Runtime input @input(type="int", default=3) a supplied or defaulted value must satisfy the type

The three moments matter because they are different failure modes. A declaration error is a compile error: the document itself is wrong. A pipeline error is a type mismatch between two lenses — the shape of the data does not fit the transformation. A runtime input error is the interesting one, because it is the only check that touches a value the author did not write. When a host supplies age="thirty" where the contract declared int, the failure is F453, and it happens at the boundary, not inside the model's reasoning. I have written separately about how FACET materializes these runtime inputs; here the point is only that the type check is the last deterministic gate before the model.

This is the point most prompt-based systems miss. They treat the model call as the place where validation happens. FTS treats the model call as the one place where you have already lost the ability to validate deterministically, so everything checkable gets checked before and after it.

Constraints are typed too

The type system's primitives are what you would expect: string, int, float, bool, null, and any. What makes FTS worth paying attention to is that a type can carry constraints, and those constraints are themselves typed.

A string accepts a pattern — a regex the value must match. An int or float accepts min and max. Any type can carry an enum — a fixed list of allowed values. A boolean or null can only carry an enum, because a range on a boolean is meaningless. And any, deliberately, carries no constraints at all.

The key distinction is the third column: FACET encodes which constraint is legal for which type. You cannot attach a numeric min to a string, because the type system knows a minimum is not defined for strings. An inapplicable constraint is a validation error, not a silently ignored annotation. I find this more important than the constraints themselves. A constraint that the compiler cannot tell you is impossible is a constraint you cannot trust, because it fails only in production, on a value you never saw.

@var_types
  username: "string"
  age: "int"
  status: "string | null"

@vars
  username: "alice"
  age: 30
  status: null

Here status is string | null — FACET expresses optionality as a union, not as a convention. There is no "maybe undefined" that slips past the compiler. Either the type is string, or it is string | null, and the difference is visible in the declaration.

Types that reach into content

FTS is not limited to text. It defines multimodal types whose constraints are physical:

  • image with format ∈ {png, jpeg, webp} and a max_dim;
  • audio with format ∈ {mp3, wav, ogg} and a max_duration;
  • embedding<size=N> where N > 0, a fixed-length numeric vector.

An embedding<size=1024> is a type, not a comment. The compiler knows it must be a vector of exactly 1024 numbers. This matters when embeddings flow between a retrieval system, a memory layer, and a provider — the three components stop agreeing on dimension by convention and start agreeing by contract. The type carries the dimensionality of the model call, which is exactly the kind of detail that silently drifts when it lives in prose.

Assignability, and the one deliberate escape hatch

FTS defines five assignability rules. A type T1 is assignable to T2 when T2 is any, when both are the same primitive and constraints are satisfied, when a union target contains an assignable member, when list/map elements are assignable, or when a struct target's required fields exist and are assignable.

Notice the first rule: any accepts everything. FACET does not pretend to close every hole. It gives you an explicit escape hatch and makes it visible, so a reviewer can see where the contract deliberately gave up checking. The danger is not a type system that has a bypass; the danger is a bypass you cannot see. In FTS the bypass is a named type, any, that shows up in the declaration instead of hiding in the runtime.

The same discipline applies to ordering. FACET rejects forward references — a variable must be declared before it is used. This is a small rule with a real consequence for determinism: if the compiler accepts code whose meaning depends on evaluation order, then two identical documents can mean different things. Requiring declaration before use removes a whole class of ordering ambiguity before it becomes a runtime bug.

From types to interfaces

The type system is also the source of truth for @interface definitions. FACET maps FTS types to JSON Schema — primitives, structs with required fields, lists, maps, unions, and embedding<size=N> as a fixed-length numeric array. An unmappable type raises F452. This is where the type system stops being an internal check and becomes the contract other tools generate against. The host SDK boundary is derived from the same types that validate the run, so the schema a caller sees and the validation a run performs cannot drift apart. The same mapping is what makes constraint loss across a provider change visible rather than silent — a topic I covered in why provider translation drops guarantees.

I built FACET around a simple belief: the contract layer should make the model call a controlled edge, and types are the cheapest deterministic check you can put at that edge. A type is not intelligence and it is not policy — it does not decide what the model may do, only what shape the values flowing in and out must have. But that is already a lot. It means a malformed request fails before it costs tokens, and a malformed result fails before it costs trust.

Sources

  • FACET Compiler (Rust) — crates/fct-validator, crates/fct-ast: https://github.com/rokoss21/facet-compiler
  • FACET v2.1.3 Type System reference: https://github.com/rokoss21/facet-compiler/blob/master/docs/04-type-system.md
FACET AI CLI Terminal
facet@ai:~$