{"record":{"id":"c36a736d7249fb8e","repo":"mem0ai/mem0","slug":"llm-extraction-failed-e","errorCode":null,"errorMessage":"LLM extraction failed: ${e}","messagePattern":"LLM extraction failed: (.+?)","errorType":"exception","errorClass":"LLMError","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/memory/index.ts","lineNumber":933,"sourceCode":"    const userPrompt = generateAdditiveExtractionPrompt({\n      existingMemories,\n      newMessages: parsedMessages,\n      lastKMessages: lastMessages,\n      customInstructions: this.customInstructions,\n    });\n\n    let response: string;\n    try {\n      response = (await this.llm.generateResponse(\n        [\n          { role: \"system\", content: systemPrompt },\n          { role: \"user\", content: userPrompt },\n        ],\n        { type: \"json_object\" },\n      )) as string;\n    } catch (e) {\n      console.error(\"LLM extraction failed:\", e);\n      throw new LLMError(`LLM extraction failed: ${e}`, { cause: e });\n    }\n\n    // Parse response\n    let extractedMemories: Array<{\n      id?: string;\n      text?: string;\n      attributed_to?: string;\n      linked_memory_ids?: string[];\n    }> = [];\n    try {\n      const cleanResponse = extractJson(response);\n      if (cleanResponse && cleanResponse.trim()) {\n        try {\n          const parsed = AdditiveExtractionSchema.parse(\n            JSON.parse(cleanResponse),\n          );\n          extractedMemories = parsed.memory;\n        } catch {","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/memory/index.ts#L915-L951","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait memory.add('User likes tea', { userId: 'alice' });\n\n// after\ntry {\n  await memory.add('User likes tea', { userId: 'alice' });\n} catch (e) {\n  if (e instanceof LLMError) {\n    console.error('provider cause:', e.cause);\n    await sleep(backoffMs(attempt)); // retry on 429/timeout\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (let attempt = 0; attempt < 3; attempt++) {\n  try {\n    return await memory.add(text, { userId });\n  } catch (e) {\n    const msg = String((e as Error & { cause?: Error })?.cause?.message ?? e);\n    if (/429|rate limit|timeout|ECONN/i.test(msg) && attempt < 2) {\n      await new Promise(r => setTimeout(r, 2 ** attempt * 500));\n      continue;\n    }\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["llm","network","oss","memory-add","retry"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}