Skip to content

fix: key error when llm omits entities key tool call#4313

Merged
kartik-mem0 merged 2 commits intomem0ai:mainfrom
amahuli03:4312/fix-key-error-when-llm-omits-entities-key-tool-call
Mar 16, 2026
Merged

fix: key error when llm omits entities key tool call#4313
kartik-mem0 merged 2 commits intomem0ai:mainfrom
amahuli03:4312/fix-key-error-when-llm-omits-entities-key-tool-call

Conversation

@amahuli03
Copy link
Copy Markdown
Contributor

@amahuli03 amahuli03 commented Mar 12, 2026

Description

Fixes a KeyError: 'entities' crash in _retrieve_nodes_from_data when the LLM returns an extract_entities tool call without the entities key in its arguments (e.g. for short inputs like "Hello.")
Uses safe .get() access with defaults instead of direct dictionary indexing across all four graph memory

implementations: graph_memory.py, kuzu_memory.py, memgraph_memory.py, and neptune/base.py
Adds test coverage for the missing-key scenario to test_memgraph_memory.py and test_kuzu.py.

Fixes #4312

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test
    • Existing memgraph and kuzu tests pass
    • New test_missing_entities_key_returns_empty tests pass in both test files
    • New TestRetrieveNodesFromData class in test_kuzu.py covers happy path, missing key, and None tool_calls

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Maintainer Checklist

@kartik-mem0 kartik-mem0 merged commit 2e5e290 into mem0ai:main Mar 16, 2026
6 of 7 checks passed
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError for entities during retrieval

3 participants