From dced2fa8e6e6c0b72cbfbffb576ddad9502bc062 Mon Sep 17 00:00:00 2001 From: "Ahmed Nassar AHN@zurich.ibm.com" Date: Sat, 31 Oct 2026 18:16:26 +0100 Subject: [PATCH] fix(doclang): emit a fillable empty_value only inside a field item On the DocLang 0.9 base a CVAT empty_value directly in a legacy form group became outside , which the schema forbids (kv fixtures failed Schematron validation). The fillable value is now emitted only under a field item or field value; elsewhere empty_value stays plain text, as upstream. Co-Authored-By: Claude Opus 5.5 --- docling_core/transforms/serializer/doclang.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docling_core/transforms/serializer/doclang.py b/docling_core/transforms/serializer/doclang.py index 80a463ff..75d85798 100644 --- a/docling_core/transforms/serializer/doclang.py +++ b/docling_core/transforms/serializer/doclang.py @@ -1311,10 +1311,13 @@ class DocLangTextSerializer(BaseModel, BaseTextSerializer): wrap_open_token = f'<{tok.value} class="{item.kind}">' elif isinstance(item, FieldHeadingItem): wrap_open_token = DocLangVocabulary._create_field_heading_token(level=item.level) - elif isinstance(item, TextItem) and item.label == DocItemLabel.EMPTY_VALUE: - # CVAT empty_value / fillable_field. A parent field_value already - # carries the tag; otherwise emit the fillable value itself. - parent_item = item.parent.resolve(doc) if item.parent else None + elif isinstance(item, TextItem) and item.label == DocItemLabel.EMPTY_VALUE and ( + isinstance(parent_item := (item.parent.resolve(doc) if item.parent else None), FieldValueItem | FieldItem) + ): + # CVAT empty_value / fillable_field inside a field item. A parent field_value + # already carries the tag; directly under the field item, emit the fillable + # value itself. Elsewhere (e.g. a legacy
group) a would sit + # outside , which DocLang forbids: such items stay plain text. if isinstance(parent_item, FieldValueItem): wrap_open_token = None else: @@ -1323,6 +1326,7 @@ class DocLangTextSerializer(BaseModel, BaseTextSerializer): elif isinstance(item, TextItem) and ( item.label in [ # FIXME: Catch all ... + DocItemLabel.EMPTY_VALUE, # outside a field item (e.g. legacy ): plain text, as upstream DocItemLabel.HANDWRITTEN_TEXT, DocItemLabel.PARAGRAPH, DocItemLabel.REFERENCE,