mem0ai/mem0 · warning · Error

Cannot process an empty messages payload.

Error message

Cannot process an empty messages payload.

What it means

MemoryClient.add() refuses a messages argument that is null/undefined or an empty array before building any payload (the comment marks this as the guard for issue #5465). Mem0's add endpoint requires at least one conversation message to extract memories from, so the client validates this client-side rather than shipping an empty POST.

Source

Thrown at mem0-ts/src/client/mem0.ts:322

    } catch (error: any) {
      // Pass through structured exceptions and APIError
      if (error instanceof MemoryError || error instanceof APIError) {
        throw error;
      } else {
        throw new APIError(
          `Failed to ping server: ${error.message || "Unknown error"}`,
        );
      }
    }
  }

  async add(
    messages: Array<Message>,
    options: AddMemoryOptions & Record<string, any> = {},
  ): Promise<Array<Memory>> {
    // Tightly scoped validation guard to resolve #5465
    if (!messages || (Array.isArray(messages) && messages.length === 0)) {
      throw new Error("Cannot process an empty messages payload.");
    }

    const payload = this._preparePayload(messages, options);
    const payloadKeys = Object.keys(payload);
    this._captureEvent("add", [payloadKeys]);

    const response = await this._fetchWithErrorHandling(
      `${this.host}/v3/memories/add/`,
      {
        method: "POST",
        headers: this.headers,
        body: JSON.stringify(payload),
      },
    );
    return response;
  }

  async update(

View on GitHub (pinned to 001c235229)

Solutions

  1. Skip the call when there is nothing to add: if (messages.length) await client.add(messages).
  2. Fix the upstream producer so the conversation array is actually populated (check the filter/map that built it).
  3. If using a string convenience form, pass at least one message object: [{ role: 'user', content: '...' }].

Example fix

// before
await client.add(messages); // messages may be []

// after
if (messages?.length) {
  await client.add(messages);
}
Defensive patterns

Strategy: validation

Validate before calling

function assertNonEmptyMessages(messages: Array<{ role: string; content: string }>): void {
  if (!messages || messages.length === 0) throw new Error('add() requires at least one message');
}

Type guard

const isNonEmptyMessages = (m: unknown): m is Array<{ role: string; content: string }> =>
  Array.isArray(m) && m.length > 0;

Prevention

When it happens

Trigger: await client.add([]) or await client.add(null as any) — e.g. piping a chat history array that turned out empty, filtering messages down to nothing, or calling add unconditionally after every turn including turns with no transcript.

Common situations: Guard-less loops that call add() even on first message before history exists; upstream UI bug producing empty conversation arrays; test harnesses calling add with placeholder data.

Related errors


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