imbajin commented on code in PR #362:
URL: https://github.com/apache/hugegraph-ai/pull/362#discussion_r3390153820
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/vector_graph_block.py:
##########
@@ -44,13 +44,59 @@
)
-def store_prompt(doc, schema, example_prompt,
graph_extract_split_type="document"):
- if (
+def _validate_schema_generator_examples(examples, label):
+ if examples is None:
+ return None
+ 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 store_prompt(
+ doc,
+ schema,
+ example_prompt,
+ graph_extract_split_type="document",
+ query_examples=None,
+ few_shot_examples=None,
+):
+ validated_query_examples =
_validate_schema_generator_examples(query_examples, "Query examples")
Review Comment:
⚠️ **Validate schema examples before generic actions**
Evidence: these save chains now run the primary action first and only then
call `store_prompt(..., query_example, few_shot)`. Since `store_prompt()`
validates those JSON blobs immediately, an invalid or blank schema-example
editor can make actions like clearing indexes report an error after the action
already ran, and blank values cannot clear a persisted override back to bundled
defaults.
Please keep schema-generator validation/persistence on an explicit
schema-generator save/generate path, or validate before the primary action and
treat blank/whitespace examples as clearing the persisted override. Add a
regression test for clearing both fields back to the bundled fallback.
--
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]