Skip to content

fix: diagnose naive identifiers on graph templates at create - #191

Open
dex0shubham wants to merge 2 commits into
yifanfeng97:mainfrom
dex0shubham:fix/graph-template-naive-identifiers
Open

dex0shubham wants to merge 2 commits into
yifanfeng97:mainfrom
dex0shubham:fix/graph-template-naive-identifiers

Conversation

@dex0shubham

Copy link
Copy Markdown
Contributor

Problem

validate_identifiers_fields accepts either identifier schema (NaiveIdentifierSchema | GraphIdentifiersSchema), but after the autotype gate it reads identifiers.entity_id unguarded. NaiveIdentifierSchema only carries item_id, so a graph-family template that uses the naive block dies with a bare attribute error:

# a type: graph template whose identifiers block is `item_id: name`
Template.create("my_graph.yaml", "en", llm_client=llm, embedder=emb)
# AttributeError: 'NaiveIdentifierSchema' object has no attribute 'entity_id'

That is the same unhelpful-crash shape the 0.10.5 load-time check was added to replace — the author of the template gets no hint about what to change.

The right diagnosis already exists in the template validator (_check_identifiers, HE-T003: " templates require entity_id, relation_id, and relation_members (not item_id)"), but he template validate is opt-in while Template.create is on every path.

Fix

Guard the graph field checks with an isinstance test and raise the HE-T003 wording as a ValueError. One check in the shared validator covers all five graph-family creators.

ValueError: graph templates require identifiers.entity_id, relation_id, and relation_members (not item_id)

Verified every template in the Gallery still constructs (0 failures).

Tests

tests/template_engine/test_parser_identifiers.py::TestGraphTemplateWithNaiveIdentifiers:

  • test_naive_identifiers_rejected_with_guidance — naive identifiers on a graph type raise the guidance message (fails pre-fix with AttributeError).
  • test_graph_identifiers_still_accepted — a well-formed graph block still passes, so the guard cannot over-reject.

ruff check / ruff format --check clean; tests/template_engine/ 105 passed, full suite 724 passed (the 3 TestGoogleGeminiProvider failures are pre-existing on main without the optional google extra).

This branch has not been deployed

No deployments
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.

1 participant