{"record":{"id":"aeb7fd29a384f681","repo":"FlowiseAI/Flowise","slug":"expected-partitioning-request-to-return-an-array","errorCode":null,"errorMessage":"Expected partitioning request to return an array, but got ${elements}","messagePattern":"Expected partitioning request to return an array, but got (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/Unstructured/Unstructured.ts","lineNumber":144,"sourceCode":"        }\n\n        const headers = {\n            'UNSTRUCTURED-API-KEY': this.apiKey || ''\n        }\n\n        const response = await fetch(this.apiUrl, {\n            method: 'POST',\n            body: formData,\n            headers\n        })\n\n        if (!response.ok) {\n            throw new Error(`Failed to partition file with error ${response.status} and message ${await response.text()}`)\n        }\n\n        const elements = await response.json()\n        if (!Array.isArray(elements)) {\n            throw new Error(`Expected partitioning request to return an array, but got ${elements}`)\n        }\n        return elements.filter((el) => typeof el.text === 'string') as Element[]\n    }\n\n    async loadAndSplitBuffer(buffer: Buffer, fileName: string): Promise<Document[]> {\n        const elements = await this._partition(buffer, fileName)\n\n        const documents: Document[] = []\n        for (const element of elements) {\n            const { metadata, text } = element\n            if (typeof text === 'string') {\n                documents.push(\n                    new Document({\n                        pageContent: text,\n                        metadata: {\n                            ...metadata,\n                            category: element.type\n                        }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/Unstructured/Unstructured.ts#L126-L162","documentation":"Thrown after a successful (response.ok) partition call when the parsed JSON is not an array. The Unstructured contract returns an array of element objects; a non-array usually means the endpoint returned an error object, an HTML error page mis-parsed, or a different API version.","triggerScenarios":"Unstructured returns 200 with a JSON object (e.g. `{ error: '...' }`) instead of an array, a reverse proxy returns a JSON status object, or an API version mismatch returns a paginated/ wrapped shape.","commonSituations":"apiUrl pointing to a different product or version (e.g. Unstructured Platform vs open-source), proxy injecting a status wrapper, or a misconfigured endpoint returning metadata objects.","solutions":["Log the actual value of `elements` to see the unexpected shape (the message stringifies it).","Confirm apiUrl matches the Unstructured API version your client expects (array response).","If the endpoint wraps results, unwrap before this check (e.g. use response.data.elements).","Ensure the response Content-Type is JSON and not an HTML error page parsed loosely.","Pin the Unstructured client/server version pair."],"exampleFix":"// before\nconst elements = await response.json()\nif (!Array.isArray(elements)) {\n    throw new Error(`Expected partitioning request to return an array, but got ${elements}`)\n}\n\n// after\nconst elements = await response.json()\nconst arr = Array.isArray(elements) ? elements : elements?.elements\nif (!Array.isArray(arr)) {\n    throw new Error(`Expected partitioning request to return an array, but got ${JSON.stringify(elements).slice(0, 500)}`)\n}","handlingStrategy":"type-guard","validationCode":"const elements = await response.json()\nif (!Array.isArray(elements)) throw new Error(`Unexpected partition shape: ${JSON.stringify(elements).slice(0, 200)}`)","typeGuard":"interface UnstructuredElement { text: string; metadata?: Record<string, unknown> }\nfunction isUnstructuredElements(v: unknown): v is UnstructuredElement[] {\n    return Array.isArray(v) && v.every(el => el && typeof (el as any).text === 'string')\n}","tryCatchPattern":"const parsed = await response.json()\nconst arr = Array.isArray(parsed) ? parsed : (parsed as any)?.elements\nif (!Array.isArray(arr)) {\n    throw new Error(`Partition contract mismatch; got ${JSON.stringify(parsed).slice(0, 200)}`)\n}","preventionTips":["Pin the Unstructured API version so the response shape is stable.","Tolerate a wrapped shape (unwrap .elements) before validating.","Log the raw body when the contract check fails.","Add an integration test that asserts Array.isArray on a known-good partition call."],"tags":["unstructured","response-parsing","api-contract","validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}