Practical technical guides / Agent-era architecture

Let Agent Tools Read Service Responses as Tolerant Readers, Not Strict Mirrors

Put a small deterministic adapter between an existing service and an agent tool: validate only consumed fields, ignore the rest, escalate unknown states and count drift.

By Sandeep Belgavi · Published 2026-11-24 · Prepared 2026-11-23

Put a small deterministic adapter between an existing service and an agent tool: validate only consumed fields, ignore the rest, escalate unknown states and count drift.

A tool that breaks when the service improves

Most agent tools are thin wrappers over services that already exist. An order-lookup tool calls the order service, turns the JSON response into something the model can read, and returns it. The quickest way to write that wrapper is to generate a model class from the service's full response schema and validate every response against it. The tool then mirrors the service exactly, and it breaks the first time the service team adds a field.

That failure is worse with an agent than with a human-facing screen. A screen that fails shows an error page and someone files a bug. An agent tool that fails returns an error to the model, and the model improvises: it retries, picks another tool, or tells the customer something plausible that is not true. The service change was harmless, and the agent's behaviour changed anyway.

This guide applies an old integration pattern, the tolerant reader, to agent tools. The adapter between the service and the tool reads only the fields the tool consumes, ignores everything else, turns values it does not understand into an explicit outcome that sends the case to a person, and counts what it ignored so the drift stays visible. The worked example is an order-lookup tool for help-desk cases at the fictional Belgavi's Book Store.

What the tool actually consumes

Start by writing down what the tool needs, not what the service returns. The order-lookup tool needs four values: the order id, the order status, the total amount and the currency. The service returns more: a customer block, line items, a creation timestamp, and, in later versions, gift-wrap flags and carrier events. None of those extra fields change what the tool tells the model.

That list of consumed fields is the contract between the tool and the service. It is much smaller than the provider schema, and it is the only part worth enforcing. Everything else is the service's business. Martin Fowler's description of the tolerant reader makes the same point for service consumers in general: take only what you need, and be as forgiving as you can about the rest.

The adapter returns one shape to the agent, always:

@dataclass(frozen=True)
class OrderView:
    order_id: str
    status: str          # one of KNOWN_STATUSES, or 'escalate'
    raw_status: str
    total: Decimal
    currency: str
    note: str = ''

The model never sees the raw payload. That is a separate benefit: fields such as the customer's name or address do not end up in the model's context just because the service happened to return them.

Three rules for the adapter

The tolerant reader in the companion example applies three rules, and each one is deterministic code rather than something the model is asked to judge.

  • Unknown fields are ignored and counted. A new gift_wrap flag does not reach the agent and does not cause an error, but the adapter increments a counter named after it.
  • Unknown values of a consumed enum become escalate. If the status is not one the tool understands, the view says escalate, keeps the raw value, and adds a note that the case should go to a person.
  • A missing or malformed consumed field is a contract violation with a field path. If total.amount is gone or is not a decimal, the adapter raises an error naming total.amount. It does not guess.

The second rule is the one that matters most for agents. A status like partially_shipped might mean the customer is owed a partial refund, or nothing. A strict reader that rejects it gives the model an error. A careless reader that passes it through lets the model guess what it means. The tolerant reader does neither: it gives the model a value the tool's instructions can handle, escalate, and the agent's prompt tells it what to do with that value.

if raw_status in KNOWN_STATUSES:
    return OrderView(order_id, raw_status, raw_status, total, currency)
drift.note_status(raw_status)
return OrderView(order_id, 'escalate', raw_status, total, currency,
                 note=f'status {raw_status!r} is not one the tool understands; route to a person')

The third rule is what keeps tolerance from turning into silence. Being forgiving about fields you do not use is safe. Being forgiving about fields you do use is how wrong refunds happen.

The worked run

The example feeds four versions of an order payload through a strict mirror of the version 1 schema and through the tolerant reader.

Version 1 is unchanged. Both readers return status shipped for ORD-7001, total 24.50 EUR.

Version 2 is additive: the service adds gift_wrap and carrier_events, and a new status, partially_shipped. The strict mirror fails on the first unknown field it sees, carrier_events. The tolerant reader returns a view with status escalate and raw status partially_shipped, and records two unknown fields and one unknown status. Nothing the tool consumes changed, and the agent keeps working.

Version 3 renames total to grand_total. This time both readers fail, and they should. The strict mirror fails on the unknown grand_total, which is the right outcome for the wrong reason. The tolerant reader fails because total.amount is missing, which is the reason a person needs to see: a field the tool uses has disappeared.

Version 4 sends 24,50 as the amount. Both readers reject it. The tolerant reader's error includes the value, so the alert says what was wrong rather than only where.

At the end of the run the drift counter reads one each for carrier_events, gift_wrap and grand_total, and one for the status partially_shipped. Those counts are what turn a tolerant reader from "ignore changes" into "notice changes without breaking". Export them as metrics, alert when a new name appears, and review them when the service team announces a release.

What stays deterministic

Nothing in this adapter needs a model. The list of consumed fields, the set of known statuses, the mapping of unknown statuses to escalate, and the decimal parsing are all ordinary code with ordinary tests. The agent consumes the adapter's output; it does not decide how to read the service.

That split is the general lesson for adapting existing systems to agents. The service contract stays between two pieces of code. The model sits on the far side of the adapter, where it reads a small, stable shape. When people suggest letting the model read raw service responses because "it can figure out new fields", they are proposing to move contract interpretation from code you can test into behaviour you cannot.

Migrating an existing tool

If you already have tools that mirror provider schemas, the migration is small and can be done one tool at a time.

  1. List the fields each tool's output actually uses, by reading the tool's code and its prompt, and write them down as the tool's consumed contract.
  2. Build the narrow view type and an adapter that fills it from the raw response, with explicit errors for missing consumed fields.
  3. Decide, for every enum the tool consumes, what an unknown value means. For most agent tools the answer is a value that routes to a person.
  4. Run the adapter beside the existing mirror for a while and compare: every response the mirror rejects and the adapter accepts is a breakage you were about to have.
  5. Add drift counters and remove the full-schema validation from the tool path.

Keep the provider schema around for what it is good at: generating clients, documenting the service, and contract tests owned by the service team. It just should not be the gate between the service and the agent.

Tradeoffs and failure modes

A tolerant reader is not free. It can hide a meaningful change. If the service starts returning total in minor units, so 2450 instead of 24.50, a reader that only checks "is this a decimal" accepts it, and the agent quotes a refund a hundred times too large. Consumed fields need semantic checks, not just type checks: a range, a scale, a currency that matches the order's market. The example checks that the currency is three upper-case letters; a real adapter would check more.

Escalation can become a sink. If a new status is common, every case carrying it goes to a person, and the queue grows until someone updates the known set. That is the right failure, because it is visible and safe, but it needs an owner. The drift counter tells that owner which value to add.

Ignoring fields is only safe for reads. A tool that writes back to the service, for example by updating an order, must not drop fields it does not understand from a read-modify-write cycle. For write paths, send only the fields you intend to change, and let the service handle the rest.

When you do not need this

If the service and the tool are owned by the same team, deployed together and versioned together, a shared generated type may be simpler and the drift problem does not arise. If the tool passes a response through to a person rather than a model, strictness costs less, because a person can read an unfamiliar field. The pattern earns its place where a separately released service feeds a model that will act on what it reads.

Verification

The companion example has six tests: a v1 payload reads the same in both readers; an additive change breaks only the strict mirror; an unknown status is never guessed into a known one; a removed consumed field fails with its path; a malformed decimal fails loudly; and the whole run, including the drift counts, matches the table in this guide. Run python -m unittest -v in the example directory. The payloads are synthetic and nothing calls a real service.

Run the example yourself

The strict mirror, the tolerant reader, the four payload versions, the drift counter and six tests. Companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.

Primary references and authorship

Sources read 23 November 2026. Original explanation, measurements and synthetic examples by Sandeep Belgavi. Views are my own and do not represent any employer, past or present.

Related on this site: