Chapter 1 · Foundation Models as System Primitives
Lesson 2 of 24 · 3 min · English · Read-only
New learners often assume setting temperature = 0 turns a language model into a pure, deterministic function. In production, it does not. Floating-point addition on GPUs is non-associative: (a + b) + c can differ from a + (b + c) at the last bit depending on how your request is dynamically batched with other users' requests. In Mixture-of-Experts (MoE) architectures, tiny tie-breaking differences can even route a token to a different expert sub-network. Engineering rule: always treat model outputs as untrusted external inputs—just like user form submissions or third-party webhooks.
Intuition: Asking a model in plain English to "please return only valid JSON with no markdown backticks" is like asking a stranger to fill out a form on a blank sheet of paper. Constrained decoding hands them a digital form where invalid keys are physically disabled.
Mechanism: At every decode step (Step 4 in Figure 1.1), a finite-state machine (FSM) compiled from your JSON Schema inspects the model's raw probability distribution and masks out (sets to zero probability) any token that would violate the schema. This guarantees 100% syntactic schema adherence on the first try without expensive retry loops.
Because models generate tokens strictly left-to-right, field order inside your JSON schema directly affects accuracy. If you place the classification label first, the model must commit to an answer before it has written any supporting evidence. Putting a brief reasoning or evidence field before the label lets the model condition its final decision on its own intermediate analysis.
Broken Schema (Label First — Lower Accuracy)
{ "urgency": "P1_CRITICAL", "reasoning": "User says VPN is down for 1 person, not an outage..." }
The model guessed P1_CRITICAL on token 4, then rationalized or contradicted itself in reasoning.
Fixed Schema (Evidence First — Higher Accuracy)
{ "evidence": "Single user reports VPN timeout; no other tickets.", "urgency": "P3_NORMAL" }
The model extracts the scope of impact first, then accurately assigns P3_NORMAL.
Evaluation-Driven Development
Agents, Tool Use & Orchestration
Adaptation & Post-Training
Inference Physics, Security & Economics