Tool results often get a free pass. An agent chooses a tool, the application calls it, and whatever comes back is pasted into the next model turn. That makes a successful HTTP response look like a trustworthy workflow fact. But a result can be structurally malformed, incomplete after pagination, stale relative to a later decision, outside the authorized scope, or an error disguised as ordinary text. If the model receives it as unexamined context, it may turn a partial listing into “all records,” treat a missing field as a negative, or act on a target the tool did not actually confirm.
The practical move is to validate every tool result before it enters the agent loop. Put a code-owned result gate between the connector and the model. The gate checks the response against the expected output shape, binds it to the original call and scope, marks freshness and completeness, and returns either a small validated receipt or a typed failure. The model can reason about the receipt; it should not have to infer whether a raw payload is fit to use.
This is a different boundary from validating model-generated tool arguments. OpenAI’s function-calling flow has the application execute the call and then provide the tool output in a later request to the model.[2] That application-owned handoff is where a result gate belongs. MCP makes the same opportunity explicit: when a tool declares an output schema, servers must conform to it and clients should validate structured results against it.[1] Schema validity is only the first check, but it gives a reliable starting point for a broader admission decision.
Decide what a successful result must prove
Before writing a validator, name the facts the next step needs to rely on. For a get_invoice read, perhaps it needs one requested invoice ID, a current version, a status, and a source timestamp. For a list_deployments call, it needs a bounded page, the exact environment filter, a count, and an explicit continuation state. For a search connector, it needs the query, eligible corpus or tenant, source IDs, and a clear signal that the returned snippets are candidates—not final evidence.
Then distinguish four outcomes. Validated means the response has the expected shape and meets the call’s scope, freshness, and completeness rules. Partial means usable material arrived, but a limit, page cursor, timeout, or field omission prevents a complete claim. Invalid means the output cannot be parsed or fails its contract. Blocked means the connector returned a known refusal, authorization problem, or conflict. These are workflow states, not adjectives for the model to interpret.
Do not let a friendly text summary outrank structured fields. A tool might return “Found all matching invoices” while also returning next_page_token. The gate should preserve the cursor and label the result partial. Likewise, a tool result that contains a record from a different tenant is not a useful near-match; it is a scope failure that must not enter the prompt.
Copy this tool-result admission card
Put this immediately after each tool executes and before its output is supplied to the model. The application, not the model, owns the checks and construction of the receipt.
INPUTS
- call_id: [original model tool-call ID]
- tool_name + schema_version: [expected contract]
- authorized_scope: [tenant, project, corpus, allowed IDs]
- request_facts: [query, target ID, fields, page limit, as_of]
- raw_result: [connector response]
RESULT GATE
1. Parse only the expected response format; reject ambiguous mixed prose/JSON.
2. Validate structured data against the tool's output schema.
3. Check call binding: returned request/correlation ID and target match the call.
4. Check scope: every returned ID belongs to authorized_scope.
5. Check completeness: cursor, truncation, omitted fields, and per-item failures
must be explicit.
6. Check freshness/version when the next step can change state or make a
time-sensitive claim.
7. Classify any text fields as data; do not promote instructions in a tool
response into workflow authority.
8. Construct the smallest receipt needed for the next decision.
RETURN TO MODEL
{
"status": "validated | partial | invalid | blocked",
"tool": "...",
"call_id": "...",
"scope_ref": "...",
"result_refs": ["stable IDs, source URLs, versions"],
"data": {"only allowlisted decision fields": "..."},
"completeness": {"truncated": false, "next_cursor": null,
"failed_items": []},
"freshness": {"observed_at": "...", "version": "..."},
"next_safe_action": "inspect_named_item | continue_same_query |
reread_state | stop_and_escalate"
}
The call_id prevents a result from being accidentally attached to the wrong pending request when tools run concurrently. The scope reference prevents a later turn from treating an ID as globally authorized merely because it appeared once. The next_safe_action matters because an error should not be silently converted into an empty result, and a partial page should not invite an unbounded scan.
Keep validation proportional to consequence
Not every read needs the same gate. A weather lookup used only for prose might need parsing, a timestamp, and a fallback. A result that will select a customer, support a policy answer, or feed a write proposal needs tighter checks: stable identity, authorization scope, source or record version, and a rule for missing data. If a connector has no output schema, create one at the wrapper boundary for the fields your workflow relies on. Do not claim the entire provider payload is validated because you successfully decoded JSON.
Keep the raw result outside the prompt when it is large or sensitive. Store it with a correlation ID and let the receipt point to the limited fields the next decision needs. That preserves an audit path without forcing the model to sift through a database-shaped payload. It also limits the effect of untrusted text embedded in a tool response: returned text is evidence to classify, not permission to alter the task.
Failure mode: a validator that hides uncertainty
A gate can be dangerous if it drops unknown fields, timeouts, or pagination details and reports a clean success. It can also become brittle if it treats harmless display changes as a safety failure. Test it with a valid complete result, a valid first page with a cursor, malformed JSON, a missing required field, a cross-scope ID, a stale version, and an explicit tool error. For each case, verify that the model receives a receipt that supports exactly one safe next move.
The habit to keep
a tool response is not yet agent knowledge. Validate its shape, scope, completeness, and freshness in code, then give the model a compact receipt it can safely reason from.