Skip to content

fix: handle string attributes in graph ontology to prevent TypeError crash#581

Open
octo-patch wants to merge 1 commit into666ghj:mainfrom
octo-patch:fix/issue-135-normalize-attributes-strings
Open

fix: handle string attributes in graph ontology to prevent TypeError crash#581
octo-patch wants to merge 1 commit into666ghj:mainfrom
octo-patch:fix/issue-135-normalize-attributes-strings

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #135

Problem

When the LLM returns ontology attributes as 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() in graph_builder.py crashes with:

TypeError: string indices must be integers, not 'str'

at attr_def["name"] for both entity and edge attribute loops.

Solution

Two-layer fix:

  1. ontology_generator.py (primary fix): Normalize string attributes to properly-structured dicts during _validate_ontology_result(). Any attribute that arrives as a bare string s is converted to {"name": s, "type": "text", "description": s} before it reaches downstream code.

  2. graph_builder.py (safety net): Add isinstance(attr_def, str) guard in both the entity and edge attribute loops inside set_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 attributes is a list of strings — graph build now completes without error. Existing dict-format attributes continue to work as before.

…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>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

报错,Zep图谱构建失败

1 participant