Conditionals Belong in the Compiler, Not the Model
A model should never be asked to choose which version of its own contract is real. When a system prompt says "if this is production, be strict; if it is a demo, be loose," it hands the model a branch it is not equipped to evaluate deterministically — and a wrong choice there is invisible until it has already contaminated output. FACET takes the branch out of the model's hands entirely. Conditional evaluation is a compile-time step: false branches are pruned from the document before the model ever runs, so the model receives exactly one resolved contract, not a decision to make.
This is not a new idea in software. The C preprocessor resolved #ifdef before compilation for decades, and feature flags resolve before a binary ships. What is unusual is that FACET applies the same discipline to the document an AI model is about to read. The reason matters more than the mechanism: a contract is a boundary, and a boundary you let the model redraw is not a boundary.
The model must not choose its own contract
Most agent code encodes branching as prose. "Use the strict policy when the user is in the EU." "Fall back to the simple format for older models." Each of these is a conditional that lives inside the model's reasoning, evaluated with whatever consistency the model happens to produce that run. Two identical requests can take two different branches, and neither branch leaves a record of why.
The cost shows up as control loss. A conditional is a control-flow decision, and control flow is exactly the layer you want deterministic. When branching lives in the prompt, determinism is a hope. When it lives in the compiler, it is a fact you can replay.
FACET's answer is the if attribute. Any facet or list item can carry an if="EXPR" attribute, where EXPR is a small, bounded expression. If the expression is false, the node — and everything nested under it — is removed from the document before anything else happens. There is no "maybe" state. There is no partially-evaluated branch. The false path simply does not exist in what the model receives.
A bounded expression language
The expression language is deliberately tiny, because a branch condition should not be a programming language. It has:
- Operands: string and number literals, booleans,
null, a variable name, or a nested path likecfg.lang. - Comparison:
==,!=,<,<=,>,>=, andin. - Logic:
and,or,not, with parentheses for grouping.
String comparison is lexicographic; number comparison is numeric. There are no function calls, no loops, no side effects, and no way to reach out to a model. An expression either resolves to true or false, or it fails to compile.
@vars
mode: "expert"
features: ["recursion", "tail-calls"]
@system(role="Deep Technical Expert", if="mode == 'expert'")
constraints:
- "Use precise terminology"
@plan
- "Intro"
- "Tail recursion" (if="'tail-calls' in features")
Here the list item "Tail recursion" survives only because 'tail-calls' is a member of features. Change that variable, rebuild, and the item is gone from the canonical output — not hidden behind a hint the model might ignore, but absent from the document itself.
A broken condition fails loudly, with its own error block: F701 for a parse error, F702 for an unknown variable, F703 for a type error, and F704 when the expression is not a quoted string. These are compile-time failures. A conditional that references a variable you never declared, or compares a string to a number, does not reach production as a silent wrong answer; it stops the build. That is the difference between a boundary and a suggestion.
Where the branch is cut
The interesting part is not that conditionals exist, but where they sit in the compile pipeline. FACET's canonicalization order is explicit, and the position of conditionals inside it is what makes them safe.
- Imports are expanded and merged.
- Variables are resolved and substituted.
- Variable types are validated.
- Conditionals are evaluated and false nodes are pruned.
- Anchors and aliases are resolved.
- Lenses are applied.
Two properties follow from this order. First, conditionals run after variable resolution and type validation, so an if expression only ever sees final, valid values. You cannot write a condition against a variable that does not exist yet, and you cannot write one against a value whose type has not already been checked. The condition reads resolved state, not a promise.
Second, conditionals run before anchors and lenses. A pruned branch never contributes an anchor, never triggers a lens, and never appears in canonical JSON. This matters because it means conditional pruning is structural, not cosmetic. It changes the shape of the document, not just a value inside it. A lens is a pure transformation, and a pure transformation should never be asked to run on a branch that was never meant to be part of the final contract.
Pruning, not a flag
The distinction between "the model ignores the other branch" and "the other branch does not exist" is the whole article. When you pass a model a document with both branches present and a note saying "use the production one," you have given it the capacity to choose wrong. Even a model that chooses right had to spend reasoning deciding, and that reasoning is not reproducible.
Pruning removes the capacity. There is no @system(if="env=='prod'") and @system(if="env=='dev'") both present in the output. After evaluation, one remains. The model cannot select the wrong branch because the wrong branch was never in its input.
This is the same principle I wrote about in capability projection: projection removes tools the model is not allowed to call from its vocabulary before inference, and conditional evaluation removes branches that are not live from the document before inference. Both are forms of the same move — shrink the model's world to exactly what is authorized, instead of asking it to police itself.
It also connects to the type system. Types check a value before it reaches the model; conditionals decide which structure reaches the model at all. One bounds the data, the other bounds the shape. Between them, what a model receives is a single, fully-determined contract, and everything the contract was not supposed to contain was removed by the compiler, not by the model.
What EXPR deliberately refuses to do
The tightness of the expression language is the point, not a limitation to be relaxed later. A conditional that could call a function, read a file, or query a model would reintroduce exactly the nondeterminism it exists to remove. The moment a branch condition depends on something that can change at runtime, the compile-time guarantee evaporates.
That is why there is no if that invokes a lens, and no if that talks to a model. If a condition genuinely depends on the model's output — "if the answer is risky, apply stricter validation" — that is not a compile-time branch; that is a runtime decision, and it belongs in a guard, a policy check, or a retry gate, not in the document the model reads. FACET keeps those two worlds separate. The document is determined before the model runs; what the model does is governed after it runs.
I keep returning to this split because it is where most agent systems blur the line. They mix configuration, policy, and reasoning into one prompt and call it a contract. FACET's answer is to give each concern its own stage and its own failure codes, so a wrong branch is a build error, not a subtle production misbehavior you discover weeks later.
A contract is either determined before inference or it is not a contract. Conditional evaluation is how FACET makes that sentence true, one pruned branch at a time.
Sources
- FACET Language Specification v1.1 (Draft r3) — §3.10 conditional attributes, §3.10.1 EXPR, §9.1 canonicalization algorithm, §11 error codes.