FlowiseAI/Flowise · error · ToolInputParsingException

Received tool input did not match expected schema

Error message

Received tool input did not match expected schema

What it means

Thrown by RetrieverTool.call when parseWithTypeConversion fails to coerce the incoming `arg` against the tool's `schema`. The arg is forwarded as-is into the error's data field via JSON.stringify. This is a tool-input contract violation: the caller (often an LLM agent) sent a payload the retriever cannot interpret.

Source

Thrown at packages/components/nodes/tools/RetrieverTool/RetrieverTool.ts:63

    constructor(fields: DynamicStructuredToolInput<T>) {
        super(fields)
        this.name = fields.name
        this.description = fields.description
        this.func = fields.func
        this.returnDirect = fields.returnDirect ?? this.returnDirect
        this.schema = fields.schema
    }

    async call(arg: any, configArg?: RunnableConfig | Callbacks, tags?: string[], flowConfig?: IFlowConfig): 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 ToolInputParsingException(`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.runName

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Inspect this.schema on the RetrieverTool instance and align the agent's output to it.
  2. Update the agent's system prompt to include the exact JSON shape the retriever expects.
  3. If using LangChain function-calling, bind the tool via `bindTools` so the model sees the schema.
  4. Pre-parse and normalize the arg before invoking call().

Example fix

// before
const retriever = new RetrieverTool({ schema: z.object({ query: z.string(), k: z.number() }), ... })
await retriever.call('search term') // throws: Received tool input did not match expected schema

// after
await retriever.call({ query: 'search term', k: 4 })
Defensive patterns

Strategy: type-guard

Validate before calling

async function safeRetrieverCall(tool: any, arg: unknown) {
  // Pre-validate against the tool's schema if it exposes safeParse (zod)
  if (tool.schema?.safeParse) {
    const r = tool.schema.safeParse(arg)
    if (!r.success) throw new Error(`Arg rejected pre-call: ${r.error.message}`)
  }
  return tool.call(arg)
}

Type guard

import { z } from 'zod'
const retrieverInput = z.object({ query: z.string(), k: z.number().int().positive().optional() })
const isRetrieverInput = (x: unknown): x is z.infer<typeof retrieverInput> =>
  retrieverInput.safeParse(x).success

Try / catch

try {
  return await retriever.call(arg)
} catch (e) {
  if (/did not match expected schema/i.test((e as Error).message)) {
    throw new Error(`Agent sent invalid retriever input: ${JSON.stringify(arg)}`)
  }
  throw e
}

Prevention

When it happens

Trigger: An agent invokes the retriever with a free-form string when the schema expects an object (or vice versa); required fields missing; field types mismatch (e.g. number vs string); extra fields when additionalProperties is false and coercion is strict.

Common situations: Agent prompt does not describe the tool schema accurately; the retriever wraps a vector store whose schema changed; LLM hallucinated the input shape; legacy flows after a schema migration.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/ee47c4963c3bba9e. Report an issue: GitHub.