{"record":{"id":"9dafedb7a454134a","repo":"docling-project/docling","slug":"unsupported-template-type-type-template","errorCode":null,"errorMessage":"Unsupported template type: {type(template)}","messagePattern":"Unsupported template type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"docling/pipeline/extraction_vlm_pipeline.py","lineNumber":226,"sourceCode":"        if isinstance(template, str):\n            return template\n        elif isinstance(template, dict):\n            return json.dumps(template, indent=2)\n        elif isinstance(template, BaseModel):\n            return template.model_dump_json(indent=2)\n        elif inspect.isclass(template) and issubclass(template, BaseModel):\n            from polyfactory.factories.pydantic_factory import ModelFactory\n\n            class ExtractionTemplateFactory(ModelFactory[template]):  # type: ignore\n                __use_examples__ = True  # prefer Field(examples=...) when present\n                __use_defaults__ = True  # use field defaults instead of random values\n                __check_model__ = (\n                    True  # setting the value to avoid deprecation warnings\n                )\n\n            return ExtractionTemplateFactory.build().model_dump_json(indent=2)  # type: ignore\n        else:\n            raise ValueError(f\"Unsupported template type: {type(template)}\")\n\n    @classmethod\n    def get_default_options(cls) -> PipelineOptions:\n        return VlmExtractionPipelineOptions()\n","sourceCodeStart":208,"sourceCodeEnd":231,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/pipeline/extraction_vlm_pipeline.py#L208-L231","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Define the extraction target as a pydantic BaseModel and pass either the class or an instance: class Contract(BaseModel): vendor: str; template=Contract","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","Check the branch chain above the raise in your docling version to see exactly which template types are accepted before 339 fires"],"exampleFix":"# before\ntemplate = {'vendor': 'str', 'total': 'float'}  # plain dict -> ValueError\n\n# after\nfrom pydantic import BaseModel\nclass Contract(BaseModel):\n    vendor: str\n    total: float\ntemplate = Contract","handlingStrategy":"type-guard","validationCode":"from pydantic import BaseModel\n\ndef is_valid_template(t) -> bool:\n    return (\n        isinstance(t, BaseModel)\n        or (isinstance(t, type) and issubclass(t, BaseModel))\n    )","typeGuard":"from pydantic import BaseModel\nfrom typing import Any\n\ndef is_extraction_template(x: Any) -> bool:\n    return isinstance(x, BaseModel) or (isinstance(x, type) and issubclass(x, BaseModel))","tryCatchPattern":null,"preventionTips":["Model extraction targets as pydantic BaseModel classes; avoid passing raw dicts or dataclasses","If you only have a JSON payload, convert it into a BaseModel instance first (Model.model_validate(payload))"],"tags":["extraction","vlm","template","pydantic","type-error"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}