Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docling_core/types/doc/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
FieldSerializationInfo,
SerializerFunctionWrapHandler,
StringConstraints,
ValidationInfo,
computed_field,
field_serializer,
field_validator,
Expand Down Expand Up @@ -5643,6 +5644,9 @@ def save_as_json(
with open(filename, "w", encoding="utf-8") as fw:
json.dump(out, fw, indent=indent)

class _ValidationContext(BaseModel):
validate_ref_bidir: bool = True # whether to validate reference bidirectionality

@classmethod
def load_from_json(cls, filename: Union[str, Path]) -> "DoclingDocument":
"""load_from_json.
Expand Down Expand Up @@ -7074,7 +7078,6 @@ def _normalize_table_children_from_rich_cells(self):
table.children.append(cell.ref)
child_crefs.add(cell.ref.cref)

@model_validator(mode="after")
def validate_document(self) -> Self:
"""validate_document."""

Expand All @@ -7086,6 +7089,14 @@ def validate_document(self) -> Self:

return self

@model_validator(mode="after")
def _validate_document(self, info: ValidationInfo) -> Self:
ctx = self._ValidationContext.model_validate(info.context or {})
if ctx.validate_ref_bidir:
return self.validate_document()
else:
return self

@model_validator(mode="after")
def validate_misplaced_list_items(self) -> Self:
"""validate_misplaced_list_items."""
Expand Down
Loading