docling-project/docling · error · ValueError

Unsupported template type: {type(template)}

Error message

Unsupported template type: {type(template)}

What it means

ExtractionVlmPipeline's template normalization (_prepare_template) accepts only specific template shapes — including pydantic BaseModel subclasses (for which it builds a polyfactory ModelFactory) and presumably BaseModel instances / JSON strings handled by earlier branches. Anything else (dict, dataclass, str schema, TypedDict) reaches the final else and raises ValueError with the template's type.

Source

Thrown at docling/pipeline/extraction_vlm_pipeline.py:226

        if isinstance(template, str):
            return template
        elif isinstance(template, dict):
            return json.dumps(template, indent=2)
        elif isinstance(template, BaseModel):
            return template.model_dump_json(indent=2)
        elif inspect.isclass(template) and issubclass(template, BaseModel):
            from polyfactory.factories.pydantic_factory import ModelFactory

            class ExtractionTemplateFactory(ModelFactory[template]):  # type: ignore
                __use_examples__ = True  # prefer Field(examples=...) when present
                __use_defaults__ = True  # use field defaults instead of random values
                __check_model__ = (
                    True  # setting the value to avoid deprecation warnings
                )

            return ExtractionTemplateFactory.build().model_dump_json(indent=2)  # type: ignore
        else:
            raise ValueError(f"Unsupported template type: {type(template)}")

    @classmethod
    def get_default_options(cls) -> PipelineOptions:
        return VlmExtractionPipelineOptions()

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Define the extraction target as a pydantic BaseModel and pass either the class or an instance: class Contract(BaseModel): vendor: str; template=Contract
  2. If you have a dict/JSON, first parse it into a dynamically built BaseModel (e.g. via pydantic.create_model) or use the template form this docling version documents
  3. Check the branch chain above the raise in your docling version to see exactly which template types are accepted before 339 fires

Example fix

# before
template = {'vendor': 'str', 'total': 'float'}  # plain dict -> ValueError

# after
from pydantic import BaseModel
class Contract(BaseModel):
    vendor: str
    total: float
template = Contract
Defensive patterns

Strategy: type-guard

Validate before calling

from pydantic import BaseModel

def is_valid_template(t) -> bool:
    return (
        isinstance(t, BaseModel)
        or (isinstance(t, type) and issubclass(t, BaseModel))
    )

Type guard

from pydantic import BaseModel
from typing import Any

def is_extraction_template(x: Any) -> bool:
    return isinstance(x, BaseModel) or (isinstance(x, type) and issubclass(x, BaseModel))

Prevention

When it happens

Trigger: Calling execute()/extraction with template={'name': str} (raw dict as JSON-schema-ish), a dataclass, a TypedDict, or a plain JSON string not matching an accepted branch — i.e. anything that is not a pydantic BaseModel instance/class or one of the other recognized template forms in this version.

Common situations: Users porting JSON-schema dicts from other extraction frameworks; assuming any mapping works because the API names the parameter 'template'; version drift where accepted template types changed between docling releases.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/9dafedb7a454134a. Report an issue: GitHub.