Fix handle malformed entity dicts and None LLM response in memgraph_memory#4238
Merged
deshraj merged 3 commits intomem0ai:mainfrom Mar 7, 2026
Merged
Conversation
…es_from_data instead of crashing the entire loop (KeyError: entity_type), fix in _establish_nodes_relations_from_data when LLM returns None (TypeError: NoneType object is not subscriptable) — matches pattern in graph_memory.py, issues mem0ai#4055 , related mem0ai#2054
deshraj
previously approved these changes
Mar 7, 2026
Contributor
Author
|
fix linting issues ^ @deshraj |
deshraj
approved these changes
Mar 7, 2026
18 tasks
iamvaleriofantozzi
pushed a commit
to iamvaleriofantozzi/mem0-1
that referenced
this pull request
Mar 19, 2026
jamebobob
pushed a commit
to jamebobob/mem0-vigil-recall
that referenced
this pull request
Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two crashes in
memgraph_memory.pywhen callingmemory.add()with graph memory enabled.Fixes #4055 | Related #2054
Bugs Fixed
1.
KeyError: 'entity_type'When the LLM returns a malformed entity like
{"entity": "task"}with noentity_type, the loopcrashes and drops all remaining entities silently. Fixed by skipping invalid items instead of
stopping the loop.
2.
TypeError: 'NoneType' object is not subscriptableWhen using
openai_structured,message.contentisNonewhen a tool call is made. The code didextracted_entities["tool_calls"]directly on thatNoneand crashed. Fixed by adding a nullcheck, same pattern already used in
graph_memory.py.Type of change
How Has This Been Tested?
Added
tests/memory/test_memgraph_memory.py. All 46 existing tests still pass.Bug 2 reproduced with real OpenAI API (
gpt-4o-mini):message.content"Hello world""Hello! How can I assist you today?"TypeError: string indices must be integers"The sky is blue."NoneTypeError: 'NoneType' object is not subscriptableBoth crash at
extracted_entities["tool_calls"], exact error from issue #4055.