mem0ai/mem0 · error · LLMError
LLM extraction failed: ${e}
Error message
LLM extraction failed: ${e} What it means
Wrapped as LLMError when the underlying LLM provider call inside Memory._getFactExtractMemory (memory extraction during add()) throws. The original error is logged and attached via the cause option, so the message 'LLM extraction failed: <e>' mirrors the provider failure (auth, rate limit, timeout, malformed request). This is a provider-side failure, not a validation problem.
Source
Thrown at mem0-ts/src/oss/src/memory/index.ts:933
const userPrompt = generateAdditiveExtractionPrompt({
existingMemories,
newMessages: parsedMessages,
lastKMessages: lastMessages,
customInstructions: this.customInstructions,
});
let response: string;
try {
response = (await this.llm.generateResponse(
[
{ role: "system", content: systemPrompt },
{ role: "user", content: userPrompt },
],
{ type: "json_object" },
)) as string;
} catch (e) {
console.error("LLM extraction failed:", e);
throw new LLMError(`LLM extraction failed: ${e}`, { cause: e });
}
// Parse response
let extractedMemories: Array<{
id?: string;
text?: string;
attributed_to?: string;
linked_memory_ids?: string[];
}> = [];
try {
const cleanResponse = extractJson(response);
if (cleanResponse && cleanResponse.trim()) {
try {
const parsed = AdditiveExtractionSchema.parse(
JSON.parse(cleanResponse),
);
extractedMemories = parsed.memory;
} catch {View on GitHub (pinned to 001c235229)
Solutions
- Read the cause in the caught error — it names the real provider failure; fix that (key, quota, model name)
- For 429/timeout, retry add() with backoff; the call is not idempotent per message, so dedupe on your side if you retry
- For very long messages, chunk or truncate input before calling add()
- Verify the llm config block of Memory constructor matches a provider and model your credentials support
Example fix
// before
await memory.add('User likes tea', { userId: 'alice' });
// after
try {
await memory.add('User likes tea', { userId: 'alice' });
} catch (e) {
if (e instanceof LLMError) {
console.error('provider cause:', e.cause);
await sleep(backoffMs(attempt)); // retry on 429/timeout
} else throw e;
} Defensive patterns
Strategy: retry
Try / catch
for (let attempt = 0; attempt < 3; attempt++) {
try {
return await memory.add(text, { userId });
} catch (e) {
const msg = String((e as Error & { cause?: Error })?.cause?.message ?? e);
if (/429|rate limit|timeout|ECONN/i.test(msg) && attempt < 2) {
await new Promise(r => setTimeout(r, 2 ** attempt * 500));
continue;
}
throw e;
}
} Prevention
- Always inspect e.cause — it carries the real provider error
- Keep LLM credentials valid and model names available before batch ingestion
- Throttle concurrent add() calls to stay under provider rate limits
When it happens
Trigger: Any exception from this.llm.generateResponse([system, user], { type: 'json_object' }) during add(): invalid/expired OpenAI-style API key, 429 rate limit, network timeout, model name not available to the account, or context length exceeded by very long messages.
Common situations: Wrong or missing OPENAI_API_KEY in the environment where the OSS Memory runs; hitting org rate limits when batch-adding many memories; switching the LLM config to a model the key cannot access; enormous transcripts exceeding the model's token limit.
Related errors
- LLM extraction failed: {e}
- DeepSeek LLM failed: ${message}
- LiteLLM failed: ${message}
- LM Studio LLM failed: ${message}
- MiniMax LLM failed: ${message}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/c36a736d7249fb8e.
Report an issue: GitHub.