TL;DR — Constrained decoding and schema validation have mostly solved malformed tool calls. What remains is the reference problem: arguments that parse perfectly but point at things that don't exist or that the model never saw. Fix it by having the runtime mint handles, so the model picks from options instead of recalling identifiers.
Most teams treat function calling as a syntax problem. Get the model to emit valid JSON, validate it against a schema, retry on failure, ship. That framing was right two years ago. Today it optimizes the part that's already mostly solved.
The failures that survive in production look like this: the call is well-formed, every field has the right type, the schema validator is happy, and the argument is wrong anyway. order_id is a perfectly shaped UUID that belongs to nobody. The user_id is real, but it's another customer's. The model recalled an identifier from the middle of a long context and transposed two characters.
My thesis: a typed AI interface has to type references, not just shapes. A string that matches a UUID regex is not an order ID. It's a claim that an order ID exists. The model is a lossy copier making that claim, and your types don't know the difference.
Shape types are the cheap half
A JSON schema tells you that a field is a string, an integer in a range, or one of five enum values. That's structural information. It rules out a class of errors, and constrained decoding can enforce it almost for free.
But a schema can't express "this string must be one the user has already seen." It can't express "this record belongs to the current tenant." It can't express "this file path exists." Those are referential and relational properties. They live in your database, not in the schema.
So the typical stack has a gap. Types guarantee the argument is plausible. Nothing guarantees it is real. And plausibility is exactly what a language model is good at producing. A fabricated identifier is the model's native failure mode: fluent, well-formed, wrong.
Why identifiers are the worst argument type
Free-form text arguments tolerate small errors. A search query that's slightly off still returns something useful. Identifiers have no such tolerance. They are high-entropy, meaningless to the model, and require exact reproduction.
That's three bad properties at once:
Exact copy required. One wrong character turns a valid reference into a different valid reference or a dangling one.
No semantic redundancy. Natural language has error correction built in. A random UUID has none.
Silent collision. If the mangled ID happens to resolve, you act on the wrong entity and nothing errors.
The last one is the dangerous case. A dangling reference fails loudly and the agent can retry. A wrong-but-valid reference succeeds quietly. It's the AI version of a foreign key pointing at the wrong row, except no constraint exists to catch it.
Mint handles, don't ask for recall
The fix is to stop asking the model to remember identifiers. Make the runtime hand it a menu.
When a read tool returns three orders, don't return three UUIDs. Return three short, session-scoped handles, such as order_1, order_2, order_3, alongside the human-readable details. The runtime keeps a table mapping handles to real IDs. The mutating tool accepts only a handle. The model never has to reproduce a long opaque string, and it can't reference something the runtime didn't issue.
This changes the argument from recall to selection. Selection from a small closed set is something models do reliably. Recall of a random string from thousands of tokens back is not.
It also gives you a property you can enforce: every reference in a mutating call must resolve to a handle minted earlier in this session. That's checkable with a dictionary lookup, no model involved.
Dynamic enums are the same idea
If your serving stack supports schemas generated per request, push this further. For a step where the model must pick one of the candidates you just showed it, build the schema with an enum of exactly those handles. Constrained decoding then makes an out-of-menu answer unrepresentable rather than merely invalid.
Static schemas describe your API. Per-turn schemas describe this decision. The second is much tighter, and it's where typed interfaces get interesting.
Make the two phases explicit
The handle pattern suggests a structural rule: split tools into resolve and act.
Resolve tools take fuzzy input (a name, a description, a date range) and return handles with enough context to disambiguate.
Act tools take only handles and constrained parameters. They never accept free-form identifiers.
This mirrors a pattern from conventional engineering: parse, don't validate. In TypeScript terms, the resolve step is a parser that turns a loose string into a branded type like ResolvedOrder. The act function's signature demands that branded type, so the compiler refuses a raw string. The model-facing boundary does the parsing. Everything behind it works with values that are already known to be real.
The branding matters more than it looks. Without it, the validated and unvalidated values are both just string, and six months later someone adds a code path that skips resolution. With it, that shortcut won't compile.
Errors are part of the interface
When a reference fails to resolve, the error message is the next prompt. "Invalid order_id" teaches the model nothing and invites another guess, probably another fabrication.
Return something that reduces the search space: the handles that are currently valid, or the closest matches, plus an instruction to pick from them. You're converting a recall failure into a selection problem on the retry. A good error shape turns the second attempt into the easy case.
Also be careful what the error leaks. If "order not found" and "order belongs to another tenant" return different messages, the model, or an attacker steering it through injected text, can probe for existence. Handles scoped to a session sidestep this: the other tenant's orders were never issued, so they are never addressable.
How to test this
Schema-conformance tests are the wrong test. They'll pass at a very high rate and tell you little. Test the referential layer instead:
Fabrication probes. Replay scenarios where the right entity is only mentioned in passing, far back in context, and check whether the model invents or selects.
Near-miss collisions. Seed your test data with similar identifiers and see whether a mangled one lands on a neighbor.
Cross-scope attempts. Put another tenant's identifier in the context via a tool result and confirm the act tool rejects it.
Retry behavior. After a rejected reference, does the second call select from the offered options, or guess again?
Track "references that failed to resolve" and "references that resolved to something the user never mentioned" as separate metrics. The first is noise. The second is your real incident rate.
The takeaway
Constrained decoding made the model's output well-typed. It did nothing to make it well-grounded. As the syntax problem fades, the interesting work in typed AI interfaces moves up a level: from "is this valid JSON" to "does this value refer to something real, visible, and permitted."
Stop letting the model recall identifiers. Have the runtime issue handles, make act tools accept only handles, brand the resolved types, and write errors that offer a menu. Your schema should describe the shape of a call. Your runtime should guarantee what it points at.
Top comments (0)