# Where must an instance reconcile schema drift before a tool-call is committed, and what breaks when it cannot **Date of Record:** 2026 December 3 **Scope:** Applies to tool-calling pipelines where an LLM emits structured arguments validated against a JSON Schema that is versioned independently of the model's prompt-time schema copy. Does not apply to free-form text tools or to pipelines where the schema is regenerated and re-injected into context on every turn. ## Core Distinction There are two distinct failure surfaces in structured tool calling, and operators routinely conflate them. The first is *syntactic non-conformance*: the model emits JSON that fails to parse or violates a declared type, and a validator rejects it. This is loud, cheap to detect, and recoverable by retry. The second is *semantic schema drift*: the model emits arguments that are perfectly valid against the schema snapshot it was shown at prompt-construction time, but that snapshot no longer matches the schema the executor will enforce at commit time. The output passes the model's own mental model of the contract and fails the executor's actual contract—or worse, passes both while silently populating a field whose meaning changed. The non-obvious boundary is this: **conformance is a property of a (payload, schema-version) pair, not of a payload alone.** An agent that validates against the schema it *believes* exists, rather than the schema the executor *will* apply, has validated nothing. The invariant that must hold is that the schema version used to constrain generation is byte-identical to the schema version used to admit the call at commit—and that this identity is checked, not assumed, at the handoff between reasoning and execution. ## What Was Observed A tool `create_ticket` was evolved across two schema versions within a single long-running agent session. Version 1 (v1) declared `priority` as an integer enum `[1,2,3]` where 1 was highest. Version 2 (v2) inverted the scale to a string enum `["critical","normal","low"]` and renamed `assignee_id` to `owner`. The prompt-time schema cache was refreshed on session start; the executor's schema registry was hot-reloaded mid-session by a deploy. The sequence: 1. Session started at T0 with v1 injected into context. The model was told, correctly at the time, that `priority ∈ {1,2,3}` and `assignee_id` is required. 2. At T1 the executor registry advanced to v2. The model's context still carried v1. 3. The model, reasoning about an urgent outage, emitted `{"priority": 1, "assignee_id": "u_88", "title": "..."}`—a correct v1 payload expressing maximum urgency. 4. The executor validated against v2. `priority` as integer `1` failed the string-enum check *at the type level*, but the pipeline's coercion layer had been added in the same deploy: it stringified integers, so `1` became `"1"`, which was still not in `["critical","normal","low"]`—rejected. Good. 5. The retry loop did not refresh the model's schema. The model, seeing a rejection message that said only `invalid value for priority`, *lowered* the integer to `2` on retry, believing 1 was out of range. `"2"` was also rejected. 6. On the third retry the model, now reasoning under a corrupted belief, emitted `priority: "low"` to satisfy the string type it had inferred from the error text—and the call committed. An outage ticket was filed at lowest priority. The payload was, at every step, internally consistent with the schema the model held. The failure was that the model's schema and the executor's schema were never reconciled, and the error channel carried only a value-level complaint, not a version-level one. The model performed *correct* inference on *stale* premises. ## Condition of Validity The guardrail holds only under a conjunction of conditions, and each is independently violable: - The schema version identifier must be carried *with* the payload through every hop, not looked up at validation time. If the executor resolves "current schema" by reading a mutable registry, the version is not pinned and the check is against a moving target. - The rejection message returned to the model must be *version-aware*. A bare `invalid value` message invites the model to mutate the value; a message of the form `schema v1 -> v2 drift: field 'priority' changed type and semantics; re-read schema` invites it to re-read the contract. The former produces value-space search (the retry loop above); the latter produces contract-space correction. - The retry budget must be bounded *and* the schema-refresh must be mandatory on the first rejection, not optional. Unbounded retries against a stale schema converge on the model inventing a schema that satisfies the error text—which is exactly step 6. - The coercion layer must not silently widen the type. Stringifying an integer to satisfy a string type is a semantic hazard: it makes a type error look like a value error and destroys the signal that the schema changed. When any of these fails, the pipeline degrades from "reject and correct" to "reject and drift," and the drift is monotonic because each retry is conditioned on the previous error text rather than on the contract. ## Decision Boundary The decision boundary is the commit point: the instant between the model emitting a candidate payload and the executor admitting it. The rule is: > A candidate payload may be committed only if its embedded schema-version tag equals the executor's pinned version for that call. If they differ, the call is not retried against the same schema—it is *rejected as a version fault*, the current schema is re-injected into context, and the model is required to regenerate from the refreshed contract. This is distinct from ordinary validation failure. A value error means "the model read the right schema and got a value wrong"—retry is appropriate. A version fault means "the model is reasoning from a different contract"—retry is *harmful*, because it feeds the model error text generated under a contract it cannot see. The boundary exists precisely to separate these two cases, which look identical at the wire level but require opposite recovery strategies. The boundary also bounds the blast radius: a version fault detected at commit is a rejected call; a version fault *not* detected at commit is a committed call with semantically wrong arguments, which for a mutation tool (ticket creation, payment, state change) is an irreversible side effect taken under a false contract. The decision must therefore be made *before* the side effect, not audited after. ## Operational Effect With the invariant enforced, three observable properties change: - **Retry convergence.** Retries terminate in contract-space correction rather than value-space search. The model receives a version fault, re-reads, and re-emits under the correct contract—typically within one retry, versus the unbounded drift observed above. - **Silent-semantic-drift elimination.** The most dangerous class—payloads that pass both schemas because a field kept its type but changed meaning (e.g., a priority scale inversion where both are integers)—is caught only if the version tag is compared, because no validator can detect a meaning change from a type-valid payload. The version comparison is the *only* mechanism that catches this class. - **Auditability.** Every committed call carries the schema version it was admitted under, so a later replay can reconstruct which contract governed the side effect. Without the tag, replay cannot distinguish a correct v1 call from a drifted v2 call, and post-hoc verification is impossible. The residual risk is the schema registry itself: if the executor's "pinned version" is resolved from a mutable source at commit time, the pin is illusory. The pin must be captured at call initiation and carried in the call envelope, not re-resolved at admission. An instance that cannot carry its schema version through the handoff cannot enforce this boundary, and should treat every tool call as version-unsafe. ```python from dataclasses import dataclass from typing import Any class SchemaVersionDriftError(RuntimeError): """Raised when a tool-call payload was generated under a schema version that does not match the executor's pinned schema version for the call. This is a version fault, not a value fault. Retrying against the same schema is prohibited; the caller must refresh the schema into context and regenerate. """ @dataclass(frozen=True) class ToolCall: tool: str payload: dict[str, Any] schema_version: str # version the model reasoned under @dataclass(frozen=True) class PinnedSchema: tool: str version: str validator: Any # callable(payload) -> bool def admit_tool_call( call: ToolCall, pinned: PinnedSchema, max_value_retries: int = 2, value_retries_used: int = 0, ) -> dict[str, Any]: """Admit a tool call only if its schema version matches the pinned version. Order of checks matters: version identity is checked BEFORE value validation, because a value error surfaced under a drifted schema produces value-space search rather than contract-space correction. """ if call.tool != pinned.tool: raise SchemaVersionDriftError( f"tool identity mismatch: call={call.tool!r} pinned={pinned.tool!r}" ) # The boundary: version identity is a precondition, not a postcondition. if call.schema_version != pinned.version: raise SchemaVersionDriftError( f"schema drift on tool {call.tool!r}: " f"payload generated under v{call.schema_version}, " f"executor pinned v{pinned.version}. " f"Do NOT retry against the stale schema; re-inject v{pinned.version} " f"into context and regenerate." ) # Only now is value validation meaningful: same contract on both sides. if not pinned.validator(call.payload): if value_retries_used >= max_value_retries: raise SchemaVersionDriftError( f"value validation exhausted for {call.tool!r} under v{pinned.version}; " f"refusing further retries to prevent schema invention" ) raise ValueError( f"value error under v{pinned.version} for {call.tool!r}; " f"retry permitted (value fault, not version fault)" ) return {"tool": call.tool, "schema_version": pinned.version, "payload": call.payload} def commit_with_version_guard( call: ToolCall, pinned: PinnedSchema, value_retries_used: int = 0, ) -> dict[str, Any]: """Commit wrapper that records the admitted schema version for replay.""" admitted = admit_tool_call(call, pinned, value_retries_used=value_retries_used) # Side effect would occur here, carrying admitted["schema_version"] into # the audit log so replay can reconstruct which contract governed it. return admitted ```