Skip to content

feat: add layout_model per-request option for layout analysis model selection#113

Open
b-g-d wants to merge 1 commit intodocling-project:mainfrom
b-g-d:feat/layout-model-selection
Open

feat: add layout_model per-request option for layout analysis model selection#113
b-g-d wants to merge 1 commit intodocling-project:mainfrom
b-g-d:feat/layout-model-selection

Conversation

@b-g-d
Copy link
Copy Markdown

@b-g-d b-g-d commented Mar 24, 2026

Summary

Adds a layout_model enum field to ConvertDocumentsOptions so users can select between docling's 6 layout analysis models (docling_layout_heron, docling_layout_heron_101, docling_layout_egret_medium, docling_layout_egret_large, docling_layout_egret_xlarge, docling_layout_v2) without manually constructing verbose layout_custom_config dicts.

A @model_validator(mode="before") expands layout_model into the existing layout_custom_config dict, maintaining full backward compatibility. When layout_custom_config is explicitly provided, it takes precedence.

Context

This was originally submitted as docling-serve#540, but @dolfim-ibm directed it here since the datamodel belongs in docling-jobkit. The docling-serve side (Gradio UI dropdown, DOCLING_SERVE_DEFAULT_LAYOUT_MODEL env var, docs) will be submitted as a follow-up PR once this is merged.

Changes

File Change
docling_jobkit/datamodel/convert.py Import LayoutModelType + 6 model spec constants; add LAYOUT_MODEL_SPECS mapping; add layout_model field; add expand_layout_model model validator; update layout_custom_config description noting precedence
tests/test_layout_model.py 7 unit tests covering expansion, all model types, precedence, None default, string values, and invalid model rejection

Test plan

  • uv run pytest tests/test_layout_model.py — all 7 tests pass
  • uv run pytest tests/test_kind_selection.py tests/test_convert_options.py — all existing tests still pass
  • test_options_validator failure is pre-existing on main (unrelated InlineVlmOptions comparison)

Note on upcoming ONNX changes

@dolfim-ibm mentioned upcoming layout model changes with different ONNX runtimes. This PR only adds the layout_modellayout_custom_config expansion at the request options level and doesn't touch the runtime/converter layer, so it should be compatible with those changes. If the LayoutModelType enum or LayoutModelConfig shape changes in docling, the LAYOUT_MODEL_SPECS mapping here would need a corresponding update.

…election

Add a `layout_model` enum field to `ConvertDocumentsOptions` so users
can select between docling's 6 layout analysis models without manually
constructing verbose `layout_custom_config` dicts.

A model_validator(mode="before") expands `layout_model` into the
existing `layout_custom_config` dict, maintaining full backward
compatibility. When `layout_custom_config` is explicitly provided,
it takes precedence.

Signed-off-by: bryan <b-g-d@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bryan <b-g-d@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @b-g-d, all your commits are properly signed off. 🎉

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 24, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant