Faultgate 0.5.0, Faultgate-Zero 0.2, Trace-to-Fixture 0.1 and Fault-Contract 0.1 are on PyPISee products →
Guides

Tool Call Validation: Check What Strict Mode Misses

Strict mode checks the arguments a model writes. It does not check tool results or recorded traffic. Tool call validation with contracts covers both.

Tool Call Validation: Check What Strict Mode Misses

Tool call validation is checking that the arguments an AI agent sends to a tool, and the result the tool sends back, match a contract you wrote down. Provider strict modes cover only the first half. Suppose (hypothetical) a refund agent without strict mode sends amount as the string "20.00". A default Pydantic backend coerces the text and the refund goes through (Pydantic). A contract check on the recorded run fails: $.amount: expected number, got string (fault-contract README).

01 / Tool call validation has two directions, and strict mode covers one

Strict mode is a provider setting that restricts the tool name and the arguments a model may generate. OpenAI says setting strict to true will "ensure function calls reliably adhere to the function schema, instead of being best effort" (OpenAI function calling). Anthropic says strict: true "guarantees Claude's tool inputs match your JSON Schema by constraining the model's token sampling to schema-valid outputs", and that the tool name is always valid (Anthropic strict tool use).

The other direction has no equivalent setting. Your application runs the tool, then feeds the result back to the model (Google Cloud). That result can be structured JSON or plain text (OpenAI function calling), and it often carries content from sources outside your control: webpages, inbound email, user uploads, third-party APIs. Anthropic's guidance is to treat that content as untrusted (Anthropic handle tool calls).

Tool use is fragile before validation enters the picture. On tau-bench, a benchmark of tool-agent-user interaction, even gpt-4o succeeded on under 50% of tasks, with pass^8 under 25% in retail (tau-bench). pass^8 means success on all eight repeated attempts. The metric is end-to-end task success, so it says nothing about argument error counts. It does show that a two-way loop fails often enough that both edges deserve a check.

02 / What strict mode guarantees, in the providers' own words

Strict mode makes argument shape reliable for supported schemas. Each provider still puts the rest of the work on your application.

The mechanics are strict at the schema level. OpenAI requires every field or function parameter marked required (OpenAI structured outputs), and additionalProperties: false on every object (OpenAI structured outputs). A schema that breaks those rules with strict on is an API error (OpenAI structured outputs). Anthropic documents that without strict mode the model can omit required fields, "breaking your functions and causing runtime errors" (Anthropic strict tool use).

Strict mode also leaves room for failure. OpenAI says in some cases "the model might not generate a valid response that matches the provided JSON schema" (OpenAI structured outputs). It says your application "still needs to handle refusals, incomplete responses, and API errors, and validate any business rules that the schema does not express" (OpenAI structured outputs). JSON mode is a different feature, and it does not guarantee that a response conforms to a particular schema (OpenAI).

OpenAI's launch post reports 100% on its own complex-schema eval for gpt-4o-2024-08-06 with Structured Outputs, against under 40% for gpt-4-0613 (OpenAI). Read that as a vendor eval on chosen schemas. It is not a production error rate.

The failure this section does not cover is the one researchers name first. Gorilla attributes API-call errors to the model's "inability to generate accurate input arguments" and its "tendency to hallucinate the wrong usage of an API call" (Gorilla). We found no published number that separates wrong types from missing fields. Treat argument errors as a documented failure mode with no rate attached.

03 / Your validator's defaults are looser than strict mode

A backend or a test that validates with library defaults accepts data strict mode would refuse.

The two settings strict mode forces are off by default elsewhere. JSON Schema, a standard format for describing JSON data, allows additional properties (JSON Schema) and allows properties to be omitted (JSON Schema). Pydantic, a Python validation library, "will attempt to coerce values to the desired type when possible" (Pydantic), while its strict mode errors on data of the wrong type (Pydantic). JSON Schema itself never converts types, so a string against a number field is a violation (fault-contract README).

RuleStrict modeLibrary default
Extra fieldsadditionalProperties: false required (OpenAI)additional properties valid (JSON Schema)
Missing fieldsevery property required (OpenAI)omitted properties valid (JSON Schema)
Wrong typeschema-valid output only (Anthropic)Pydantic coerces when possible (Pydantic)

The gap also appears between the definition the model sees and the model your backend validates with. In fault-contract's bundled refund example, the contract requires amount, and the tool definition marks it optional. The definitions check prints:

TEXT
issue_refund WARN D7 $.amount is required by the contract, but the tool definition marks it optional

The model is never told that the backend needs the field (fault-contract README).

04 / Tool responses drift while your schema stays the same

An API owner can change the result your agent reads without touching your code or your prompt.

GitHub's REST API documentation lists removing or renaming a response field, changing a field's type and removing enum values among breaking changes (GitHub). Adding a response field is additive and non-breaking (GitHub). Stripe releases new API versions monthly with no breaking changes, and a major release with breaking changes twice a year (Stripe). An open enum, meaning a set of allowed values that can grow, can receive new values without an API version upgrade (Stripe).

A response contract lists the fields the agent actually reads. That is the point of writing the response side down. A new field passes and costs nothing. A removed field, a changed type or an unexpected enum value fails in the check, where the change is visible, instead of in a downstream decision.

The protocol layer has the same idea. In MCP (Model Context Protocol), the specification for serving tools to a model, a tool may declare an outputSchema for structured results (MCP specification). Servers MUST return results that conform to it, and clients SHOULD validate results against it (MCP specification). The specification's security guidance says to validate tool results before passing them to the LLM (MCP specification).

Error results are their own trap. If a call fails and the response still violates the contract, the likely cause is that the result was not recognised as an error (fault-contract README). Return an explicit error signal: an error flag, an Error: prefix or an error field.

We found no source that measures how often response shapes drift in production. The mechanism is documented. The frequency is not, so do not put a rate in a slide.

05 / One contract per tool, checked in pytest and on exported traces

A contract is one JSON file per tool. It says what the agent may send and what it relies on getting back, in JSON Schema 2020-12 or as the tool's own Pydantic model.

FAULTLINE makes fault-contract, a free open-source tool under the MIT licence, at version 0.1.0 alpha (fault-contract). The check reads data that was already sent and received. Nothing calls a tool, a backend or the network (fault-contract). It covers results, where a tool definition does not (fault-contract).

The refund example ships with the tool. Its contract looks like this (README):

JSON
{
  "contract": 1,
  "tool": "issue_refund",
  "owner": "billing",
  "request": {
    "schema": {
      "type": "object",
      "properties": {
        "order_id": { "type": "string", "pattern": "^[0-9]{4,}$" },
        "amount": { "type": "number", "exclusiveMinimum": 0 },
        "customer_id": { "type": "string" }
      },
      "required": ["order_id", "amount", "customer_id"],
      "additionalProperties": false
    }
  },
  "response": {
    "schema": {
      "type": "object",
      "properties": {
        "refunded": { "type": "number" },
        "order_id": { "type": "string" }
      },
      "required": ["refunded", "order_id"]
    }
  }
}

When the fake model sends amount as "20.00", the run fails in pytest with the schema path and the mismatch (README):

TEXT
faultgate-zero: 1 check fired on run 'refund-double-charge' (3 steps, 4 model calls)
contract step 3 issue_refund request $.amount: expected number, got string
step 3 issue_refund response $.refunded: expected number, got string

With faultgate-zero installed, pytest runs the check through a plugin entry point, so existing tests need no change (README). Check recorded traffic in continuous integration (CI) by exporting runs and pointing the command at the file:

BASH
pytest --fgz-export-otlp runs.json
fault-contract check runs.json

Exports come from faultgate-zero itself or from Langfuse, LangSmith, Braintrust and OpenInference (README). Where checks run matters as much as the checks. Unit tests catch the shapes your fixtures use. A weekly trace export catches the shapes production sends. A definitions check catches the contract field the model was never told about (README). The CI setup is in faultgate-zero, the trace method is in production traces to tests, and the wider testing workflow is in how to test AI agents.

The same idea works without FAULTLINE. Apply the strict settings from section 03 to a response schema of your own, and run it over recorded calls in CI. Any validator can do the shape check. The value comes from covering both directions and from checking recorded data instead of a hand-written fixture.

06 / The same boundary check is part of a security control

A schema check on arguments is also a security boundary, as long as it is reported with the rest of the enforcement layer and its cost.

FAULTLINE's P09 research held four structural attack categories at a 0.0% attack success rate across 400 live runs by intercepting calls at the execution boundary (FAULTLINE research). That result belongs to a runtime policy. A schema validator on its own did not produce it.

Publication 02 measured a wider provenance contract. The contract enforces envelope formatting, tool enumeration allowlists, strict schema argument boundaries and verbatim substring grounding against the user's turns (FAULTLINE research). Pooled valid attack success fell from 30.32% to 7.41% (FAULTLINE research). In that contract, substring grounding false-blocks 24.5% of legitimate actions when tasks require ungrounded world knowledge, measured over 10,227 replayed traces (FAULTLINE research).

The 30.32% to 7.41% result does not come from schema checks alone. Report the components and the false-block rate together, or the number credits one control with the work of four. The security framing sits in MCP security.

BAR CHART

MCPTox valid attack success, pooled across six models

Unit: %
0%8.3%16.7%25%33.4%30.32%No contract7.41%Full provenance contract
Source: FAULTLINE Publication 02. The contract has four parts, schema checks are one. False blocks: 24.5%
View accessible data table
SetupASR
No contract30.32 %
Full provenance contract7.41 %

07 / What to change on Monday

The decision: turn on strict mode for every tool whose schema supports it, then write one contract per tool covering request and response. The owner: the engineering owner of the agent, with each tool's owning team reviewing its contract.

Start where a wrong argument costs money or moves data out. Refunds, payments, email, file writes. Turn on strict mode first, and fix the schemas it rejects. Then write the response side, listing only the fields the agent reads.

Run the check in two places. In pytest, where it covers the shapes your tests exercise. In CI over a weekly trace export, where it covers what production actually sent. Run the definitions check in the same job so the model is told every field the backend requires (README).

Track two numbers. Coverage: the share of tools with a contract that covers both directions. Violations: contract failures per 1,000 recorded calls, split into request and response so you know which side is failing.

Business rules stay in your application (OpenAI structured outputs). A contract that amount is a number above zero does not say a refund is allowed. That limit belongs in policy, with the rest of the agent's permissions.

The tooling is free. fault-contract is open source, and the research behind the boundary check is published with its numbers and its limits. The paid offer is the AI Agent Audit, for a team that wants an outside read on the agent itself.

Questions#

What is tool call validation?

Tool call validation is checking that the arguments an agent sends to a tool, and the result the tool returns, match a contract you wrote. The request side covers the tool name and argument shape. The response side covers the fields and types the agent relies on. Provider strict modes constrain only the request side.

Does strict mode guarantee valid tool calls?

For supported schemas it constrains the arguments and tool name the model generates. It does not cover the result your application or a third-party API returns. OpenAI also says the application must still handle refusals, incomplete responses and API errors, validate business rules the schema does not express, and expect cases where the model does not produce a schema-valid response.

How do you validate a tool call response?

Write a response schema that lists only the fields the agent reads, then validate the result before it goes back to the model. MCP tools can declare an outputSchema, and the specification tells clients to validate results against it. Recorded traces let you check responses after the fact without calling the API again.

Should I validate tool calls with Pydantic or JSON Schema?

Either works, and the same contract idea applies to both. JSON Schema 2020-12 is the neutral format and never converts types. A Pydantic contract can point at the backend model itself and run in strict mode, with lax mode reported separately. Set the strict options either way: required fields, no extra properties, and no type coercion.