Extraction Pipeline Prompting#
The VLM extraction pipeline supports two distinct prompting strategies, selected via the ExtractionPromptStyle enum (NUEXTRACT or GRANITE_VISION). The strategy is set in VlmExtractionPipelineOptions.extraction_prompt_style and flows through to TransformersExtractionModel, which dispatches to the appropriate input-builder at runtime .
NUEXTRACT: Schema-Injected Tokenizer Chat Template#
build_nuextract_inputs() constructs inputs by passing the JSON schema template directly into the tokenizer's chat template via processor.tokenizer.apply_chat_template(..., template=<schema>). Key details:
- The raw schema string is passed as the
templateargument — the schema is embedded inside the tokenizer's native chat template rather than being inserted as plain text in a user message. - Vision content is handled by
qwen-vl-utils(process_vision_info,fetch_image), which is a hard runtime dependency for this style. An explicitImportErroris raised if the package is absent . - At model init,
processor.tokenizer.padding_sideis set to"left"and aGenerationConfigis loaded from disk — both specific toNUEXTRACT. - When Python < 3.14, the model is compiled with
torch.compile()at startup . - The target model is
NuExtract-2.0-2B(HuggingFace:numind/NuExtract-2.0-2B).
GRANITE_VISION: Fixed Natural-Language Instruction Prompt#
build_granite_vision_inputs() constructs a standard HuggingFace chat conversation where each message contains:
- An
{"type": "image"}content item. - A
{"type": "text", "text": <extraction_prompt>}content item.
The extraction prompt is built by _build_extraction_prompt(template), which wraps the schema in a fixed natural-language instruction:
"Extract structured data from this document image. Return a JSON object matching this schema: … Return null for fields you cannot find. Return ONLY valid JSON, no other text."
processor.apply_chat_template() (top-level processor, not the tokenizer sub-object) is used to render the conversation — no qwen-vl-utils required. The target model is granite-vision-4.1-4b (HuggingFace: ibm-granite/granite-vision-4.1-4b, requires trust_remote_code=True).
Dispatch and Configuration#
NUEXTRACT | GRANITE_VISION | |
|---|---|---|
| Input builder | build_nuextract_inputs() | build_granite_vision_inputs() |
| Schema delivery | Via tokenizer chat template= arg | Embedded in natural-language instruction text |
| Vision processing | qwen-vl-utils | HF processor directly |
| Padding side | Left | Default |
GenerationConfig | Loaded from disk | Not used (falls back to use_cache=True) |
torch.compile() | Yes (Python < 3.14) | No (.eval() instead) |
| Default model | numind/NuExtract-2.0-2B | ibm-granite/granite-vision-4.1-4b |
The style must match the chosen model — mixing them produces incorrect output .
Key Files#
| File | Purpose |
|---|---|
docling/models/extraction/prompt_utils.py | Both input builder functions and _build_extraction_prompt() |
docling/datamodel/extraction_options.py | ExtractionPromptStyle enum |
docling/models/extraction/transformers_extraction_model.py | Runtime dispatch + model init differences |
docling/datamodel/vlm_model_specs.py | NU_EXTRACT_2B_TRANSFORMERS and GRANITE_VISION_4_1_TRANSFORMERS specs |
docling/datamodel/pipeline_options.py | VlmExtractionPipelineOptions.extraction_prompt_style |