fix: handle string attributes in graph ontology to prevent TypeError crash#581
Open
octo-patch wants to merge 1 commit into666ghj:mainfrom
Open
fix: handle string attributes in graph ontology to prevent TypeError crash#581octo-patch wants to merge 1 commit into666ghj:mainfrom
octo-patch wants to merge 1 commit into666ghj:mainfrom
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>
5 tasks
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.
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.