FlowiseAI/Flowise · error · Error
Received tool input did not match expected schema: ${JSON.st
Error message
Received tool input did not match expected schema: ${JSON.stringify(arg)} What it means
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.
Source
Thrown at packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts:284
this.overrideConfig = overrideConfig
this.returnDirect = returnDirect
}
async call(
arg: z.infer<typeof this.schema>,
configArg?: RunnableConfig | Callbacks,
tags?: string[],
flowConfig?: { sessionId?: string; chatId?: string; input?: string }
): Promise<string> {
const config = parseCallbackConfigArg(configArg)
if (config.runName === undefined) {
config.runName = this.name
}
let parsed
try {
parsed = await parseWithTypeConversion(this.schema, arg)
} catch (e) {
throw new Error(`Received tool input did not match expected schema: ${JSON.stringify(arg)}`)
}
const callbackManager_ = await CallbackManager.configure(
config.callbacks,
this.callbacks,
config.tags || tags,
this.tags,
config.metadata,
this.metadata,
{ verbose: this.verbose }
)
const runManager = await callbackManager_?.handleToolStart(
this.toJSON(),
typeof parsed === 'string' ? parsed : JSON.stringify(parsed),
undefined,
undefined,
undefined,
undefined,
config.runNameView on GitHub (pinned to abe4a8601a)
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.
Example fix
// before
try {
parsed = await parseWithTypeConversion(this.schema, arg)
} catch (e) {
throw new Error(`Received tool input did not match expected schema: ${JSON.stringify(arg)}`)
}
// after: keep the cause for debugging
try {
parsed = await parseWithTypeConversion(this.schema, arg)
} catch (e) {
const reason = e instanceof Error ? e.message : String(e)
throw new Error(
`Received tool input did not match expected schema: ${JSON.stringify(arg)} (reason: ${reason})`
)
} Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate the LLM payload shape before handing it to the tool
function preflightSchema(schema: z.ZodTypeAny, arg: unknown) {
const r = schema.safeParse(arg)
if (!r.success) throw new Error(`Preflight schema violation: ${r.error.message}`)
} Type guard
function looksLikeToolArg(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v)
} Try / catch
try {
return await agentTool.invoke(arg)
} catch (e) {
const msg = (e as Error).message
if (msg.startsWith('Received tool input did not match')) {
// feed the JSON-stringified arg back to the model with a corrective prompt
} else throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Received tool input did not match expected schema: ${JSON.st
- Received tool input did not match expected schema
- Error parsing Zod Schema: ${exception}
- Received tool input did not match expected schema ${e}
- Unsupported type: ${typeInfo.base}
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/87bef2342177d9c6.
Report an issue: GitHub.