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
- Log/print `iterationInput` and its typeof just before the node runs to see the actual value.
- Ensure the upstream node emits a real JSON array string like `[1,2,3]` or `["a","b"]`.
- If the source is an object, wrap it: `[${myObject}]`, or map the object's values to an array before binding.
- If using newline/CSV data, add a preprocessor node that splits it into an array.
- 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
- Always bind iterationInput to an output proven to be an array.
- Add a preprocessor node that wraps/maps non-array data into an array.
- Validate with Array.isArray(JSON.parse(x)) in a code node before the Iteration node.
- Avoid pasting CSV/newline text directly into the array field.
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
- Invalid Flow State
- Question and selectedChatModel are required
- chatflowId must be a valid array
- Invalid JSON in executeFlowOverrideConfig: ${parseError.mess
- Model is required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/9db7df434a6e0cf3.
Report an issue: GitHub.