{"record":{"id":"1ffdca0197f3cf73","repo":"chroma-core/chroma","slug":"expected-each-document-to-be-a-string-but-got-t","errorCode":null,"errorMessage":"Expected each document to be a string, but got ${typeof document}","messagePattern":"Expected each document to be a string, but got (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":176,"sourceCode":"  documents: (string | null | undefined)[];\n  fieldName: string;\n  nullable?: boolean;\n}) => {\n  if (!Array.isArray(documents)) {\n    throw new ChromaValueError(\n      `Expected '${fieldName}' to be an array, but got ${typeof documents}`,\n    );\n  }\n\n  if (documents.length === 0) {\n    throw new ChromaValueError(\n      `Expected '${fieldName}' to be a non-empty list`,\n    );\n  }\n\n  documents.forEach((document) => {\n    if (!nullable && typeof document !== \"string\" && !document) {\n      throw new ChromaValueError(\n        `Expected each document to be a string, but got ${typeof document}`,\n      );\n    }\n  });\n};\n\n/**\n * Validates an array of IDs for type correctness and uniqueness.\n * @param ids - Array of ID strings to validate\n * @throws ChromaValueError if IDs are not strings, empty, or contain duplicates\n */\nexport const validateIDs = (ids: string[]) => {\n  if (!Array.isArray(ids)) {\n    throw new ChromaValueError(\n      `Expected 'ids' to be an array, but got ${typeof ids}`,\n    );\n  }\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L158-L194","documentation":"ChromaValueError thrown by validateDocuments (utils.ts:176) per-element when a document entry is falsy and not a string (null/undefined/false/0/NaN) while nullable=false (the default — validateBaseRecordSet never passes nullable=true). Note the guard is `typeof document !== 'string' && !document`, so truthy non-strings (e.g. 42) slip through; this fires for null/undefined holes in the array.","triggerScenarios":"collection.add({ ids, documents: ['a', null, 'c'] }) with default nullable=false; sparse rows mapped as documents: rows.map(r => r.text) where r.text is undefined; update({ ids, documents }) with null placeholders.","commonSituations":"Optional text columns where some rows lack a body; JSON ingestion producing nulls; mixing documents and embeddings where some records intentionally have no text (currently not allowed by this validator).","solutions":["Coalesce holes to a string: documents.map(d => d ?? '')","Filter out rows without text and add them in a separate batch (or with embeddings only)","If nulls are intentional, note this client validator does not expose nullable=true on the public path — avoid nulls in documents"],"exampleFix":"// before\nawait collection.add({ ids, documents: [doc1, null, doc3] });\n// after\nawait collection.add({ ids, documents: [doc1, doc2 ?? \"\", doc3] });","handlingStrategy":"type-guard","validationCode":"const bad = documents.findIndex(d => d !== null && d !== undefined && typeof d !== 'string');\nif (bad !== -1) throw new TypeError(`documents[${bad}] is not a string`);\nif (documents.some(d => d == null)) documents = documents.map(d => d ?? '');","typeGuard":"function isDocumentArray(v): v is string[] { return Array.isArray(v) && v.every(d => typeof d === 'string'); }","tryCatchPattern":"try { await collection.add({ ids, documents }); } catch (e) { if (e instanceof ChromaValueError && /each document to be a string/.test(e.message)) documents = documents.map(d => d ?? ''); else throw e; }","preventionTips":["Coalesce null/undefined text to '' before insert","Filter textless rows into a separate embeddings-only batch","Validate parsed JSON payloads for null text fields"],"tags":["chromadb","validation","documents","null-handling"],"backgroundTag":"invalid-documents-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}