mastra-ai/mastra · error
Invalid input: array items must be strings or objects with a
Error message
Invalid input: array items must be strings or objects with an id property
What it means
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.
Source
Thrown at packages/memory/src/index.ts:2832
): Promise<void> {
// Normalize input to messageIds before creating span to avoid leaking full message objects into traces
let messageIds: string[];
if (!Array.isArray(input)) {
throw new Error('Invalid input: must be an array of message IDs or message objects');
}
if (input.length === 0) {
return;
}
messageIds = input.map(item => {
if (typeof item === 'string') {
return item;
} else if (item && typeof item === 'object' && 'id' in item) {
return item.id;
} else {
throw new Error('Invalid input: array items must be strings or objects with an id property');
}
});
const invalidIds = messageIds.filter(id => !id || typeof id !== 'string');
if (invalidIds.length > 0) {
throw new Error('All message IDs must be non-empty strings');
}
const span = this.createMemorySpan('delete', observabilityContext, undefined, {
messageCount: messageIds.length,
});
try {
const memoryStore = await this.getMemoryStore();
await memoryStore.deleteMessages(messageIds);
if (this.vector) {
this.trackVectorCleanup(this.deleteMessageVectors(messageIds));View on GitHub (pinned to 75dd419e61)
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`
Example fix
// before
await memory.deleteMessages(rows); // rows: { messageId: string }[]
// after
await memory.deleteMessages(rows.map(r => ({ id: r.messageId }))); Defensive patterns
Strategy: type-guard
Validate before calling
const validItems = (items: unknown[]): (string | { id: string })[] =>
items.filter((i): i is string | { id: string } =>
typeof i === 'string' || (typeof i === 'object' && i !== null && typeof (i as any).id !== 'undefined')
); Type guard
const isDeletableItem = (i: unknown): i is string | { id: string } =>
typeof i === 'string' || (typeof i === 'object' && i !== null && 'id' in i); Try / catch
try {
await memory.deleteMessages(items);
} catch (err) {
if (err instanceof Error && err.message.includes('must be strings or objects with an id')) {
console.error('Bad item in deleteMessages input:', items.find(i => !isDeletableItem(i)));
}
throw err;
} Prevention
- 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
When it happens
Trigger: Passing an array containing numbers, null/undefined entries, or objects that carry the ID under a different key (e.g. { messageId }) instead of { id }.
Common situations: 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.
Related errors
- Invalid input: must be an array of message IDs or message ob
- All message IDs must be non-empty strings
- Received input message with wrong threadId. Input ${message.
- Received input message with wrong resourceId. Input ${messag
- Found unhandled message ${JSON.stringify(message)}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/62eec15c69a2ef08.
Report an issue: GitHub.