FACET Lens Trust Levels: A Typed Effect Boundary for AI
A data transformation inside an AI contract is never “just a helper.” The moment it reads a file, calls a service, depends on time, or can consume unbounded work, it changes the execution contract.
This is why I find the FACET lens model more interesting than a library of convenient text functions. A lens has a type, but it also has a trust level, a determinism class, a gas function, and—when it can touch the outside world—an effect class. Together these fields form a compact effect boundary for AI execution.
A pipeline should expose what it can do
The readable surface is intentionally small:
@vars
clean: " FACET " |> trim() |> lowercase()
fields: { id: 7, state: "ready" } |> keys()
The first pipeline has the shape string -> string -> string. The second turns an object into list<string>. FACET checks each transition through the Facet Type System; passing 42 to trim() is a compile-time type error (F451).
That prevents a familiar class of accidental failures, but typing alone is not enough. Two functions may share the same signature while having radically different operational meaning:
normalize(text) -> text
fetch_and_normalize(url) -> text
The first can be local and repeatable. The second performs I/O, depends on remote state, and may fail for reasons absent from its return type. If both appear as ordinary helpers, the contract hides the most important difference.
FACET makes that difference part of the registered lens identity:
| Field | Question it answers |
|---|---|
input_type / output_type |
Can this pipeline be composed safely? |
trust_level |
How far can the lens reach beyond pure local computation? |
determinism class |
Is the result pure, bounded, or volatile? |
gas_cost(input, args) |
How much bounded work may this invocation consume? |
effect_class |
What kind of external consequence must policy evaluate? |
This is not metadata for documentation. It controls whether execution is legal.
Three levels, three different contracts
FACET v2.1.3 defines three lens trust levels.
Level 0 is deterministic and performs no I/O. Standard operations such as trim, lowercase, keys, sort_by, and ensure_list belong here. They are the natural building blocks for reproducible compilation and layout. Even a regex-capable Level-0 lens must use linear-time-safe behavior; “pure” does not excuse pathological resource use.
Level 1 permits bounded external behavior under a cache contract. In Pure Mode, it cannot quietly perform I/O. It may use an existing cache entry, but a miss fails with F803. The failure is a feature: replay remains replay rather than becoming an unnoticed live run.
Level 2 is volatile or nondeterministic. Pure Mode forbids it with F801. Exec Mode may allow it only when the host and the policy/runtime guard agree. For Levels 1 and 2, the registered effect_class is required; an absent or invalid class is itself an error (F456).
The useful distinction is not “safe versus unsafe.” It is which proof is required before this operation may participate in the run.
Mode changes authority, not meaning
I want execution modes to constrain authority without rewriting semantics.
A Level-1 lens does not become pure because a cache happens to contain its result. Its declared behavior remains bounded-external; Pure Mode merely chooses a legal cache-only path. A Level-2 lens does not become deterministic because one invocation returned the same bytes twice. Its volatility remains part of the contract.
That stability matters for review. The same .facet document can be inspected without pretending that environment changes alter the nature of its operations. Mode, host profile, effective policy, and cache state decide whether a declared operation may execute. They do not retroactively relabel it.
This fits the wider FACET policy model: capability says what authority exists, effect class describes consequences, and the runtime guard decides a concrete invocation. A lens pipeline therefore cannot smuggle network or filesystem work through an innocent-looking transformation stage.
Gas closes a second hidden boundary
Effects are not the only danger. Pure computation can still consume too much work.
Every lens invocation has a deterministic gas function, and the host defines a GasLimit. Crossing it fails with F902. This makes computational budget a contract input rather than an operational surprise.
The distinction between gas and token budget is important:
- gas bounds transformation work during evaluation;
- Token Box budget bounds what can enter model context during layout;
- policy and guard decisions bound authority and consequences.
These controls protect different resources. Combining them into one vague “budget” would erase failure ownership. A gas failure asks for a smaller computation or a different limit. A Token Box overflow asks for a different context allocation. A policy denial asks for different authority or evidence.
FACET already uses this separation elsewhere: stable R-DAG scheduling controls evaluation order, while the Token Box model controls context placement. Lens gas adds a bound inside the compute phase.
A registry is an executable review surface
A useful lens registry should let a reviewer answer four questions before deployment:
- Does every pipeline type-check end to end?
- Can any lens perform I/O or depend on volatile state?
- Which effect classes require policy and guard approval?
- Can worst-case transformation work exceed the configured gas limit?
This turns extension review into something more precise than reading helper code and hoping names are honest. A function called summarize might be a pure deterministic transform, a cache-backed external call, or a volatile model invocation. The name proves nothing. Its registered contract does.
There is a hard boundary here: trust levels classify declared behavior; they do not prove that an implementation is honest. A conforming host still has to enforce registry rules, sandbox or isolate extensions where required, account for gas correctly, and fail closed. The article explains the specification mechanism, not an empirical security guarantee for every plugin ecosystem.
The deeper design lesson
AI systems increasingly assemble requests through preprocessors, retrievers, formatters, tool-schema generators, and provider adapters. Most stacks type only the values and leave the transformations operationally untyped.
I think that is too weak. If a transformation can spend resources or create external effects, those properties belong beside its input and output types. Otherwise the pipeline has a typed data path and an untyped execution path.
FACET lenses show a stronger model:
value type
+ trust level
+ determinism class
+ gas bound
+ effect class
= reviewable transformation contract
That is the concrete shift. A pipeline stops being a chain of convenient functions and becomes a sequence of declared, bounded operations. For AI infrastructure, this is the difference between readable syntax and an execution contract I can actually reason about.