Learning resourcesReviewed · Pydantic

Pydantic AI Harness: Repair Tool Arguments

This guide shows Python developers how to repair malformed tool-call JSON in Pydantic AI Harness, but ambiguous repairs can change the intended arguments. It explains installation, validation, message-history updates and tracing for the RepairToolArguments capability.

Researched 25 Nov 2026

In short.

This guide explains automatic repair of malformed tool-call JSON for Python developers using Pydantic AI Harness, with the catch that inferred arguments may differ from the model's intent. RepairToolArguments uses json-repair before normal schema validation, applies across an agent's tools and preserves repaired arguments in message history. The page provides setup instructions and a local TestModel example, but establishes no repair success rate, performance measurements, costs or licensing terms. Nothing was executed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://pydantic.dev/docs/ai/harness/repair-tool-arguments/index.md], including its 0.x API-change notice, setup example, validation limits, history behavior, telemetry and API reference. Linked pages and repository files are excluded. No code was executed; repair accuracy, runtime compatibility, live-provider behavior, performance, costs and licensing terms remain unverified or unknown as described.

The overview

Identity

Repair Tool Arguments is a feature guide within the Pydantic AI Harness documentation. It covers the RepairToolArguments capability, which repairs malformed JSON supplied by a model when calling an agent's tools. The original page is [https://pydantic.dev/docs/ai/harness/repair-tool-arguments/index.md].

The capability can be attached directly to an agent or obtained through Coder, which includes it.

Assessment

The guide is useful for understanding a focused recovery step: fixing JSON syntax before checking whether arguments meet a tool's schema. It explains both integration and less obvious behavior, including provider replay metadata and repair tracing.

Its main limitation is semantic uncertainty. A repair can produce valid arguments that differ from the intended request. The page provides no measurements of repair accuracy, latency or retry reduction, and its example does not explicitly demonstrate malformed input.

Users

The guide is most relevant to Python developers building Pydantic AI agents whose model-generated tool calls sometimes contain malformed JSON. Beginners get a compact installation and integration example; experienced developers get details about validation hooks, call history and telemetry.

It assumes familiarity with agents, tools and Python package installation. It does not provide a broader introduction to building an agent.

Capabilities

The documented repair cases include trailing commas, single-quoted keys and incomplete JSON. Valid JSON strings and already-parsed arguments pass through unchanged.

The capability applies to all tools on the agent, including tools supplied by other capabilities. After a repair, it updates the tool call in message history so subsequent requests replay the repaired arguments.

Using it

Requirements

The documented dependency is pydantic-ai-harness with the repair-tool-arguments extra, which installs json-repair. Importing RepairToolArguments without the extra raises an ImportError naming the missing extra. The coder extra also installs json-repair because Coder includes the capability.

The page does not specify a minimum Python version, exact dependency versions, operating-system requirements or a provider compatibility matrix. Its example uses the local TestModel.

Mechanism

The asynchronous before_tool_validate hook passes malformed JSON to json-repair before normal Pydantic AI tool-schema validation. The repair library receives no schema. Missing fields and invalid field types still follow normal validation and retry behavior. If repair raises ValueError or RecursionError, the original arguments proceed to normal validation.

For calls with a provider_name, the API reference says the original arguments and provider item ID are retained in call.provider_details as original_args and original_id. Moving the ID matters for OpenAI Responses: retaining it would cause replay of the provider's stored call instead of the repaired arguments.

Each repair attempt emits a repair_tool_arguments span through ctx.tracer. Valid JSON and parsed arguments do not emit that span. Repair spans contain no arguments or tool contents, even when trace_include_content is enabled; normal core tool spans continue.

Setup

The documented installation commands are pip install "pydantic-ai-harness[repair-tool-arguments]" or uv add "pydantic-ai-harness[repair-tool-arguments]".

Import RepairToolArguments from pydantic_ai_harness.repair_tool_arguments, then include RepairToolArguments() in the Agent constructor's capabilities list. The capability has no configuration options.

Example

The supplied example constructs Agent(TestModel(), capabilities=[RepairToolArguments()]), registers an asynchronous greet(name: str) tool with @agent.tool_plain, and returns a greeting containing the supplied name. It calls agent.run_sync('Greet someone') and prints result.output.

This illustrates how to attach the capability to an agent. It does not explicitly supply malformed JSON or show a before-and-after repair. No example code was executed, and no runtime output was independently established.

Assessment & evidence

Limitations

Repair is heuristic: incomplete or malformed input can admit multiple interpretations, and inferred strings may differ from the model's intent. Passing schema validation does not establish that the repaired request means what was intended.

The capability does not bypass validation, approval or execution checks. It has no configuration options and applies across the agent's tools. The page establishes no exhaustive malformed-input coverage, repair success rate or guarantee of correct interpretation.

Reasoning

The practical fit depends on whether syntax recovery is desirable for the application's tools. It may help a call reach validation when JSON formatting is the obstacle, while preserving the existing validation and approval stages.

A reasonable inference from the documented ambiguity is that evaluation should check argument meaning as well as parsing success. This is especially relevant when a tool's behavior depends on precise names or values. The page supplies no evidence that repairs preserve intent reliably enough for any particular application.

Alternatives

The page presents direct use of RepairToolArguments and use through Coder as two integration routes to the same capability. It also documents normal validation and retries as the path for missing fields, invalid types and specified repair failures.

Other repair libraries, provider-specific structured-output features and alternative agent frameworks are not compared. Their suitability relative to this capability is not assessed.

Evidence

The evidence consists of the complete selected documentation page at [https://pydantic.dev/docs/ai/harness/repair-tool-arguments/index.md]. It includes installation instructions, an agent example, validation and safety notes, history handling, telemetry details and an API reference.

The linked documentation index, Coder guide, version-policy page and GitHub source are outside the supplied evidence. Claims about behavior are documentation-based; implementation correctness, live-provider behavior and performance were not independently assessed.

Access & freshness

Costs

The page states no prices, subscription requirements or licensing fees. It also provides no measurements of repair overhead or savings from avoided retries. Those costs and effects are unknown.

The example uses a local TestModel and gives no basis for estimating live model-provider charges.

Rights

The page does not state licensing terms for the documentation, Pydantic AI Harness or json-repair. Commercial-use, modification and redistribution rights are therefore unknown from this evidence.

It links to source code at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/repair_tool_arguments/], but that repository's contents and license were not assessed.

Freshness

The supplied page snapshot was captured on 25 November 2026. The page warns that Pydantic AI Harness APIs may change between minor releases while on 0.x, with deprecation warnings and release-note migration guidance.

No exact package version, release date or page-update date is established. Compatibility with a particular installed version or later release remains unknown.

Actions

For adoption, confirm the API against the intended package version and choose direct attachment or Coder according to the agent's requirements. Install the corresponding extra.

Evaluate representative trailing commas, single-quoted keys, incomplete JSON, valid arguments, missing fields and invalid types. Check repaired values against intended meaning, inspect history metadata and confirm that existing validation and approval behavior remains appropriate. These are proposed checks; none were performed.

Evidence for this report

selected-page.txtselected · checked 2026-11-25