{"record":{"id":"9688ca215d109ba6","repo":"chroma-core/chroma","slug":"expected-include-items-to-be-strings","errorCode":null,"errorMessage":"Expected 'include' items to be strings","messagePattern":"Expected 'include' items to be strings","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":730,"sourceCode":" * @param options.include - Array of fields to include in results\n * @param options.exclude - Optional array of fields that should not be included\n * @throws ChromaValueError if include fields are invalid\n */\nexport const validateInclude = ({\n  include,\n  exclude,\n}: {\n  include: Include[];\n  exclude?: Include[];\n}) => {\n  if (!Array.isArray(include)) {\n    throw new ChromaValueError(\"Expected 'include' to be a non-empty array\");\n  }\n\n  const validValues = Object.keys(IncludeEnum);\n  include.forEach((item) => {\n    if (typeof (item as any) !== \"string\") {\n      throw new ChromaValueError(\"Expected 'include' items to be strings\");\n    }\n\n    if (!validValues.includes(item)) {\n      throw new ChromaValueError(\n        `Expected 'include' items to be one of ${validValues.join(\n          \", \",\n        )}, but got ${item}`,\n      );\n    }\n\n    if (exclude?.includes(item)) {\n      throw new ChromaValueError(`${item} is not allowed for this operation`);\n    }\n  });\n};\n\n/**\n * Validates the number of results parameter for queries.","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L712-L748","documentation":"Every element of the include array must be a string (a key of IncludeEnum); validateInclude's forEach throws this ChromaValueError for numbers, null, objects, or symbols (utils.ts:728-731). The check runs before the enum-membership check, so non-strings fail with this message rather than the 'one of' message.","triggerScenarios":"include: [1]; include: [null]; include: [{}] — usually values that arrived untyped from JSON config, URL query params, or another API's field indices.","commonSituations":"Loading include lists from user-supplied configuration; mapping another vector DB's numeric field selectors directly into Chroma include.","solutions":["Validate before the call: include.every(v => typeof v === 'string')","Type the variable as Include[] using the package's exported types","Convert foreign field names to IncludeEnum values at the config boundary"],"exampleFix":"// before\nawait col.get({ include: [1, 2] });\n\n// after\nawait col.get({ include: ['documents', 'metadatas'] });","handlingStrategy":"validation","validationCode":"function normalizeInclude(raw: unknown): string[] {\n  const list = Array.isArray(raw) ? raw : [raw];\n  if (!list.every(v => typeof v === 'string')) {\n    throw new TypeError('include items must be strings');\n  }\n  return list as string[];\n}","typeGuard":"const isStringIncludeList = (v: unknown): v is string[] =>\n  Array.isArray(v) && v.every(item => typeof item === 'string');","tryCatchPattern":null,"preventionTips":["Validate config-sourced include lists at the system boundary (zod/valibot schema)","Type the variable as Include[] rather than any[]","Convert external field selectors to IncludeEnum values before use"],"tags":["javascript","typescript","validation","include","type-mismatch"],"backgroundTag":"invalid-include-parameter","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}