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: validate document templates require output.fields

Frankie-Xub68db6a425cc
diff --git a/hyperextract/utils/template_engine/validator.py b/hyperextract/utils/template_engine/validator.py
index 027cebf..50831df 100644
--- a/hyperextract/utils/template_engine/validator.py
+++ b/hyperextract/utils/template_engine/validator.py
@@ -63,7 +63,7 @@ BINARY_GRAPH_TYPES = frozenset(
)
TEMPORAL_TYPES = frozenset({"temporal_graph", "spatio_temporal_graph"})
SPATIAL_TYPES = frozenset({"spatial_graph", "spatio_temporal_graph"})
-RECORD_TYPES = frozenset({"model", "list", "set"})
+RECORD_TYPES = frozenset({"model", "list", "set", "document"})
FIELD_COUNT_LIMIT = 5
_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}")
diff --git a/tests/cli/test_template_validate.py b/tests/cli/test_template_validate.py
index e64dc76..d53098a 100644
--- a/tests/cli/test_template_validate.py
+++ b/tests/cli/test_template_validate.py
@@ -69,6 +69,24 @@ class TestTemplateValidateCli:
assert result.exit_code == 0
assert "OK" in result.output
+ def test_document_graph_output_exits_one_with_he_t002(self, tmp_path):
+ path = _write(
+ tmp_path,
+ VALID_GRAPH.replace("type: graph", "type: document").replace(
+ "name: ValidGraph", "name: BadDocument"
+ ),
+ )
+ result = runner.invoke(app, ["template", "validate", str(path)])
+ assert result.exit_code == 1
+ assert "HE-T002" in result.output
+ assert "output.fields" in result.output
+
+ def test_base_document_preset_is_clean(self):
+ path = PRESETS_DIR / "general" / "base_document.yaml"
+ result = runner.invoke(app, ["template", "validate", str(path)])
+ assert result.exit_code == 0, result.output
+ assert "OK" in result.output
+
def test_identifier_error_exits_one(self, tmp_path):
path = _write(
tmp_path, VALID_GRAPH.replace("entity_id: name", "entity_id: nope")
diff --git a/tests/template_engine/test_validator.py b/tests/template_engine/test_validator.py
index c1f5313..c2c1369 100644
--- a/tests/template_engine/test_validator.py
+++ b/tests/template_engine/test_validator.py
@@ -159,6 +159,11 @@ class TestValidTemplates:
assert result.ok
assert result.diagnostics == []
+ def test_gallery_base_document_has_no_errors(self):
+ result = validate_template(PRESETS_DIR / "general" / "base_document.yaml")
+ assert result.ok
+ assert not any(d.severity == "error" for d in result.diagnostics)
+
class TestStructureErrors:
def test_invalid_yaml(self, tmp_path):
@@ -173,6 +178,41 @@ class TestStructureErrors:
assert not result.ok
assert HE_T002 in _codes(result)
+ def test_document_with_graph_output_is_he_t002(self, tmp_path):
+ yaml_text = VALID_GRAPH.replace("type: graph", "type: document").replace(
+ "name: ValidGraph", "name: BadDocument"
+ )
+ result = validate_template(_write(tmp_path, yaml_text))
+ assert not result.ok
+ diags = _by_code(result, HE_T002)
+ assert diags
+ assert any("output.fields" in d.message for d in diags)
+
+ def test_document_with_only_entities_is_he_t002(self, tmp_path):
+ yaml_text = """
+language: en
+name: EntitiesOnlyDocument
+type: document
+tags: [test]
+description: document with a graph entities block
+output:
+ description: wrong shape
+ entities:
+ description: entities
+ fields:
+ - name: name
+ type: str
+ description: entity name
+guideline:
+ target: Extract
+ rules: Keep names
+display:
+ label: '{name}'
+"""
+ result = validate_template(_write(tmp_path, yaml_text))
+ assert not result.ok
+ assert HE_T002 in _codes(result)
+
def test_missing_file(self, tmp_path):
result = validate_template(tmp_path / "missing.yaml")
assert not result.ok