FlowiseAI/Flowise · error · Error

Expected partitioning request to return an array, but got ${

Error message

Expected partitioning request to return an array, but got ${elements}

What it means

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.

Source

Thrown at packages/components/nodes/documentloaders/Unstructured/Unstructured.ts:144

        }

        const headers = {
            'UNSTRUCTURED-API-KEY': this.apiKey || ''
        }

        const response = await fetch(this.apiUrl, {
            method: 'POST',
            body: formData,
            headers
        })

        if (!response.ok) {
            throw new Error(`Failed to partition file with error ${response.status} and message ${await response.text()}`)
        }

        const elements = await response.json()
        if (!Array.isArray(elements)) {
            throw new Error(`Expected partitioning request to return an array, but got ${elements}`)
        }
        return elements.filter((el) => typeof el.text === 'string') as Element[]
    }

    async loadAndSplitBuffer(buffer: Buffer, fileName: string): Promise<Document[]> {
        const elements = await this._partition(buffer, fileName)

        const documents: Document[] = []
        for (const element of elements) {
            const { metadata, text } = element
            if (typeof text === 'string') {
                documents.push(
                    new Document({
                        pageContent: text,
                        metadata: {
                            ...metadata,
                            category: element.type
                        }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Log the actual value of `elements` to see the unexpected shape (the message stringifies it).
  2. Confirm apiUrl matches the Unstructured API version your client expects (array response).
  3. If the endpoint wraps results, unwrap before this check (e.g. use response.data.elements).
  4. Ensure the response Content-Type is JSON and not an HTML error page parsed loosely.
  5. Pin the Unstructured client/server version pair.

Example fix

// before
const elements = await response.json()
if (!Array.isArray(elements)) {
    throw new Error(`Expected partitioning request to return an array, but got ${elements}`)
}

// after
const elements = await response.json()
const arr = Array.isArray(elements) ? elements : elements?.elements
if (!Array.isArray(arr)) {
    throw new Error(`Expected partitioning request to return an array, but got ${JSON.stringify(elements).slice(0, 500)}`)
}
Defensive patterns

Strategy: type-guard

Validate before calling

const elements = await response.json()
if (!Array.isArray(elements)) throw new Error(`Unexpected partition shape: ${JSON.stringify(elements).slice(0, 200)}`)

Type guard

interface UnstructuredElement { text: string; metadata?: Record<string, unknown> }
function isUnstructuredElements(v: unknown): v is UnstructuredElement[] {
    return Array.isArray(v) && v.every(el => el && typeof (el as any).text === 'string')
}

Try / catch

const parsed = await response.json()
const arr = Array.isArray(parsed) ? parsed : (parsed as any)?.elements
if (!Array.isArray(arr)) {
    throw new Error(`Partition contract mismatch; got ${JSON.stringify(parsed).slice(0, 200)}`)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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