run-llama/llama_index · error · ValueError

Could not infer node type for data: {node_dict!s}

Error message

Could not infer node type for data: {node_dict!s}

What it means

Raised by SimplePropertyGraphStore.from_dict when a serialized node dict contains neither a 'name' key (which would make it an EntityNode) nor a 'text' key (which would make it a ChunkNode). Node type is inferred purely by key sniffing during manual deserialization, so any other shape is unrecoverable.

Source

Thrown at llama-index-core/llama_index/core/graph_stores/simple_labelled.py:214

        return cls.from_persist_path(persist_path, fs=fs)

    @classmethod
    def from_dict(
        cls,
        data: dict,
    ) -> "SimplePropertyGraphStore":
        """Load from dict."""
        # need to load nodes manually
        node_dicts = data["nodes"]

        kg_nodes: Dict[str, LabelledNode] = {}
        for id, node_dict in node_dicts.items():
            if "name" in node_dict:
                kg_nodes[id] = EntityNode.model_validate(node_dict)
            elif "text" in node_dict:
                kg_nodes[id] = ChunkNode.model_validate(node_dict)
            else:
                raise ValueError(f"Could not infer node type for data: {node_dict!s}")

        # clear the nodes, to load later
        data["nodes"] = {}

        # load the graph
        graph = LabelledPropertyGraph.model_validate(data)

        # add the node back
        graph.nodes = kg_nodes

        return cls(graph)

    def to_dict(self) -> dict:
        """Convert to dict."""
        return self.graph.model_dump()

    # NOTE: Unimplemented methods for SimplePropertyGraphStore

View on GitHub (pinned to afd0fef371)

Solutions

  1. Regenerate the persisted dict with the same llama-index version that reads it, so each node carries 'name' (entities) or 'text' (chunks).
  2. Repair the data by adding the correct key per node type before from_dict: name for entities, text for chunks.
  3. If the source is another store implementation, convert nodes explicitly to EntityNode/ChunkNode models instead of relying on from_dict inference.

Example fix

# before
store = SimplePropertyGraphStore.from_dict(loaded_json)  # node missing name/text

# after
for node in loaded_json["nodes"].values():
    if "name" not in node and "text" not in node:
        node["text"] = node.get("id", "")  # or route to EntityNode with node["name"] = ...
store = SimplePropertyGraphStore.from_dict(loaded_json)
Defensive patterns

Strategy: validation

Validate before calling

for node_id, nd in data["nodes"].items():
    if "name" not in nd and "text" not in nd:
        raise ValueError(f"Node {node_id} lacks 'name'/'text'; cannot infer type")
store = SimplePropertyGraphStore.from_dict(data)

Type guard

def all_nodes_have_type_key(node_dicts: dict) -> bool:
    return all(("name" in nd) or ("text" in nd) for nd in node_dicts.values())

Prevention

When it happens

Trigger: Calling SimplePropertyGraphStore.from_dict(data) on hand-edited JSON, data exported from a different property-graph store version, or dicts whose node fields were renamed/filtered (e.g. serialized with exclude={'text'}) before saving.

Common situations: Schema drift between llama-index versions changing node serialization keys; round-tripping persisted graph JSON through external tools that drop empty strings (a node with text='' may lose the key); merging graphs from heterogeneous sources.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/b1231d9426a3529d. Report an issue: GitHub.