mem0ai/mem0 · error
messages array cannot be empty. Provide at least one message
Error message
messages array cannot be empty. Provide at least one message with non-empty content.
What it means
The second input validation in Memory.add(): when messages is an array it must be non-empty — an empty array throws with this message before any LLM or embedding work starts. It prevents wasting a pipeline run (and API cost) on input that could not produce a memory.
Source
Thrown at mem0-ts/src/oss/src/memory/index.ts:742
if (config?.timestamp !== undefined) {
await this._getNoticeTelemetryId();
throw new Error(
await getTemporalFeatureErrorMessage(this, {
triggerFunction: "add",
triggerParameter: "timestamp",
}),
);
}
// Validate messages input
if (messages === undefined || messages === null) {
throw new Error(
"messages is required and cannot be undefined or null. Provide a string or array of messages.",
);
}
if (Array.isArray(messages)) {
if (messages.length === 0) {
throw new Error(
"messages array cannot be empty. Provide at least one message with non-empty content.",
);
}
const allBlank = messages.every(
(m) => typeof m.content === "string" && m.content.trim() === "",
);
if (allBlank) {
throw new Error(
"messages array cannot contain only blank content. Provide at least one message with non-empty content.",
);
}
} else if (messages.trim() === "") {
throw new Error(
"messages string cannot be empty. Provide non-empty content.",
);
}
const temporalUsageNotice = detectTemporalUsageFromMetadata(View on GitHub (pinned to 001c235229)
Solutions
- Skip the call when the array is empty: if (messages.length === 0) return;
- Fix upstream filtering so the array retains intended content; log the pre-call length when debugging.
- In chat loops, call add() only after at least one real message exists.
- Batch emitters should drop empty chunks before invoking Memory.
Example fix
// before
await memory.add(history.filter((m) => m.role === 'user'), opts); // [] when bot-only history -> throws
// after
const userMsgs = history.filter((m) => m.role === 'user');
if (userMsgs.length > 0) {
await memory.add(userMsgs, opts);
} Defensive patterns
Strategy: validation
Validate before calling
function hasNonEmptyMessages(messages: unknown): boolean {
return Array.isArray(messages) && messages.length > 0;
} Type guard
function isNonEmptyMessageArray(messages: unknown): messages is { role: string; content: string }[] {
return (
Array.isArray(messages) &&
messages.length > 0 &&
messages.some((m) => typeof m?.content === 'string' && m.content.trim() !== '')
);
} Prevention
- Skip the add() call when the array is empty — returning early is cheaper than catching.
- Log pre-call message counts in chat pipelines to catch empty-transcript bugs.
- Make batch emitters drop empty chunks before invoking Memory.
When it happens
Trigger: Calling memory.add([], { filters: { userId: 'u1' } }), or passing a filtered/mapped array that ended up empty — e.g. messages.filter(m => m.role === 'user') when no user messages exist.
Common situations: Chat pipelines where the transcript hasn't received messages yet (add called at conversation start), arrays emptied by filtering, slicing beyond length, or spreading an empty list; batching code that emits zero-item chunks.
Related errors
- messages is required and cannot be undefined or null. Provid
- Either memoryId or --all is required
- At least one entity ID is required for deleteEntities.
- Unknown LLM provider: ${providerId}
- Unknown embedder provider: ${providerId}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/af737eb90ce63926.
Report an issue: GitHub.