{"id":2485,"library":"docling-core","title":"Docling Core","description":"Docling Core is a Python library for defining, validating, and structuring data types and schemas. It's designed to align with the Docling specification, offering robust data validation capabilities. Currently at version 2.73.0, it undergoes frequent updates, often with daily or weekly releases in its 2.x series.","status":"active","version":"2.73.0","language":"en","source_language":"en","source_url":"https://github.com/docling/docling-core","tags":["data validation","schema definition","data types","openapi"],"install":[{"cmd":"pip install docling-core","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The 'Type' class was removed in version 2.0.0 and replaced by 'DataType'.","wrong":"from docling_core import Type","symbol":"DataType","correct":"from docling_core import DataType"},{"symbol":"Field","correct":"from docling_core import Field"},{"note":"The 'ValidationError' class was renamed to 'ValidationErrors' in version 2.0.0.","wrong":"from docling_core import ValidationError","symbol":"ValidationErrors","correct":"from docling_core import ValidationErrors"}],"quickstart":{"code":"from docling_core import Field, DataType\n\nclass User(DataType):\n    name = Field(str, description=\"The user's full name\")\n    age = Field(int, min_value=0, description=\"The user's age\")\n    email = Field(str, format=\"email\", description=\"The user's email address\")\n\nuser_data = {\n    \"name\": \"John Doe\",\n    \"age\": 30,\n    \"email\": \"john.doe@example.com\"\n}\n\ntry:\n    user = User(user_data)\n    print(f\"Validated user: {user.name}, {user.age}, {user.email}\")\nexcept Exception as e:\n    print(f\"Validation error: {e}\")\n\n# Example of invalid data\ninvalid_user_data = {\n    \"name\": \"Jane Doe\",\n    \"age\": -5,  # Invalid age\n    \"email\": \"invalid-email\"\n}\n\ntry:\n    User(invalid_user_data)\nexcept Exception as e:\n    print(f\"Validation error for invalid data: {e}\")","lang":"python","description":"This example defines a `User` data type with `Field` validators for name, age, and email. It demonstrates how to instantiate a `DataType` with valid data and handles validation errors for invalid input."},"warnings":[{"fix":"Migrate all `Type` usages to `DataType`. E.g., `from docling_core import DataType`.","message":"The `Type` class was removed and replaced by `DataType`. Code using `from docling_core import Type` or instantiating `Type(...)` will break.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update exception handling: `except ValidationErrors as e:` instead of `except ValidationError as e:`.","message":"The primary exception class for validation errors was renamed from `ValidationError` to `ValidationErrors`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Change `class MyData(DataType, description=\"...\")` to `class MyData(DataType, _description=\"...\")`.","message":"The `description` argument for `DataType` classes was renamed to `_description` to avoid potential conflicts with user-defined fields.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Review `format` usage. Ensure it's one of the supported strings or a callable. Custom format validation might need a separate callable validator.","message":"The `format` argument in `Field` has stricter validation in 2.x and only accepts specific predefined formats (like 'email', 'uri') or a callable validator. Arbitrary strings might no longer work as expected.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"To allow extra fields, define the DataType with `class MyData(DataType, allow_extra_fields=True):`.","message":"By default, `DataType` is strict and will raise `ValidationErrors` if extra fields are provided in the input dictionary that are not defined in the `DataType` schema. Explicitly allow extra fields if needed.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}