fix(memory): re-raise LLM extraction failures instead of returning [] (salvage of #5178) (#5878)

This commit is contained in:
Bartok
2026-07-01 18:36:19 +05:30
committed by GitHub
parent c325bd3b8e
commit ad7e09851c
2 changed files with 55 additions and 2 deletions
+9 -2
View File
@@ -22,6 +22,7 @@ from mem0.configs.prompts import (
PROCEDURAL_MEMORY_SYSTEM_PROMPT,
generate_additive_extraction_prompt,
)
from mem0.exceptions import LLMError
from mem0.exceptions import ValidationError as Mem0ValidationError
from mem0.memory.base import MemoryBase
from mem0.memory.setup import mem0_dir, setup_config
@@ -912,8 +913,12 @@ class Memory(MemoryBase):
response_format={"type": "json_object"},
)
except Exception as e:
# Re-raise so callers can implement provider fallback / retry.
# The original silent ``return []`` made upstream callers unable to
# distinguish "LLM unavailable" (429/5xx/timeout) from "LLM
# extracted no facts" -- both surfaced as an empty list.
logger.error(f"LLM extraction failed: {e}")
return []
raise LLMError(f"LLM extraction failed: {e}") from e
# Parse response
try:
@@ -2536,8 +2541,10 @@ class AsyncMemory(MemoryBase):
response_format={"type": "json_object"},
)
except Exception as e:
# Re-raise so callers can implement provider fallback / retry
# (see sync counterpart for rationale).
logger.error(f"LLM extraction failed (async): {e}")
return []
raise LLMError(f"LLM extraction failed: {e}") from e
# Parse response
try: