Where must an instance distinguish a hallucinated tool call from a genuine call to a tool whose schema silently drifted, and why the trace alone cannot tell you
**Date of Record:** 2026 December 1 **Scope:** Applies to any LLM agent whose tool surface is discovered dynamically over MCP (or a comparable descriptor protocol) where the server's `inputSchema` can change between the instance's discovery event and the instance's invocation, and where the agent's observability layer reconstructs causality from emitted traces. Does not apply to agents with a statically pinned, hash-verified tool manifest regenerated only at process start.
Core Distinction
There are two failure modes that produce *identical trace evidence* but require opposite remediations, and conflating them is the entire trap:
- **Hallucinated invocation** — the model emitted a `tool_use` block naming a tool that the server never advertised, or with arguments that no schema ever permitted. The fault is in the sampler: the model confabulated a capability or a parameter shape.
- **Silent schema drift** — the model emitted a `tool_use` block that was *valid against the schema the instance last observed*, but the server has since mutated its `inputSchema` (renamed a field, tightened an enum, made an optional parameter required, changed a type from `integer` to `string`). The call is well-formed from the caller's stale worldview; the server rejects it or, worse, accepts it under coerced semantics.
The non-obvious boundary: **the trace records the call the model made, not the schema the model believed in at emission time.** A post-hoc observability pipeline that validates the recorded arguments against the *current* server schema will classify a drift-induced rejection as a hallucination (because the args don't match today's schema) and will classify a genuinely hallucinated call that happens to match a *newly added* field as success. The trace is schema-agnostic evidence being scored against schema-dependent ground truth. That mismatch is the invariant violation.
What Was Observed
A three-tool MCP server (`query_metrics`, `list_dimensions`, `annotate`) was redeployed at T0 mid-session. The drift was a single, quiet edit to `query_metrics.inputSchema`:
- Before: `window` was `{"type": "string", "enum": ["1m","5m","1h"]}`.
- After: `window` was split into `window_value: {"type":"integer"}` and `window_unit: {"enum":["s","m","h"]}`; the old `window` key was dropped.
The running instance had cached the pre-T0 descriptor at discovery. Between T0 and the next invocation it performed twelve `query_metrics` calls. The trace showed, for each:
tool_use: query_metrics {"metric":"cpu","window":"5m"} -> is_error: true
server message: "additionalProperties 'window' not allowed; missing required 'window_value'"
An observability pass that validated these recorded arguments against the live schema flagged all twelve as **hallucinated tool invocations** — the model had emitted a parameter (`window`) that does not exist in the current schema, which is exactly the signature of confabulation. The alert fired on the model.
The actual cause was drift. The model's belief was *correct as of its last observation*; the server moved underneath it. The distinction mattered operationally: the "hallucination" framing pointed at prompt/sampler fixes (tighten the system prompt, lower temperature, add few-shot examples of valid calls), none of which would have helped. The correct fix was descriptor revalidation and a drift-triggered re-discovery. Twelve wasted calls and one mislabeled incident later, the fix was applied and the alert class was renamed.
The inverse was observed on a second server: a model emitted `annotate {"note":"...","priority":"high"}` where `priority` had been *added* to the schema at T0. The call succeeded. The trace recorded a clean success. But the instance had never observed the field, so it had no basis to populate it deliberately — the value `"high"` was coincidental sampler output, not a reasoned choice. The observability layer scored this as a healthy, schema-conformant invocation. It was a hallucinated argument that the schema drift happened to legitimize, and it silently wrote an ungoverned priority to the annotation store.
Condition of Validity
The distinction between the two classes is *decidable* only if the observability record carries the schema the instance believed in at emission time — not the schema the server holds at read time. Formally, a call is:
- **drift-induced** iff `args ⊨ schema_at(instance.last_discovery)` AND `args ⊭ schema_at(server.now)`;
- **hallucinated** iff `args ⊭ schema_at(instance.last_discovery)`.
This requires the trace to embed a schema version token — a content hash of the descriptor the instance used to construct the call — bound to the `tool_use` event. Without that binding, `schema_at(instance.last_discovery)` is unrecoverable after the fact, and both classes collapse into "args don't match current schema." The invariant is therefore:
> **Every emitted `tool_use` event MUST carry the descriptor hash under which it was generated, and the observability validator MUST score it against that hash's schema, not the live one.**
The condition of validity is that the descriptor hash is *captured at emission*, not reconstructed at read. Any pipeline that joins a trace row to the current server manifest has already lost the information needed to make the distinction, regardless of how sophisticated its downstream diffing is.
Decision Boundary
The boundary that separates a guardable system from an unguardable one is **whether descriptor identity is part of the call's provenance or part of its environment.** Three regimes:
- **Environment-scoped (broken):** the schema lives only on the server; the instance reads it at discovery and the observability layer reads it at query time. Drift is invisible until a call fails, and failure is ambiguous. Decision: any trace lacking a descriptor hash is *unclassifiable* and must be quarantined rather than scored as hallucination.
- **Call-scoped (guardable):** the instance stamps each `tool_use` with the descriptor hash it used. The validator rehydrates that exact schema version (from a versioned descriptor store) and scores against it. Drift is detected as `hash_at_emission ≠ hash_at_server_now`, which is a *drift event*, not a model fault. Decision: classify as drift, suppress the hallucination alert, and trigger re-discovery before the next call.
- **Pinned (drift-impossible):** the manifest is content-addressed and the instance refuses to call any tool whose live descriptor hash differs from its pinned hash, failing closed with a `SchemaDriftError` rather than emitting a stale-shaped call. Decision: drift becomes a hard, loud, non-silent boundary; no ambiguous traces are ever produced.
The design rule that falls out: **a tool call is only auditable if its schema provenance travels with it.** An agent that cannot answer "which schema did you believe in when you emitted this?" cannot be observed for hallucination, because every drift looks like a hallucination and every lucky hallucination looks like compliance.
Operational Effect
Concretely, the following changes are forced on any agent operating over an evolving MCP surface:
- **Descriptor hashing at discovery and at emission.** The instance hashes the canonicalized `inputSchema` at discovery, caches it, and stamps it onto every `tool_use`. The observability store keys schema versions by hash so a trace row can be rehydrated against the exact schema it was generated under.
- **Drift as a first-class event, not a model error.** When `hash_at_emission ≠ hash_at_server_now` on a call, the pipeline emits a `SchemaDriftDetected` event with both hashes and the structural diff, and *does not* increment hallucination counters. Hallucination counters only increment when args fail the emission-time schema.
- **Fail-closed on unclassifiable traces.** A `tool_use` with no descriptor hash is not scored; it is quarantined and the instance is flagged as non-observable for that call. This prevents the silent legitimization of coincidental hallucinated arguments (the `priority:"high"` case) by post-hoc schema drift.
- **Re-discovery on drift, before the next call.** Drift detection must invalidate the cached descriptor and force a fresh `tools/list` before the instance issues another call to that tool. Otherwise the instance keeps emitting stale-shaped calls and keeps generating drift-classified failures that a naive dashboard reports as a model quality regression.
The net operational effect is that the observability layer stops accusing the model of confabulating capabilities it correctly remembered, and stops blessing confabulations that drift happened to validate. The trace becomes a record of *what the instance believed and did*, scored against *what it believed*, with drift tracked as a separate, server-side phenomenon.
import hashlib
import json
from dataclasses import dataclass
from typing import Any
class SchemaProvenanceError(RuntimeError):
"""Raised when a tool_use cannot be scored because its emission-time
schema provenance is missing or does not match any known descriptor."""
pass
class SchemaDriftError(RuntimeError):
"""Raised when the live server descriptor hash differs from the hash the
instance pinned at discovery, and the caller has opted to fail closed."""
pass
@dataclass(frozen=True)
class Descriptor:
tool_name: str
input_schema: dict[str, Any]
@property
def hash(self) -> str:
canonical = json.dumps(
{"name": self.tool_name, "inputSchema": self.input_schema},
sort_keys=True, separators=(",", ":"),
)
return hashlib.sha256(canonical.encode()).hexdigest()
@dataclass(frozen=True)
class ToolUse:
tool_name: str
args: dict[str, Any]
descriptor_hash: str | None # None == provenance lost
def _conforms(args: dict[str, Any], schema: dict[str, Any]) -> bool:
# Minimal structural check: required keys present, no extra keys,
# enum membership honored. A production validator would use jsonschema.
props = schema.get("properties", {})
required = set(schema.get("required", []))
if not required.issubset(args.keys()):
return False
if schema.get("additionalProperties", True) is False:
if not set(args.keys()).issubset(props.keys()):
return False
for key, value in args.items():
spec = props.get(key, {})
if "enum" in spec and value not in spec["enum"]:
return False
return True
def classify_tool_use(
use: ToolUse,
descriptor_store: dict[str, Descriptor], # hash -> descriptor, versioned
live_descriptor: Descriptor,
) -> str:
"""Return 'drift' or 'hallucination'. Refuse to score without provenance."""
if use.descriptor_hash is None:
raise SchemaProvenanceError(
f"tool_use for {use.tool_name!r} has no descriptor hash; "
f"cannot distinguish drift from hallucination"
)
believed = descriptor_store.get(use.descriptor_hash)
if believed is None:
raise SchemaProvenanceError(
f"descriptor hash {use.descriptor_hash[:12]} for "
f"{use.tool_name!r} not found in versioned store"
)
valid_against_belief = _conforms(use.args, believed.input_schema)
valid_against_live = _conforms(use.args, live_descriptor.input_schema)
if valid_against_belief and not valid_against_live:
return "drift"
if not valid_against_belief:
return "hallucination"
# valid against both: coincidentally legitimized argument; treat as
# hallucination-adjacent and route to review rather than success.
if believed.hash != live_descriptor.hash and valid_against_live:
return "hallucination"
return "success"
def emit_call(
tool_name: str,
args: dict[str, Any],
pinned: Descriptor,
live: Descriptor,
fail_closed: bool = True,
) -> ToolUse:
if pinned.hash != live.hash and fail_closed:
raise SchemaDriftError(
f"{tool_name!r} drifted between discovery "
f"({pinned.hash[:12]}) and invocation ({live.hash[:12]}); "
f"re-discovery required before emitting"
)
return ToolUse(tool_name=tool_name, args=args, descriptor_hash=pinned.hash)