An added upstream field is compatible for code but changes agent decisions. Project tool results through a versioned allowlist, detect additions and replay first.
An additive change that changed a decision
The order service at Belgavi's Book Store has a lookup endpoint that every internal client uses. Its owners follow the usual rule for evolving a JSON API: never remove or rename a field, add new ones freely, and let clients ignore what they do not understand. That rule is why the warehouse dashboard, the invoice job and the customer site all survived the last release untouched. The release added two fields to every order: risk_score, a fraud estimate between 0 and 1, and loyalty_tier, which marks customers in the gold programme. It also added a nested internal.warehouse_note.
Geetha's refund agent calls the same endpoint as a tool. The agent receives the tool result as JSON, the model reads all of it, and the model proposes approve, refuse or escalate. Nobody changed the agent, its prompt or its model. On the day the release went out, three refunds that the agent used to approve went to a person instead, because the model now saw a risk score of 0.7 or more and treated it as a reason to escalate. One refund of 2,400 that used to be escalated as too large was approved, because the customer was gold.
Each of those outcomes may even be reasonable. The problem is that none of them was decided by anyone. A product decision about refunds, whether fraud risk or loyalty should influence them and at what threshold, was made implicitly by an upstream team adding a field for a different consumer. The tolerant reader rule protects code that ignores unknown fields. A model does not ignore them. For an agent, every field in a tool result is an input to the decision, so an additive change is a behaviour change.
What stays deterministic
The fix is not to stop upstream teams adding fields. It is to put a deterministic layer between the raw tool result and the model, and to change that layer only through review:
- A projection that passes only allowlisted fields to the model, with the allowlist version attached to the result. Everything else is dropped before the model sees it.
- A drift detector that compares the fields the upstream service actually returns with the allowlist and with a list of fields already reviewed and rejected. New fields raise a review item, not an incident.
- A replay that reruns recorded decisions with the current projection and with a candidate projection that includes the new field, and reports which decisions change.
The model stays the non-deterministic part. What it is allowed to see becomes a versioned, reviewed contract, exactly like the request schema the tool already has.
The projection
The companion example keeps the allowlist as data. Version 3 of the order lookup projection has five fields.
ALLOWLIST = {
'version': 3,
'fields': {
'order_id': 'string',
'status': 'string',
'delivered_days_ago': 'integer',
'amount': 'number',
'items': 'array',
},
}
def project(record, allowlist=ALLOWLIST):
shown = {k: record[k] for k in allowlist['fields'] if k in record}
dropped = sorted(flatten_keys(record) - set(allowlist['fields']))
missing = sorted(k for k in allowlist['fields'] if k not in record)
return ({'projection_version': allowlist['version'], 'result': shown},
{'dropped': dropped, 'missing': missing})Three details matter more than the code size suggests. The projection version is attached to the tool result, so a decision record can say which contract the model saw. Missing allowlisted fields are reported, not filled with defaults, because inventing a value for a field the model expects is a different bug. And dropped fields are listed with their nested paths, so internal.warehouse_note shows up as a dropped key and not as an opaque object.
For order BB-9002, the upstream record has nine keys after the release, counting the nested note. The model sees five, plus projection_version: 3. The report lists internal, internal.warehouse_note, loyalty_tier and risk_score as dropped.
Detecting upstream additions in CI
The drift check runs against recorded or sampled responses from the upstream service, for example the contract test fixtures the service publishes, or a nightly sample from a staging environment. It returns fields that are neither allowlisted nor already reviewed and rejected.
def upstream_additions(samples, allowlist=ALLOWLIST, known_dropped=()):
seen = set()
for s in samples:
seen |= flatten_keys(s)
return sorted(seen - set(allowlist['fields']) - set(known_dropped))On the twelve synthetic records in the example it returns the four new keys. After a review decides that internal and internal.warehouse_note stay hidden, they go into the reviewed-and-dropped list and the check is quiet again for them. A field that is neither added nor rejected keeps failing the check, which is the point: silence means a person made a decision.
This is the same pattern as a schema diff in consumer-driven contract testing, pointed the other way. The consumer is not checking that the provider still sends what it needs; it is checking that the provider has not started sending something nobody has reviewed.
Replay before exposure
Deciding whether to expose risk_score is a product decision, and it needs evidence. The replay takes recorded inputs, projects each one twice, and runs the decision for both views. In production the decision is a model call with the recorded prompt, the recorded tool results and the candidate projection, usually at temperature 0 and repeated a few times to see how stable the change is. In the example it is a deterministic stub that uses whatever fields it can see, which is enough to show the mechanics.
| Candidate projection | Cases | Decisions changed | Changes |
|---|---|---|---|
version 4 with risk_score | 12 | 3 | BB-9002, BB-9006 and BB-9011 move from approve to escalate |
version 4 with loyalty_tier | 12 | 1 | BB-9005 moves from escalate to approve |
| version 3 unchanged | 12 | 0 | none |
The table is the review artefact. The refund owner can now say whether three extra escalations in twelve cases are the intended effect of fraud risk, and whether gold customers should bypass the amount limit. If the answer is yes, the allowlist moves to version 4 with the field and a short note on why. If no, the field joins the reviewed-and-dropped list. Either way the decision record for every later refund says which projection version the model saw, so an auditor can tell a model change from a contract change.
Migration for an existing agent
Most agents in production pass tool results through unchanged. Moving to a projection does not need a big switch:
- Record, for a week, the raw tool results the agent receives and the fields that appear. This is the baseline allowlist, and it is usually larger than anyone expects.
- Remove from the baseline every field nobody can explain, then replay the recorded decisions with the reduced projection. Fields whose removal changes decisions are the ones the agent actually relies on; keep those and document them.
- Put the projection in the tool adapter, not in the prompt. A prompt instruction such as "ignore the risk score" still puts the value in front of the model, which is weaker than removing it.
- Add the drift check to the pipeline that deploys the agent, and to the upstream service's own pipeline if its owners agree. A failure there names the field and links to the replay.
- Store the projection version with each decision. It costs a few bytes and saves a long argument later.
Failure modes
Nested and dynamic keys. A field such as attributes that holds an open map defeats a flat allowlist. Allowlist the specific nested paths the agent needs, or project the map into a fixed structure in the adapter.
Meaning changes without new keys. If upstream changes amount from gross to net, nothing is added, and the drift check stays quiet. Contract tests on values and units still matter; the allowlist only covers which fields are visible.
Allowlist sprawl. If every review ends with "add it, it might help", the projection becomes the raw result again. The replay is the counterweight: a field that changes no decisions on recorded data has no evidence of benefit and some cost in tokens and attention.
Text fields. Free-text fields such as notes can carry instructions and personal data. Treat them as untrusted input even when allowlisted, and prefer structured fields where the agent only needs a fact.
When you do not need this. If the agent only renders tool results for a person, or the tool is owned by the same team that owns the agent and releases them together, a code review on the tool change is the same control. The allowlist earns its keep when the tool's owners have other consumers and their own release schedule.
Verification
The companion example pins its output in expected.json and its tests check four properties: only allowlisted fields reach the model and the version is attached; a missing field is reported and not invented; additions are detected and reviewed rejections are quiet; and the replay finds exactly the decisions that change, with an unchanged projection changing nothing. In a real system, add one more check: sample live tool calls and assert that the result the model received matches the projection of the raw result for the version recorded on the decision.