{"record":{"id":"62eec15c69a2ef08","repo":"mastra-ai/mastra","slug":"invalid-input-array-items-must-be-strings-or-obje","errorCode":null,"errorMessage":"Invalid input: array items must be strings or objects with an id property","messagePattern":"Invalid input: array items must be strings or objects with an id property","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/index.ts","lineNumber":2832,"sourceCode":"  ): Promise<void> {\n    // Normalize input to messageIds before creating span to avoid leaking full message objects into traces\n    let messageIds: string[];\n\n    if (!Array.isArray(input)) {\n      throw new Error('Invalid input: must be an array of message IDs or message objects');\n    }\n\n    if (input.length === 0) {\n      return;\n    }\n\n    messageIds = input.map(item => {\n      if (typeof item === 'string') {\n        return item;\n      } else if (item && typeof item === 'object' && 'id' in item) {\n        return item.id;\n      } else {\n        throw new Error('Invalid input: array items must be strings or objects with an id property');\n      }\n    });\n\n    const invalidIds = messageIds.filter(id => !id || typeof id !== 'string');\n    if (invalidIds.length > 0) {\n      throw new Error('All message IDs must be non-empty strings');\n    }\n\n    const span = this.createMemorySpan('delete', observabilityContext, undefined, {\n      messageCount: messageIds.length,\n    });\n\n    try {\n      const memoryStore = await this.getMemoryStore();\n\n      await memoryStore.deleteMessages(messageIds);\n      if (this.vector) {\n        this.trackVectorCleanup(this.deleteMessageVectors(messageIds));","sourceCodeStart":2814,"sourceCodeEnd":2850,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/index.ts#L2814-L2850","documentation":"After confirming the input is an array, deleteMessages normalizes each item: it must be a string (message ID) or an object containing an `id` property. An item that is null, a number, an object without `id`, etc. throws this error inside the map.","triggerScenarios":"Passing an array containing numbers, null/undefined entries, or objects that carry the ID under a different key (e.g. { messageId }) instead of { id }.","commonSituations":"Mapping DB rows with differently-named ID fields directly into deleteMessages; mixing partial objects from API responses that omit `id`; untyped JS callers constructing mixed arrays.","solutions":["Ensure every array item is a string ID or an object with an `id` property (e.g. map rows: rows.map(r => r.id))","Filter out null/undefined entries before calling","Rename or normalize keys so the identifier is exposed as `id`"],"exampleFix":"// before\nawait memory.deleteMessages(rows); // rows: { messageId: string }[]\n\n// after\nawait memory.deleteMessages(rows.map(r => ({ id: r.messageId })));","handlingStrategy":"type-guard","validationCode":"const validItems = (items: unknown[]): (string | { id: string })[] =>\n  items.filter((i): i is string | { id: string } =>\n    typeof i === 'string' || (typeof i === 'object' && i !== null && typeof (i as any).id !== 'undefined')\n  );","typeGuard":"const isDeletableItem = (i: unknown): i is string | { id: string } =>\n  typeof i === 'string' || (typeof i === 'object' && i !== null && 'id' in i);","tryCatchPattern":"try {\n  await memory.deleteMessages(items);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('must be strings or objects with an id')) {\n    console.error('Bad item in deleteMessages input:', items.find(i => !isDeletableItem(i)));\n  }\n  throw err;\n}","preventionTips":["Normalize rows/records to { id } or plain string IDs before calling deleteMessages","Filter null/undefined out of arrays sourced from APIs or DB queries","Keep a single mapping helper from your domain record type to deletable items"],"tags":["memory","input-validation","api-misuse"],"backgroundTag":"invalid-input-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}