{"record":{"id":"9db7df434a6e0cf3","repo":"FlowiseAI/Flowise","slug":"invalid-input-array","errorCode":null,"errorMessage":"Invalid input array","messagePattern":"Invalid input array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/Iteration/Iteration.ts","lineNumber":56,"sourceCode":"\n    async run(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {\n        const iterationInput = nodeData.inputs?.iterationInput\n\n        // Helper function to clean JSON strings with redundant backslashes\n        const safeParseJson = (str: string): string => {\n            try {\n                return parseJsonBody(str)\n            } catch {\n                // Try parsing after cleaning\n                return parseJsonBody(str.replace(/\\\\([\"'[\\]{}])/g, '$1'))\n            }\n        }\n\n        const iterationInputArray =\n            typeof iterationInput === 'string' && iterationInput !== '' ? safeParseJson(iterationInput) : iterationInput\n\n        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {\n            throw new Error('Invalid input array')\n        }\n\n        const state = options.agentflowRuntime?.state as ICommonObject\n\n        const returnOutput = {\n            id: nodeData.id,\n            name: this.name,\n            input: {\n                iterationInput: iterationInputArray\n            },\n            output: {},\n            state\n        }\n\n        return returnOutput\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/Iteration/Iteration.ts#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {\n            throw new Error('Invalid input array')\n        }\n// after\n        if (!iterationInputArray || !Array.isArray(iterationInputArray)) {\n            throw new Error(`Invalid input array: expected a JSON array, got ${typeof iterationInput} = ${JSON.stringify(iterationInput)?.slice(0, 120)}`)\n        }","handlingStrategy":"validation","validationCode":"const raw = nodeData.inputs?.iterationInput\nconst parsed = typeof raw === 'string' && raw !== '' ? JSON.parse(raw) : raw\nif (!Array.isArray(parsed) || parsed.length === 0) {\n  throw new Error('iterationInput must bind to a non-empty JSON array')\n}","typeGuard":"const isJsonArray = (v: unknown): v is unknown[] =>\n  Array.isArray(v) && v.length > 0","tryCatchPattern":"try {\n  const out = await iterNode.run(nodeData, input, options)\n} catch (e) {\n  if ((e as Error).message === 'Invalid input array') {\n    // fix upstream binding to emit a JSON array\n  }\n  throw e\n}","preventionTips":["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."],"tags":["agentflow","iteration","validation","json-parse","input-validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}