{"record":{"id":"811f71f42036567d","repo":"FlowiseAI/Flowise","slug":"document-object-must-contain-pagecontent-and-metad","errorCode":null,"errorMessage":"Document object must contain pageContent and metadata","messagePattern":"Document object must contain pageContent and metadata","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts","lineNumber":134,"sourceCode":"        }\n\n        const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)\n\n        try {\n            const response = await executeJavaScriptCode(javascriptFunction, sandbox, {\n                libraries: ['axios']\n            })\n\n            if (output === 'document' && Array.isArray(response)) {\n                if (response.length === 0) return response\n                if (\n                    response[0].pageContent &&\n                    typeof response[0].pageContent === 'string' &&\n                    response[0].metadata &&\n                    typeof response[0].metadata === 'object'\n                )\n                    return response\n                throw new Error('Document object must contain pageContent and metadata')\n            }\n\n            if (output === 'text' && typeof response === 'string') {\n                return handleEscapeCharacters(response, false)\n            }\n\n            return response\n        } catch (e) {\n            throw new Error(e)\n        }\n    }\n}\n\nmodule.exports = { nodeClass: CustomDocumentLoader_DocumentLoaders }\n","sourceCodeStart":116,"sourceCodeEnd":149,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts#L116-L149","documentation":"CustomDocumentLoader ran the user's javascriptFunction in a sandbox and the output was an array (output='document'), but the first element does not satisfy the document shape: pageContent must be a string AND metadata must be an object. This is a contract check on sandbox output, not a network or parse error.","triggerScenarios":"The function returned [{text: ...}] instead of [{pageContent, metadata}]; pageContent is a number or undefined; metadata is missing or is a string; the function returned the raw axios response object instead of mapped documents.","commonSituations":"User wrote the sandbox function against a different schema; the API they fetched from returned objects that were not mapped; only checked length>0 but element shape is wrong.","solutions":["Map every element explicitly: return response.data.map(item => ({ pageContent: String(item.text), metadata: { id: item.id } })).","Ensure pageContent is coerced to a string and metadata is always an object (use {} as fallback if you want it to pass).","Test the sandbox function standalone with a sample input before wiring it into the node."],"exampleFix":"// before\n// user function returned: [{ text: 'hi' }]\n// after - shape each row to the contract\nconst docs = response.data.map((item) => ({\n  pageContent: String(item.text ?? ''),\n  metadata: { id: item.id, source: item.url }\n}))\nreturn docs","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import type { IDocument } from './types'\n\nfunction isDocumentArray(value: unknown): value is IDocument[] {\n  if (!Array.isArray(value) || value.length === 0) return false\n  return value.every((item) =>\n    item !== null && typeof item === 'object'\n    && typeof (item as any).pageContent === 'string'\n    && (item as any).metadata !== null && typeof (item as any).metadata === 'object'\n  )\n}\n// if (output === 'document' && isDocumentArray(response)) return response\n// else throw with available-fields diagnostics","tryCatchPattern":null,"preventionTips":["In your sandbox function, always map rows to { pageContent: String(...), metadata: {...} }.","Coerce pageContent with String() so numbers/undefined become strings.","Return [] rather than a malformed array when there are no results."],"tags":["validation","document","javascript","sandbox","custom-document-loader"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}