{"record":{"id":"b3bf9962d2685874","repo":"mem0ai/mem0","slug":"messages-array-cannot-contain-only-blank-content","errorCode":null,"errorMessage":"messages array cannot contain only blank content. Provide at least one message with non-empty content.","messagePattern":"messages array cannot contain only blank content\\. Provide at least one message with non-empty content\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/memory/index.ts","lineNumber":750,"sourceCode":"    }\n\n    // Validate messages input\n    if (messages === undefined || messages === null) {\n      throw new Error(\n        \"messages is required and cannot be undefined or null. Provide a string or array of messages.\",\n      );\n    }\n    if (Array.isArray(messages)) {\n      if (messages.length === 0) {\n        throw new Error(\n          \"messages array cannot be empty. Provide at least one message with non-empty content.\",\n        );\n      }\n      const allBlank = messages.every(\n        (m) => typeof m.content === \"string\" && m.content.trim() === \"\",\n      );\n      if (allBlank) {\n        throw new Error(\n          \"messages array cannot contain only blank content. Provide at least one message with non-empty content.\",\n        );\n      }\n    } else if (messages.trim() === \"\") {\n      throw new Error(\n        \"messages string cannot be empty. Provide non-empty content.\",\n      );\n    }\n\n    const temporalUsageNotice = detectTemporalUsageFromMetadata(\n      config?.metadata,\n    );\n\n    await this._ensureInitialized();\n    await this._captureEvent(\"add\", {\n      message_count: Array.isArray(messages) ? messages.length : 1,\n      has_metadata: !!config.metadata,\n      has_filters: !!config.filters,","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/memory/index.ts#L732-L768","documentation":"Thrown by the OSS Memory.add() method when the messages argument is an array in which every message has string content that is empty or whitespace-only. The SDK refuses to spend an LLM/embedding call on input that carries no information. It is a client-side validation guard that fires before any provider call.","triggerScenarios":"Calling memory.add(messages) where messages is a non-empty array and messages.every(m => typeof m.content === 'string' && m.content.trim() === '') is true, e.g. memory.add([{ role: 'user', content: '   ' }]). Non-string content (e.g. image parts) makes every() false, so only all-blank string arrays trigger it.","commonSituations":"Passing user input straight from a form/chat UI where the user submitted whitespace; upstream trimming that reduces content to ''; transcript arrays whose text fields were dropped during JSON transformation.","solutions":["Filter or reject blank messages before calling add(): messages.filter(m => typeof m.content !== 'string' || m.content.trim() !== '')","If the array becomes empty after filtering, validate earlier in your pipeline and skip the add() call entirely","Check that message objects actually carry the content field and it was not renamed (e.g. 'text') during mapping"],"exampleFix":"// before\nawait memory.add([{ role: 'user', content: '   ' }]);\n\n// after\nconst msgs = transcript.filter(m => m.content?.trim());\nif (msgs.length) {\n  await memory.add(msgs);\n}","handlingStrategy":"validation","validationCode":"const hasContent = (msgs) =>\n  Array.isArray(msgs)\n    ? msgs.some((m) => typeof m.content !== 'string' || m.content.trim() !== '')\n    : msgs.trim() !== '';\nif (!hasContent(messages)) throw new Error('nothing to memorize');","typeGuard":null,"tryCatchPattern":"try { await memory.add(messages, { userId }); } catch (e) { if (e instanceof Error && e.message.includes('blank content')) { /* skip empty input */ } else throw e; }","preventionTips":["Trim and reject empty chat input at the UI/boundary layer before it reaches memory.add()","When mapping transcripts to Message[], assert every message has non-blank string content"],"tags":["validation","typescript","oss","memory-add"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}