apache / apache/hugegraph-ai

[Bug] load_into_graph drops the whole vertex when one property value mismatches its declared type, then edges fail with a cryptic "Invalid vertex id"

Open
#373 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
143
Forks
89
PR merge metrics
No merged PRs in 30d

Description

### Summary
When importing LLM-extracted graph data, `Commit2Graph.load_into_graph` treats a single property value whose type does not match the schema's declared `data_type` as a **whole-vertex** failure: it logs `"Property type/format 'age' is not correct, skip it & need check it again"` and then `continue`s, silently dropping the vertex. Any edge that references that vertex is then sent to the server with the *local* reference (`"1:Sarah"`) as an endpoint id and fails with `Server Exception: Invalid vertex id '1:Sarah'`. The log message says "skip it" (the property) but the code drops the **entire vertex** — message and behavior disagree.

### Reproduction (headless)
1. Schema without `propertykeys` (`CheckSchema` then defaults every property to `TEXT`): `person` with `primary_keys=["name"]`, `properties=["name","age","occupation"]`, `nullable_keys=["age","occupation"]`, `id_strategy="PRIMARY_KEY"`; edge `roommate` (person→person, property `date`).
2. Extraction returns a person with `"age":30` (JSON number — the demo prompt contract itself declares `age` as INT) plus a `roommate` edge whose `outV="1:Sarah"`.
3. Import: `age: 30` (int) fails the TEXT check → **Sarah's vertex is skipped** → `vid_mapping` has no `"1:Sarah"` → the edge falls back to the raw id → server returns `Invalid vertex id '1:Sarah'`.

The identical defect appears with a *correct* typed schema when an LLM returns `age:"30"` (string) for an `INT` property — numeric-string output is very common (see #185).

### Proposed behavior
- **Lossless coercion first.** A helper coerces a value to the declared `data_type`/`cardinality` when lossless: numeric string ↔ number, number → text, scalar → `[scalar]` for LIST/SET (then each element), strict `yyyy-MM-dd` for DATE. Unknown/un-coercible values are reported, never silently dropped.
- **Nullable property, un-coercible → drop just that property** (warning) and keep creating the vertex.
- **Primary-key / non-nullable property missing or un-coercible → skip that vertex with a reason**, and skip the edges that reference it — both named in the summary.
- **Edge endpoints**: never call `addEdge` with an id that was not produced by a successful `addVertex`.
- **Raise only if no vertex could be imported at all** (otherwise: partial import + clear summary).

### Extended Scope
The same coercion and validation logic should ideally be applied to **Edge properties**, which are susceptible to the exact same LLM hallucination issues as Vertex properties. Furthermore, to prevent a single hallucinated entity from crashing a batch operation, **PK mismatch should gracefully skip the entity rather than raising a fatal exception**. Edge properties are currently passed to the server with no type check, and server `CreateError`s are swallowed by `_handle_graph_creation`, so bad edges are silently lost today.

### Observability
Vertices and edges should go through the same coercion + reporting helper so diagnostics are aligned. Collect `dropped_properties` / `skipped_vertices` / `skipped_edges` with per-item reasons (`scope, item id, label, property, expected, actual, action`), attach the summary to the import result, and surface it in the demo (related: #247).

### Tests
The in-file `FIXME` at `hugegraph-llm/src/tests/operators/hugegraph_op/test_commit_to_hugegraph_load_into_graph.py:29` already requests this coverage: vertex nullable/primary/collection/date branches, edge-property coercion, edge-skip when an endpoint is missing, and the aggregated summary. Unit tests use a mock client.

I can submit a PR with the fix and tests.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at hugegraph-llm/src/tests/operators/hugegraph_op/test_commit_to_hugegraph_load_into_graph.py:29 and trace Commit2Graph.load_into_graph. Run the mock-client tests for nullable, primary, collection, and date vertex cases, edge-property coercion, missing endpoints, and the aggregated summary. Done means mismatched nullable fields do not drop vertices, invalid endpoints are skipped, and partial-import diagnostics report reasons without a fatal error unless no vertex imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design, databases
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.