Check the exact shape of data your agent sends and receives.
Write down the exact shape of data an agent sends to each tool and reads back from it, then check every real tool call against it: in pytest, in trace exports, and against the tool definitions the model is given.
What is fault-contract?
A contract is one small JSON file per tool. It specifies what the agent may send as request arguments and what it relies on receiving back as response data, using JSON Schema 2020-12 or Pydantic models.
Checks read data that was already sent and received: nothing calls a tool, a backend, or the network. When installed alongside faultgate-zero, pytest tests automatically evaluate tool contracts.
Known limit: trace-to-fixture 0.1.0 needs faultgate-zero below 0.2 and fault-contract needs 0.2 or newer, so the two cannot be installed in the same environment yet.
INSTALL & QUICKSTART
pip install fault-contract
pip install pydantic # only if a contract points at a Pydantic model{
"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"]
}
}
}format otlp (detected) traces 7 tool calls 17 with a contract 17
issue_refund request 1 of 2 calls
100% $.amount expected number, got string e.g. trace 7418fc74… step 3
issue_refund response 1 of 2 results
100% $.refunded expected number, got string e.g. trace 7418fc74… step 3
FAIL 2 violations in 1 tool01 / THREE SCHEMA SOURCES
| Source | Configuration | When to use |
|---|---|---|
schema | {"schema": {"type": "object", ...}} | Inline JSON Schema 2020-12 definition. |
schema_file | {"schema_file": "../../api/openapi.json#/components/schemas/RefundRequest"} | Local JSON Schema or OpenAPI JSON file relative to the contract file. |
pydantic | {"pydantic": "billing.api.models:RefundRequest", "strict": true} | Backend Pydantic model. Notice: importing a Pydantic model runs that module's import-time code. |
02 / COMMANDS
| Command | What it does | Exit codes |
|---|---|---|
fault-contract init | Draft contracts from tool definitions, Pydantic models, or trace exports. | 0 / 2 |
fault-contract check PATH... | Validates tool calls in exports and fixture folders against active contracts. | 0 clean, 1 violations, 2 input error |
fault-contract defs | Compares definitions against contracts (D1-D7 checks for missing fields and type drift). | 0 / 1 |
fault-contract explain PATH --trace ID | Step-by-step trace inspection with schema paths and Pydantic strict/lax outcomes. | 0 / 2 |
fault-contract contracts | Lists loaded contracts, their schema sources, and unchecked formats. | 0 / 2 |
03 / CONTRACT VS POLICY VS DEFINITION
| Dimension | Tool definition | Contract (fault-contract) | Policy (faultgate-zero) |
|---|---|---|---|
| Question answered | What does the model think this tool takes? | What exact shape must the data have, in and out? | What is the agent allowed to do? |
| Covers results | No | Yes (validates response shape) | Only "an earlier call succeeded" |
| Example | amount: number | amount is number > 0; customer_id required; no extra fields | issue_refund.amount <= 500; only after verify_identity |
| File location | Agent code | .faultline/contracts/*.contract.json | .faultline/policy.json |
RULE: DATA SHAPE BELONGS IN THE CONTRACT. BUSINESS BOUNDS BELONG IN POLICY.
04 / PRIVACY
Payload values appear only as redacted previews of 40 characters or fewer, and only in explain and the JSON and Markdown reports. The terminal output of check prints paths, messages, and locations without values. Locations are a hashed trace id and a step number.
Field names in paths are redacted too because dictionary keys can contain private data. Contract verification runs locally. Nothing leaves the machine.
05 / DEBUGGING
| Symptom | Likely cause | Fix |
|---|---|---|
"no contract" for a tool that has one | Names differ: matching is exact and case-sensitive. | check lists the names actually called. Make tool match. |
Exit 2 "invalid schema" | The schema violates JSON Schema 2020-12 metaschema. | The message names the file and schema path. Then run fault-contract contracts. |
Exit 2 "cannot import billing.api.models" | The backend package is not installed here. | Install it, or init --pydantic ... --snapshot. |
Many additionalProperties violations right after init | The model sends fields the definitions never listed, or a framework wraps the arguments. | explain shows the real keys. Add them, or allow extra on that object. |
06 / LIMITS
- Requires faultgate-zero 0.2.x or newer (installed automatically via dependencies).
- Importing a Pydantic model executes that module's import-time code; snapshot models if imports carry side effects.
- Known limit: trace-to-fixture 0.1.0 needs faultgate-zero below 0.2 and fault-contract needs 0.2 or newer, so the two cannot be installed in the same environment yet.
07 / THE FAULTLINE SUITE
fault-contract
Tool-call shape checks for request arguments and response results.
Current product →faultgate
Release gate over recorded traces with noise-aware statistical bands.
Open product →Need help checking agent tool contracts?
FAULTLINE offers fixed-scope diagnostic and production reliability audits. Production audits install and configure these tools when compatible.