mem0ai/mem0 · error

messages string cannot be empty. Provide non-empty content.

Error message

messages string cannot be empty. Provide non-empty content.

What it means

Thrown by the OSS Memory.add() method when messages is a plain string that is empty or contains only whitespace. As with the array form, the SDK validates before calling the LLM or embedder. It exists so callers get a clear error instead of a nonsense LLM extraction or an embedding failure downstream.

Source

Thrown at mem0-ts/src/oss/src/memory/index.ts:755

        "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(
      config?.metadata,
    );

    await this._ensureInitialized();
    await this._captureEvent("add", {
      message_count: Array.isArray(messages) ? messages.length : 1,
      has_metadata: !!config.metadata,
      has_filters: !!config.filters,
      infer: config.infer,
    });
    const { filters = {}, infer = true } = config;
    const metadata = stripIdentityKeys(config.metadata);

View on GitHub (pinned to 001c235229)

Solutions

  1. Guard before calling: if (!text.trim()) skip or prompt the user
  2. Log the raw input length when it fails to find where the empty string originates
  3. If the string comes from JSON, verify the field exists and was parsed, not undefined stringified later

Example fix

// before
await memory.add(userText); // userText === '  '

// after
if (userText.trim()) {
  await memory.add(userText);
}
Defensive patterns

Strategy: validation

Validate before calling

if (typeof messages === 'string' && !messages.trim()) {
  // nothing to store — skip the add() call
  return;
}

Type guard

const isNonEmptyString = (s: unknown): s is string =>
  typeof s === 'string' && s.trim() !== '';

Try / catch

try { await memory.add(text, { userId }); } catch (e) { if (e instanceof Error && e.message.includes('cannot be empty')) return; throw e; }

Prevention

When it happens

Trigger: Calling memory.add('') or memory.add(' \n\t') — any string where messages.trim() === ''. Array inputs never hit this branch.

Common situations: Passing a variable that was never assigned (empty template literal); forwarding chat input without trimming; a pipeline step that collapses the message to an empty string.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/55bc12517ff5e942. Report an issue: GitHub.