How to Evolve AI Agent Output Schemas Without Breaking Workflows
Structured output solves the wrong problem if we treat the first valid JSON object as the end of engineering.
A schema can force an agent to return status, changes, and evidence. It cannot guarantee that tomorrow's runtime will interpret those fields the same way—or that today's runtime can consume tomorrow's artifact. The moment an output is stored, queued, replayed, reviewed, or passed to another agent, it stops being “the model response.” It becomes a protocol message with a history.
That history needs an explicit migration path.
My rule is simple: an agent artifact should declare its schema identity, enter the system through one normalization boundary, and leave that boundary in exactly one current internal form. Do not teach every consumer every historical version. Do not ask the model to migrate its own contract. Put evolution in deterministic code.
Valid JSON is not a durable contract
Provider-native structured output is valuable. OpenAI describes constrained decoding as restricting generation to tokens allowed by a supplied JSON Schema. It also documents the boundary clearly: schema conformance does not prevent incorrect values, refusals and interrupted generations require separate handling, and only a supported subset of JSON Schema is accepted.
Even perfect syntactic conformance would not solve evolution. Consider a planning artifact:
{
"schema": "plan/v1",
"goal": "rotate credentials",
"steps": [
{"tool": "vault.rotate", "args": {"service": "billing"}}
]
}
Version 2 introduces explicit approval and separates a proposed effect from executable steps:
{
"schema": "plan/v2",
"goal": "rotate credentials",
"effects": [
{
"kind": "credential_rotation",
"target": "billing",
"approval": "required"
}
]
}
Both objects can be valid. They are not interchangeable. Renaming steps to effects is not a cosmetic change: it alters authority, lifecycle, and consumer behavior.
This is why change sets are better than regenerated final state, but change sets also need stable meaning over time. A precise artifact without an evolution policy is only temporarily precise.
Choose compatibility from the replay direction
Schema registries distinguish backward, forward, full, and transitive compatibility. The terminology is useful, but agent systems should begin with an operational question:
Which old or new artifacts must this runtime be able to replay?
The answer determines the contract:
| Operational need | Required behavior |
|---|---|
| New runtime replays old runs | read old artifacts and upcast them |
| Old workers may receive new jobs | keep new artifacts readable by old consumers, or gate rollout |
| Long-lived audit archive | test compatibility against every retained version, not only the previous one |
| Ephemeral response used once | migration may be unnecessary; validation is still required |
Most agent platforms need strong backward-transitive reading: the current runtime must understand every retained artifact that can be resumed, audited, or re-evaluated. They do not necessarily need old runtimes to understand new artifacts. That asymmetry is useful. It allows a disciplined rollout: deploy readers first, then writers.
Adjacent-version checks are not enough for durable state. Version 3 may accept version 2, and version 2 may accept version 1, while the composed migration silently changes the meaning of version 1. Replay tests must cover the full supported chain.
The artifact gateway
I prefer one deterministic gateway between external artifacts and internal logic:
bytes
-> parse
-> identify schema
-> validate source version
-> upcast v1 -> v2 -> v3
-> validate current schema
-> check semantic invariants
-> attach migration receipt
-> current internal object
Each stage has one job.
Parse rejects malformed transport. Source validation proves that the object matches the contract it claims. Upcasters perform small, version-to-version transformations. Current validation catches migration defects. Semantic invariants check properties that JSON Schema cannot express adequately: approval must exist for a privileged effect; referenced artifacts must be resolvable; a terminal status must include evidence or a classified blocker.
The final receipt makes the transformation observable:
{
"artifact_id": "plan_01J...",
"source_schema": "plan/v1",
"target_schema": "plan/v3",
"migration_path": ["v1_to_v2", "v2_to_v3"],
"source_digest": "sha256:...",
"result_digest": "sha256:...",
"invariants": ["effect_authority", "terminal_evidence"],
"status": "accepted"
}
This receipt should join the execution trace, not disappear into a debug log. The trace-join model already connects runs, effects, and durable artifacts; schema migration is another causal edge. If a replay behaves differently, we need to know whether the model, policy, source artifact, or migration changed.
Upcasters must be boring
An upcaster should be a pure function:
upcast_v1_to_v2(v1) -> v2 | MigrationError
It should not call a model, fetch mutable context, infer missing intent, or apply side effects. If a field cannot be derived without guessing, the migration is not automatic.
There are only three honest choices:
- derive the new value deterministically from old fields;
- insert an explicit neutral state such as
approval: "unknown"and block execution until resolved; - reject the artifact for manual migration.
The second option is often the most useful. Unknown is not failure; invented certainty is. A runtime can display the old plan, preserve its provenance, and refuse the privileged effect until approval is supplied.
This principle mirrors Protocol Buffers' evolution discipline. Its official guide warns never to reuse field numbers and recommends reserving deleted numbers and names. The implementation detail differs for JSON, but the design lesson survives: a removed meaning must not be silently reassigned. Keep a tombstone registry for retired JSON fields and enum values. A future developer should not reuse approved for a different kind of consent because the old name happens to be available.
Structural compatibility is not semantic compatibility
Adding an optional field is often structurally safe. It can still change behavior.
Suppose version 2 adds:
{"retry_policy": {"max_attempts": 3}}
Old artifacts omit it. If the new runtime interprets omission as “use three retries,” replay now performs more effects than the original runtime. The schema evolved backward; the execution semantics did not.
Every schema change therefore needs two reviews:
- shape compatibility: can producers and consumers parse the objects?
- behavior compatibility: does the same artifact authorize the same effects, terminal states, and failure handling?
For agent systems, behavior compatibility is the stronger gate. Defaults should preserve previous behavior, especially around retries, permissions, spending, external writes, and completion. A new capability should begin disabled or unknown unless the old contract clearly implied it.
This is also why structured output belongs beside deterministic evaluation. The model may extract facts, propose a plan, or classify evidence, but the runtime computes the decision. The same separation appears in deterministic pickers: ask the model for bounded features; let code apply stable policy.
Test evolution as a matrix, not a snapshot
A schema's unit test should not be “the current example validates.” Use a migration matrix:
| Fixture | Source validation | Migration | Current validation | Semantic result |
|---|---|---|---|---|
| oldest supported success | pass | pass | pass | same authorized effects |
| old artifact missing new field | pass | pass | pass | neutral/default-safe |
| retired enum value | pass | explicit mapping or block | pass | documented |
| malformed claimed version | fail | not run | not run | quarantined |
| future unknown version | parse | reject | not run | no downgrade guess |
Keep golden fixtures for every retained version. Hash them. Run every migration path in CI. Add property tests where useful: upcasting must not create new effect targets; repeating normalization must be idempotent; rejected artifacts must never reach an executor.
Then test replay, not only conversion. Feed the normalized artifact into the policy and dry-run layers. Compare the resulting effect set with the historical expectation. This catches the dangerous class of migrations that preserve JSON shape while changing authority.
What this pattern does not guarantee
A gateway cannot prove that an agent's values are factually correct. It cannot rescue an underspecified old artifact, and it cannot make arbitrary breaking changes compatible. JSON Schema itself does not define a universal evolution policy; open versus closed content models and registry-specific rules matter. Provider structured-output implementations may also support only subsets of the standard.
The pattern provides a narrower guarantee: every supported historical artifact reaches current code through an explicit, tested, attributable transformation—or it is blocked before execution.
That is enough to change the engineering posture. Stored model output is no longer anonymous JSON. It has a version, a migration path, semantic invariants, and evidence of what happened to it.
An AI system becomes durable when it can explain not only why an artifact was produced, but why that artifact still means the same thing after the software around it has changed.