{"record":{"id":"592a531ca3ba8bc1","repo":"chroma-core/chroma","slug":"expected-metadata-list-value-for-key-key-to-c-592a53","errorCode":null,"errorMessage":"Expected metadata list value for key '${key}' to contain only the same type, got mixed types","messagePattern":"Expected metadata list value for key '(.+?)' to contain only the same type, got mixed types","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":281,"sourceCode":"  const validateMetadataListValue = (key: string, v: unknown[]): void => {\n    if (v.length === 0) {\n      throw new ChromaValueError(\n        `Expected metadata list value for key '${key}' to be non-empty`,\n      );\n    }\n    const firstType = typeof v[0];\n    for (const item of v) {\n      if (\n        typeof item !== \"string\" &&\n        typeof item !== \"number\" &&\n        typeof item !== \"boolean\"\n      ) {\n        throw new ChromaValueError(\n          `Expected metadata list value for key '${key}' to contain only strings, numbers, or booleans, got ${typeof item}`,\n        );\n      }\n      if (typeof item !== firstType) {\n        throw new ChromaValueError(\n          `Expected metadata list value for key '${key}' to contain only the same type, got mixed types`,\n        );\n      }\n    }\n  };\n\n  for (const [key, v] of Object.entries(metadata)) {\n    if (\n      v === null ||\n      v === undefined ||\n      typeof v === \"string\" ||\n      typeof v === \"number\" ||\n      typeof v === \"boolean\"\n    ) {\n      continue;\n    }\n    if (validateSparseVector(v)) {\n      continue;","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L263-L299","documentation":"validateMetadataListValue records typeof of the first array element and throws when any later element differs. Chroma metadata lists must be homogeneous: all strings, all numbers, or all booleans. Mixed arrays such as ['1', 2] are rejected client-side with ChromaValueError.","triggerScenarios":"metadatas: [{ ids: [1, '2', 3] }]. Parsing CSV/JSON where numbers sometimes arrive as strings, producing ['1', 2]. Booleans mixed with 0/1 encodings, e.g. [true, 1].","commonSituations":"Heterogeneous API responses; loose parsing that leaves some values as strings; merging data from sources with different type conventions for the same key.","solutions":["Coerce the whole list to one type before the call, e.g. list.map(Number) or list.map(String).","Normalize at ingestion so a given key always carries one type.","Assert type uniformity across each list value in a unit test of your metadata builder."],"exampleFix":"// before\nmetadatas: [{ values: ['1', 2, '3'] }]\n\n// after\nmetadatas: [{ values: ['1', 2, '3'].map(Number) }]","handlingStrategy":"validation","validationCode":"const homogeneous = (v) => !Array.isArray(v) || v.every(item => typeof item === typeof v[0]);\nconst safe = Object.fromEntries(Object.entries(meta).filter(([, v]) => homogeneous(v)));","typeGuard":"const isHomogeneousList = (v: unknown): v is unknown[] =>\n  Array.isArray(v) && v.every(item => typeof item === typeof v[0]);","tryCatchPattern":"try {\n  await collection.add({ ids, metadatas });\n} catch (e) {\n  if ((e as Error).message.includes('mixed types')) {\n    // coerce the offending list to one type (map(String) or map(Number)) and retry\n  } else {\n    throw e;\n  }\n}","preventionTips":["Pick one canonical type per metadata key and enforce it at ingestion.","Convert query-param or CSV strings with map(Number)/map(String) before use.","Assert homogeneity in metadata builder unit tests."],"tags":["metadata","type-error","validation","javascript"],"backgroundTag":"invalid-metadata","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}