$ fssg build --deterministic --validate |

Canonical JSON as an Intermediate Representation for AI Systems

FACET

AI systems need a point where probability stops being an excuse.

A model may propose text, tool arguments, or a plan. The execution layer still needs a stable artifact it can compare, hash, cache, sign, inspect, and render for different providers. Raw model output is not that artifact. An ordinary in-memory object is not enough either: two serializers can represent the same apparent value with different key order, number spelling, escaping, defaults, or omitted fields.

In FACET, that boundary is Canonical JSON. It is the intermediate representation between a typed execution state and provider-specific payloads. The important idea is not “use JSON.” It is: define one normalized meaning, then require one stable byte representation of it.

JSON syntax is not an identity function

These documents are easy for a human to read as equivalent:

{ "limit": 4.0, "mode": "strict" }
{"mode":"strict","limit":4}

But byte comparison says they differ. A naïve hash says they differ. Depending on the implementation, a cache key or signature may also differ.

The problem becomes sharper in AI infrastructure. Provider adapters add defaults. SDKs reorder fields. Optional values disappear in one language and become null in another. Floating-point serialization varies at the edges. Strings can have equivalent-looking but distinct Unicode sequences. A streaming path may construct a different shape from a non-streaming path.

A schema can validate both objects while leaving these representational choices unresolved. Validation answers whether a value is allowed. Canonicalization answers which representation is authoritative.

The IR boundary

FACET v2.1.3 defines a five-phase path: resolution, type checking, reactive computation, layout, and render. Canonical JSON is produced at the render boundary from the typed state, computed variables, finalized Token Box layout, and interface schemas.

.facet source
  -> typed AST
  -> deterministic computation
  -> bounded context layout
  -> Canonical JSON IR
  -> provider adapter
  -> provider payload

This placement matters. OpenAI, Anthropic, Gemini, and future APIs do not become the system of record. Their payloads are disposable views. Canonical JSON records what the contract layer decided before an adapter translated that decision into a vendor dialect.

That is a narrower and more useful claim than “canonical JSON makes model inference deterministic.” It does not. FACET explicitly does not standardize model internals or inference behavior. The IR stabilizes the request context and execution contract around the probabilistic component.

For the wider contract architecture, see FACET v2.1.3 and FACET Policy as Executable Authorization.

Canonicalization has two jobs

The word normalization hides two different operations. Mixing them creates subtle bugs.

1. Semantic normalization

Before serialization, the system decides what the artifact means:

  • which fields exist;
  • whether a missing optional value becomes explicit null;
  • which defaults are materialized;
  • how tools and messages are ordered;
  • which number domains are accepted;
  • whether source strings are normalized;
  • which provider-neutral names and types form the IR.

These are contract decisions. Changing them can change behavior even if the serializer remains identical.

2. Canonical serialization

After the semantic object exists, the serializer decides how it becomes bytes:

  • deterministic object-key ordering;
  • stable primitive and number formatting;
  • defined string escaping;
  • UTF-8 output;
  • no insignificant whitespace;
  • rejection of unsupported values such as NaN and infinity.

FACET v2.1.3 requires RFC 8785 JCS or equivalent serialization for Canonical JSON. RFC 8785 defines a hashable JSON representation through deterministic property sorting, constrained number serialization, string rules, and UTF-8 generation.

The boundary is crucial: a serializer must not silently “improve” semantic values. For example, RFC 8785 preserves parsed string data rather than applying Unicode normalization during serialization. FACET separately normalizes source text to NFC and its Canonical JSON model specifies string normalization. That policy belongs before the JCS byte step. Semantic normalization chooses the value; canonical serialization freezes that value.

What FACET makes stable

The FACET Canonical JSON model fixes a provider-agnostic top-level artifact containing metadata, tools, and messages. It defines metadata such as the FACET version, execution profile and mode, host profile, document and policy hashes, budget, and target provider. Tool order follows resolved interface order. Messages follow canonical role order while preserving source order within each role.

Known optional fields are explicit rather than left to serializer convention. Empty lists and objects stay explicit. Numbers and strings follow defined constraints. Nested objects receive deterministic key ordering.

A simplified artifact looks like this:

{
  "metadata": {
    "facet_version": "2.1.3",
    "mode": "pure",
    "policy_hash": null,
    "profile": "hypervisor"
  },
  "tools": [],
  "messages": [
    { "role": "system", "content": "Return a typed decision." },
    { "role": "user", "content": "Evaluate request 42." }
  ]
}

The displayed formatting is for readers. The canonical byte stream has one prescribed representation.

Stable bytes create engineering handles

Once the same semantic state produces the same bytes under the same declared profile and version, ordinary systems techniques become available.

Hashing. A digest can identify a compiled request artifact rather than an incidental serializer output.

Signing. A signature can bind to invariant bytes. RFC 8785 was designed precisely because cryptographic operations need repeatable representations.

Caching. Cache keys can incorporate canonical inputs, lens versions, host profile, and FACET version without treating field-order noise as a miss.

Comparison and snapshots. Diffs expose contract changes instead of formatting churn. A test can compare a canonical artifact or its hash before any provider call.

Replay and audit. Stored request context remains interpretable independently of the vendor payload generated on a particular day.

These are architectural capabilities, not benchmark results. This article does not claim that canonicalization improves model quality, latency, or production reliability by a measured percentage. It removes representational ambiguity from a specific boundary; the surrounding implementation must still be conformant and tested.

This is also why FACET is not a replacement for JSON or YAML. The language expresses contracts; Canonical JSON is the compiled artifact those contracts produce.

Hash the right thing

“Canonical” does not mean every hash proves the same fact.

FACET distinguishes at least three identities:

  1. document_hash identifies the normalized, resolved source form.
  2. policy_hash identifies the effective policy together with its policy semantics version.
  3. A canonical-artifact hash can identify the rendered request context.

They answer different questions: Which program was compiled? Which authorization semantics applied? Which request artifact was rendered? Collapsing them into one digest makes provenance less precise.

The execution artifact is separate again. It records guarded operations and policy decisions, potentially with a hash chain and attestation. Canonical JSON describes request context; the execution artifact describes provenance. Stable serialization supports both, but does not erase their semantic boundary.

Limits and failure modes

Canonical JSON is only as trustworthy as its contract and implementation.

  • If two implementations disagree about semantic defaults, canonical serialization will faithfully produce two different artifacts.
  • If a host changes asset processing or another semantic rule without changing host_profile_id, old and new hashes may be misleadingly compared.
  • RFC 8785 numbers are constrained by the I-JSON/IEEE 754 model; larger integers and exact decimal values need an explicit string or domain encoding.
  • Canonicalization does not validate business meaning, authorize a tool, prove an adapter preserves semantics, or make model output repeatable.
  • A claimed “equivalent” canonicalizer needs conformance tests, especially for Unicode, escaping, nested ordering, and number edge cases.

The fail-closed rule should therefore apply here too: if the renderer cannot produce the required canonical form, it should emit no substitute artifact.

The compiler lesson for AI systems

Compilers became portable because they stopped translating every source language directly into every machine target. They introduced intermediate representations with explicit invariants.

AI infrastructure needs the same move. Without an IR, provider payloads become architecture, SDK defaults become semantics, and serialized accidents become cache identities. With a canonical IR, the provider adapter becomes what it should be: a backend.

FACET's broader thesis is that AI execution needs a formal contract layer. Canonical JSON makes that thesis operational at one precise point. It takes a typed decision and gives it a stable identity before probability re-enters the system.

That is not the whole solution to reliable AI. It is the byte-level boundary that lets the rest of the solution be tested.

Sources

For the complementary part of this workflow, see Semantic Digests for Reproducible Multimodal AI Inputs.

FACET AI CLI Terminal
facet@ai:~$