Graphify-Labs/graphify · error · ValueError
Extraction JSON has {len(errors)} error(s):
Error message
Extraction JSON has {len(errors)} error(s):
What it means
Raised by assert_valid (graphify/validate.py) after validate_extraction collected one or more schema violations in an extraction JSON dict: missing 'nodes'/'edges' keys, non-list values, nodes/edges that are not objects, missing required fields (id, label, file_type, source_file on nodes; source, target, relation, confidence, source_file on edges), invalid file_type/confidence enums, non-hashable ids, or edge endpoints that reference no known node id. The single ValueError aggregates every problem as a bulleted list, so one raise reports all defects at once.
Source
Thrown at graphify/validate.py:95
try:
unmatched = bool(node_ids) and val not in node_ids
except TypeError:
errors.append(
f"Edge {i} {endpoint} {val!r} is non-hashable - must be a string"
)
continue
if unmatched:
errors.append(f"Edge {i} {endpoint} '{val}' does not match any node id")
return errors
def assert_valid(data: dict) -> None:
"""Raise ValueError with all errors if extraction is invalid."""
errors = validate_extraction(data)
if errors:
msg = f"Extraction JSON has {len(errors)} error(s):\n" + "\n".join(f" • {e}" for e in errors)
raise ValueError(msg)
View on GitHub (pinned to 7fe58b0b0f)
Solutions
- Read the bulleted lines in the message — each names the index and the exact defect; fix them in the JSON before re-validating.
- For unmatched edge endpoints, either add the missing nodes or drop/repair the dangling edges (most common failure).
- Constrain your LLM prompt to the enums: file_type in {code, document, paper, image, rationale, concept}, confidence in {EXTRACTED, INFERRED, AMBIGUOUS}.
- Run validate_extraction(data) (returns a list, no raise) in a pre-commit or pipeline step so drift is caught before assert_valid.
Example fix
# before (edge references a node that doesn't exist)
data = {"nodes": [{"id": "n1", "label": "A", "file_type": "code", "source_file": "a.py"}],
"edges": [{"source": "n1", "target": "nX", "relation": "calls", "confidence": "EXTRACTED", "source_file": "a.py"}]}
assert_valid(data) # ValueError: 1 error(s)
# after
data["edges"][0]["target"] = "n1"
assert_valid(data) # passes Defensive patterns
Strategy: validation
Validate before calling
from graphify.validate import validate_extraction
errors = validate_extraction(data) # returns list[str], never raises
if errors:
data = repair_extraction(data, errors) # add missing nodes, coerce enums, etc.
assert not validate_extraction(data) Type guard
def is_valid_extraction(data: object) -> bool:
return isinstance(data, dict) and validate_extraction(data) == [] Try / catch
try:
assert_valid(data)
except ValueError as e:
# message aggregates every defect as ' • ...' lines — parse and report all
defects = [ln.strip("• ") for ln in str(e).splitlines() if ln.strip().startswith("•")]
report_to_user(defects) # fix-and-retry loop instead of failing on the first Prevention
- Run validate_extraction (non-raising) in pipelines before assert_valid.
- Give LLM extractors the exact enums for file_type and confidence in the prompt.
- Validate node ids first, then re-point or drop dangling edges referencing unknown ids.
- Treat any drift between extraction and schema as a prompt bug, not a data lottery.
When it happens
Trigger: Calling assert_valid(data) on LLM-produced or hand-written extraction JSON that violates the schema — typical cases: edge source/target ids that don't match any node id, a node missing 'label', file_type 'snippet' outside {code, document, paper, image, rationale, concept}, or confidence 'high' outside {EXTRACTED, INFERRED, AMBIGUOUS}. Also 'edges' spelled as neither edges nor links (links is accepted as a NetworkX <=3.1 fallback).
Common situations: Prompting an LLM to emit graphify extraction JSON and getting drifted field names or hallucinated edge ids; merging partial extractions where a node was dropped but its edges remained; schema drift between graphify versions; hand-editing graph.json and forgetting required fields.
Related errors
- Graph path must be a .json file, got: {graph_path!r}
- could not read Google Workspace shortcut {path}: {exc}
- Google Workspace shortcut {path} does not include a Drive fi
- ingest: {exc}
- outcome must be one of {OUTCOMES}, got {outcome!r}
AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14).
Data as JSON: /api/errors/be899e777aa1a848.
Report an issue: GitHub.