Skip to content

build_from_json crashes on edges with 'from'/'to' keys instead of 'source'/'target' #216

Closed

Description

@pedrolbacelar

Bug

build_from_json in graphify/build.py crashes with KeyError: 'source' when edges use alternate key names like from/to instead of the expected source/target.

How to reproduce

When using LLM subagents (particularly smaller/faster models) for semantic extraction, they sometimes produce edges with {"from": "node_a", "to": "node_b", ...} instead of {"source": "node_a", "target": "node_b", ...}. This is a reasonable variation that the schema doesn't enforce at the subagent level.

When these edges reach build_from_json, line 45 does:

src, tgt = edge["source"], edge["target"]

This raises KeyError and crashes the entire graph build, losing all extraction work (including paid LLM tokens).

Expected behavior

build_from_json should normalize common alternate key names (from → source, to → target) before processing, and skip edges that are truly malformed (missing both variants).

Impact

  • Edges with valid relationships are silently lost or cause crashes
  • Smaller models (Sonnet, Haiku) are more likely to produce alternate key names
  • The crash happens after the expensive LLM extraction, so the token cost is wasted

Suggested fix

for edge in extraction.get("edges", []):
    if "from" in edge and "source" not in edge:
        edge["source"] = edge.pop("from")
    if "to" in edge and "target" not in edge:
        edge["target"] = edge.pop("to")
    if "source" not in edge or "target" not in edge:
        continue
    src, tgt = edge["source"], edge["target"]

I have a PR ready for this: #217 (pending)

Activity

  1. added a commit that references this issue on Apr 11, 2026
  2. safishamsi commented on Apr 11, 2026

    @safishamsi
    Member

    Fixed in v0.4.2. Edges using from/to keys are now normalized to source/target before processing, so they are no longer silently dropped.

  3. added a commit that references this issue on Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions