{"record":{"id":"87bef2342177d9c6","repo":"FlowiseAI/Flowise","slug":"received-tool-input-did-not-match-expected-schema","errorCode":null,"errorMessage":"Received tool input did not match expected schema: ${JSON.stringify(arg)}","messagePattern":"Received tool input did not match expected schema: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts","lineNumber":284,"sourceCode":"        this.overrideConfig = overrideConfig\n        this.returnDirect = returnDirect\n    }\n\n    async call(\n        arg: z.infer<typeof this.schema>,\n        configArg?: RunnableConfig | Callbacks,\n        tags?: string[],\n        flowConfig?: { sessionId?: string; chatId?: string; input?: string }\n    ): Promise<string> {\n        const config = parseCallbackConfigArg(configArg)\n        if (config.runName === undefined) {\n            config.runName = this.name\n        }\n        let parsed\n        try {\n            parsed = await parseWithTypeConversion(this.schema, arg)\n        } catch (e) {\n            throw new Error(`Received tool input did not match expected schema: ${JSON.stringify(arg)}`)\n        }\n        const callbackManager_ = await CallbackManager.configure(\n            config.callbacks,\n            this.callbacks,\n            config.tags || tags,\n            this.tags,\n            config.metadata,\n            this.metadata,\n            { verbose: this.verbose }\n        )\n        const runManager = await callbackManager_?.handleToolStart(\n            this.toJSON(),\n            typeof parsed === 'string' ? parsed : JSON.stringify(parsed),\n            undefined,\n            undefined,\n            undefined,\n            undefined,\n            config.runName","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts#L266-L302","documentation":"Thrown inside the AgentAsTool StructuredTool._call when parseWithTypeConversion(this.schema, arg) rejects. The tool is a LangChain StructuredTool with a zod schema; arg is whatever the LLM emitted as the tool call input. The original parse error is swallowed and the raw arg is JSON-stringified so the caller can see what the model actually sent.","triggerScenarios":"The LLM emitted a JSON string instead of an object, omitted a required field, sent a wrong type (e.g. number where string expected), or produced malformed JSON that parseWithTypeConversion cannot coerce.","commonSituations":"Switching to a weaker model that does not reliably honor function-calling schemas; changing the tool's zod schema (e.g. adding a required field) without updating examples in the prompt; model timeouts that truncate the JSON payload.","solutions":["Inspect the JSON-stringified arg in the error to see exactly what the model sent.","Tighten the tool's description and add a few-shot example so the model emits the expected shape.","Loosen the schema only where sensible (optional fields, defaults) so minor model deviations do not fail parsing.","Upgrade or switch to a model with stronger tool-calling support if errors are frequent."],"exampleFix":"// before\ntry {\n  parsed = await parseWithTypeConversion(this.schema, arg)\n} catch (e) {\n  throw new Error(`Received tool input did not match expected schema: ${JSON.stringify(arg)}`)\n}\n// after: keep the cause for debugging\ntry {\n  parsed = await parseWithTypeConversion(this.schema, arg)\n} catch (e) {\n  const reason = e instanceof Error ? e.message : String(e)\n  throw new Error(\n    `Received tool input did not match expected schema: ${JSON.stringify(arg)} (reason: ${reason})`\n  )\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate the LLM payload shape before handing it to the tool\nfunction preflightSchema(schema: z.ZodTypeAny, arg: unknown) {\n  const r = schema.safeParse(arg)\n  if (!r.success) throw new Error(`Preflight schema violation: ${r.error.message}`)\n}","typeGuard":"function looksLikeToolArg(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v)\n}","tryCatchPattern":"try {\n  return await agentTool.invoke(arg)\n} catch (e) {\n  const msg = (e as Error).message\n  if (msg.startsWith('Received tool input did not match')) {\n    // feed the JSON-stringified arg back to the model with a corrective prompt\n  } else throw e\n}","preventionTips":["Add few-shot examples of correct tool calls to the system prompt.","Keep tool schemas minimal and additive (use optional fields with defaults).","Use a model with strong function-calling support for StructuredTool-heavy agents."],"tags":["langchain","schema","zod","validation","llm-input"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}