tool( )

Pattern

Tool Call Repair

Repair invalid tool calls using experimental_repairToolCall. Fix schema validation errors without requiring additional steps that pollute message history.

IntermediateNov 2025View the full pattern on desktop
Tool Call Repair preview

Problems solved

  • Repair malformed tool calls before retrying execution
  • Fix schema validation errors with generateObject
  • Avoid polluting message history with extra repair turns
  • Stream repair metadata to the client as data parts

Use cases

  • Agents using smaller models that misformat tool args
  • Complex Zod schemas that fail first-pass validation
  • Automatic tool-call error recovery
  • Improving tool success rates in production agents

AI SDK APIs

streamTextconvertToModelMessagestool(useChatexperimental_repairToolCallgenerateObjectNoSuchToolError

Tags

aitoolstool-call-repairexperimental-repairToolCallschema-validationerror-handlingai-sdktool-api

Requirements

Node.js
24+
Memory
512MB
Other
  • OpenAI API key

Environment variables

External services

openai

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View the pattern on desktop

Related patterns