Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

fix: use Optional type for non-required template fields

problemsolverai2026-svgc18b639a015e
diff --git a/hyperextract/utils/template_engine/parsers/output.py b/hyperextract/utils/template_engine/parsers/output.py
index 87139fe..dd32bfa 100644
--- a/hyperextract/utils/template_engine/parsers/output.py
+++ b/hyperextract/utils/template_engine/parsers/output.py
@@ -1,6 +1,6 @@
"""Output schema parser."""
-from typing import List
+from typing import List, Optional
from .schemas import (
FieldSchema,
NaiveOutputSchema,
@@ -33,8 +33,14 @@ def build_naive_schema(
kwargs["default"] = field.default
elif field.required is False: # 非必填且无默认值时,设 default=None
kwargs["default"] = None
+ # Use Optional type for non-required fields so None values pass validation
+ base_type = TYPE_MAPPING[field.type]
+ if field.required is False:
+ field_type = Optional[base_type]
+ else:
+ field_type = base_type
schema_fields[field.name] = (
- TYPE_MAPPING[field.type],
+ field_type,
Field(**kwargs),
)
return create_model(name, __doc__=description, **schema_fields)