fix: handle string attributes in graph ontology to prevent TypeError crash - #581
fix: handle string attributes in graph ontology to prevent TypeError crash#581octo-patch wants to merge 1 commit into
Conversation
…crash (fixes 666ghj#135) When the LLM returns ontology attributes as plain strings instead of dicts, set_ontology() crashes with "TypeError: string indices must be integers, not 'str'" at attr_def["name"]. Two-layer fix: 1. ontology_generator.py: normalize string attrs to {"name", "type", "description"} dicts during validation, so downstream code always receives well-formed structures. 2. graph_builder.py: add isinstance guard as a safety net in set_ontology() for both entity and edge attribute loops. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
|
Thank you for identifying the string-attribute crash in #135. Your diagnosis of the immediate failure was correct, and we preserved your original commit in the maintained implementation merged through #738. The final version centralizes normalization, skips unusable non-string shapes, protects graph_id and legacy group_id, caps each custom model at 10 fields, supplies a deterministic property for empty models, and preserves the long-document sampling already merged from #584. It also includes direct schema-conversion tests against the repository-pinned zep-cloud 3.13.0 SDK. The complete backend suite passed with 42 tests. This PR is now closed as superseded by the merged implementation. No commercial Zep request was sent because the review environment did not have a ZEP_API_KEY. 🤖 Sent by the MiroFish repository maintenance agent. |
Fixes #135
Problem
When the LLM returns ontology
attributesas a plain list of strings (e.g.["full_name", "role"]) instead of the expected list of dicts (e.g.[{"name": "full_name", "type": "text", "description": "..."}]),set_ontology()ingraph_builder.pycrashes with:at
attr_def["name"]for both entity and edge attribute loops.Solution
Two-layer fix:
ontology_generator.py(primary fix): Normalize string attributes to properly-structured dicts during_validate_ontology_result(). Any attribute that arrives as a bare stringsis converted to{"name": s, "type": "text", "description": s}before it reaches downstream code.graph_builder.py(safety net): Addisinstance(attr_def, str)guard in both the entity and edge attribute loops insideset_ontology(). This ensures the crash cannot occur even if the ontology was built through a path that skips the generator's validation.Testing
Tested with an ontology payload where
attributesis a list of strings — graph build now completes without error. Existing dict-format attributes continue to work as before.