FlowiseAI/Flowise · error · Error

Invalid input array

Error message

Invalid input array

What it means

Thrown by Iteration_Agentflow.run() when `iterationInput` does not resolve to a non-empty array. The input is either passed through directly (if not a non-empty string) or run through safeParseJson, which tries parseJsonBody then a backslash-cleaning retry. If the result is falsy or not Array.isArray, the node refuses to iterate.

Source

Thrown at packages/components/nodes/agentflow/Iteration/Iteration.ts:56

    async run(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
        const iterationInput = nodeData.inputs?.iterationInput

        // Helper function to clean JSON strings with redundant backslashes
        const safeParseJson = (str: string): string => {
            try {
                return parseJsonBody(str)
            } catch {
                // Try parsing after cleaning
                return parseJsonBody(str.replace(/\\(["'[\]{}])/g, '$1'))
            }
        }

        const iterationInputArray =
            typeof iterationInput === 'string' && iterationInput !== '' ? safeParseJson(iterationInput) : iterationInput

        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {
            throw new Error('Invalid input array')
        }

        const state = options.agentflowRuntime?.state as ICommonObject

        const returnOutput = {
            id: nodeData.id,
            name: this.name,
            input: {
                iterationInput: iterationInputArray
            },
            output: {},
            state
        }

        return returnOutput
    }
}

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Log/print `iterationInput` and its typeof just before the node runs to see the actual value.
  2. Ensure the upstream node emits a real JSON array string like `[1,2,3]` or `["a","b"]`.
  3. If the source is an object, wrap it: `[${myObject}]`, or map the object's values to an array before binding.
  4. If using newline/CSV data, add a preprocessor node that splits it into an array.
  5. Validate with `Array.isArray(JSON.parse(value))` in a prior node.

Example fix

// before
        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {
            throw new Error('Invalid input array')
        }
// after
        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {
            throw new Error(`Invalid input array: expected a JSON array, got ${typeof iterationInput} = ${JSON.stringify(iterationInput)?.slice(0, 120)}`)
        }
Defensive patterns

Strategy: validation

Validate before calling

const raw = nodeData.inputs?.iterationInput
const parsed = typeof raw === 'string' && raw !== '' ? JSON.parse(raw) : raw
if (!Array.isArray(parsed) || parsed.length === 0) {
  throw new Error('iterationInput must bind to a non-empty JSON array')
}

Type guard

const isJsonArray = (v: unknown): v is unknown[] =>
  Array.isArray(v) && v.length > 0

Try / catch

try {
  const out = await iterNode.run(nodeData, input, options)
} catch (e) {
  if ((e as Error).message === 'Invalid input array') {
    // fix upstream binding to emit a JSON array
  }
  throw e
}

Prevention

When it happens

Trigger: iterationInput is a malformed JSON string (e.g. `{"a":1}` — valid JSON but not an array), an empty string, a string that is neither valid JSON nor cleanable, or undefined/null. A JSON array serialized with double-escaped quotes that the cleaning regex cannot fix also triggers it.

Common situations: Upstream node outputs an object instead of an array; a variable binding resolves to a JSON object string; the user pasted a CSV or newline-delimited text expecting it to be parsed as a list; an LLM produced malformed JSON for the array field.

Related errors


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