VGalaxies commented on code in PR #362:
URL: https://github.com/apache/hugegraph-ai/pull/362#discussion_r3400830781
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/vector_graph_block.py:
##########
@@ -44,7 +44,56 @@
)
-def store_prompt(doc, schema, example_prompt,
graph_extract_split_type="document"):
+def _validate_schema_generator_examples(examples, label):
+ examples = (examples or "").strip()
+ if not examples:
+ return ""
+ try:
+ json.loads(examples)
+ except json.JSONDecodeError as exc:
+ raise gr.Error(f"{label} must be valid JSON: {exc.msg} at line
{exc.lineno}, column {exc.colno}") from exc
+ return examples
+
+
+def _load_persisted_json_examples(examples, label):
+ examples = (examples or "").strip()
+ if not examples:
+ return ""
+ try:
+ json.loads(examples)
+ except json.JSONDecodeError as exc:
+ log.warning("Ignoring invalid persisted %s: %s", label, exc)
+ return ""
+ return examples
+
+
+def _persist_schema_generator_examples(query_examples, few_shot_examples):
+ validated_query_examples =
_validate_schema_generator_examples(query_examples, "Query examples")
+ validated_few_shot_examples =
_validate_schema_generator_examples(few_shot_examples, "Few-shot schema
examples")
Review Comment:
**Medium: Validate few-shot schema shape before persisting**
`hugegraph-llm/src/hugegraph_llm/demo/rag_demo/vector_graph_block.py:72`
**Evidence**
- `_validate_schema_generator_examples()` only checks `json.loads()`, so
`_persist_schema_generator_examples()` accepts and saves values like
`[{"schema": {"vertices": []}}]`; the new tests use that array shape.
Downstream, `SchemaBuildNode` passes the parsed value through as
`few_shot_schema`, and `SchemaBuilder.run()` rejects anything that is not a
dict with `"'few_shot_schema' must be a dict"`.
**Impact**
- A user can save syntactically valid few-shot examples that make schema
generation fail, then the invalid persisted override keeps reloading until
manually cleared.
**Requested fix**
- Validate `few_shot_examples` as the object/dict shape required by schema
generation before writing it to YAML, or update the downstream flow to
intentionally accept the persisted shape and cover that path with a regression
test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]