Skip to content

fix(memory): centralize entity cleanup and skip malformed LLM relation dicts#4515

Merged
whysosaket merged 1 commit intomem0ai:mainfrom
Himanshu-Sangshetti:fix/memory-remove-spaces-entities-dry
Mar 28, 2026
Merged

fix(memory): centralize entity cleanup and skip malformed LLM relation dicts#4515
whysosaket merged 1 commit intomem0ai:mainfrom
Himanshu-Sangshetti:fix/memory-remove-spaces-entities-dry

Conversation

@Himanshu-Sangshetti
Copy link
Copy Markdown
Contributor

Linked Issue

Closes #3907

Description

Context — earlier PR (#4184)
PR #4184 fixed _remove_spaces_from_entities only in graph_memory.py (Neo4j) by skipping empty/incomplete relation dicts from LLM output, which removed KeyError when the model returned values like [{}] or dicts missing source / relationship / destination and the code implementation was perfect only.
Why this PR
The same helper logic existed in four places (graph_memory, memgraph_memory, kuzu_memory, neptune/base). #4184 only updated Neo4j, so Memgraph, Kuzu, and Neptune could still hit the same failure mode. This PR:

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Refactor (no functional changes)

Breaking Changes

N/A

Test Coverage

  • I added/updated unit tests

Added tests/memory/test_memory_utils.py covering malformed lists, both sanitization modes, and non-dict entries. Ran:
pytest tests/memory/test_memory_utils.py tests/memory/test_neo4j_cypher_syntax.py tests/memory/test_memgraph_memory.py -v

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed

@whysosaket whysosaket merged commit ae49ede into mem0ai:main Mar 28, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants