Skip to content

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

Closed
octo-patch wants to merge 1 commit into
666ghj:mainfrom
octo-patch:fix/issue-135-normalize-attributes-strings
Closed

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

Conversation

@octo-patch

Copy link
Copy Markdown
Contributor

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
@666ghj

666ghj commented Jul 22, 2026

Copy link
Copy Markdown
Owner

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.

@666ghj 666ghj closed this Jul 22, 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图谱构建失败

2 participants