{"record":{"id":"29cd18ec4bef8795","repo":"vercel/ai","slug":"invalid-input-for-tool-toolname-geterrormess","errorCode":null,"errorMessage":"Invalid input for tool ${toolName}: ${getErrorMessage(cause)}","messagePattern":"Invalid input for tool (.+?): (.+?)","errorType":"validation","errorClass":"InvalidToolInputError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-text/parse-tool-call.ts","lineNumber":146,"sourceCode":"    return toolCall;\n  }\n\n  return {\n    ...toolCall,\n    input: await refine(toolCall.input as InferToolInput<TOOLS[keyof TOOLS]>),\n  } as TypedToolCall<TOOLS>;\n}\n\nasync function parseProviderExecutedDynamicToolCall(\n  toolCall: LanguageModelV4ToolCall,\n): Promise<DynamicToolCall> {\n  const parseResult =\n    toolCall.input.trim() === ''\n      ? { success: true as const, value: {} }\n      : await safeParseJSON({ text: toolCall.input });\n\n  if (parseResult.success === false) {\n    throw new InvalidToolInputError({\n      toolName: toolCall.toolName,\n      toolInput: toolCall.input,\n      cause: parseResult.error,\n    });\n  }\n\n  return {\n    type: 'tool-call',\n    toolCallId: toolCall.toolCallId,\n    toolName: toolCall.toolName,\n    input: parseResult.value,\n    providerExecuted: true,\n    dynamic: true,\n    providerMetadata: toolCall.providerMetadata,\n  };\n}\n\nasync function doParseToolCall<TOOLS extends ToolSet>({","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-text/parse-tool-call.ts#L128-L164","documentation":"InvalidToolInputError thrown when parsing a provider-executed dynamic tool call's `input` string with safeParseJSON fails — the model produced text that is not valid JSON. The SDK requires tool input to be JSON so it can type-check and forward arguments.","triggerScenarios":"A provider-executed dynamic tool call whose `input` is non-empty but malformed JSON (truncated output, markdown fences, trailing text).","commonSituations":"Small maxOutputTokens cutting JSON mid-stream; models emitting comments or ```json fences; provider quirk after version upgrade; streaming interruption.","solutions":["Check `error.cause` / `toolInput` to see the malformed JSON and increase maxOutputTokens if truncated.","Add `experimental_repairToolCall` to fix common malformations automatically.","Ask the model to output raw JSON only (prompt) or switch to a model with stricter tool-call JSON support.","Catch InvalidToolInputError (isInstance) and re-prompt the model for that step."],"exampleFix":"// before\nawait generateText({ model, prompt, tools, experimental_repairToolCall: undefined });\n// after\nawait generateText({\n  model,\n  prompt,\n  tools,\n  experimental_repairToolCall: repairToolCall, // fixes malformed JSON inputs\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isInvalidToolInput(e: unknown): e is InvalidToolInputError {\n  return InvalidToolInputError.isInstance(e);\n}","tryCatchPattern":"try {\n  await generateText({ model, prompt, tools });\n} catch (e) {\n  if (InvalidToolInputError.isInstance(e)) {\n    console.warn('malformed tool JSON:', e.toolInput, e.cause);\n    // retry with feedback or enable experimental_repairToolCall\n  } else throw e;\n}","preventionTips":["Set a generous maxOutputTokens so JSON tool arguments are not truncated.","Enable experimental_repairToolCall for models known to malform JSON.","Prompt the model to emit raw JSON without code fences."],"tags":["tool-calling","json","model-output"],"backgroundTag":"invalid-json-tool-arguments","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}