﻿# Donut document parsing: task tokens are part of the output schema

Match Donut task prompts, checkpoint-specific decoder tokens, and structured postprocessing while distinguishing valid JSON from correct extracted fields.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-donut-task-token-structured-output/
Language: en

## Treat the task prefix as a trained interface

Donut reads document images through an encoder-decoder architecture rather than requiring an external OCR transcript as its primary input. The [original paper](https://arxiv.org/abs/2111.15664) presents this OCR-free approach. Its decoder is still trained for particular output tasks. A receipt-parsing checkpoint and a document-question-answering checkpoint do not become interchangeable simply because both accept a document image. The task prefix tells the decoder which trained serialization or response pattern is expected.

## Match the checkpoint and its prompt

The [Transformers Donut examples](https://huggingface.co/docs/transformers/model_doc/donut) show different prefixes for document classification, question answering, and receipt parsing. The naver-clova-ix/donut-base-finetuned-cord-v2 example uses its own task token. Preserve the checkpoint's tokenizer and registered special tokens when preparing decoder input. An ordinary natural-language instruction is not automatically equivalent to the trained task prefix, and deleting unfamiliar-looking tokens can remove the structural boundary that the model uses to begin its answer.

## Separate generation from structural decoding

Donut's serialized output can be transformed with token2json in the documented integration. That conversion interprets structural tokens; it does not prove that the document actually contains each generated field value. Distinguish a generation that terminates correctly, a sequence that parses, and an extraction whose content matches visible evidence. Keep malformed or truncated outputs observable instead of silently filling absent totals or names with default values that make the JSON appear complete.

## Test fields in document context

Consider a receipt with a subtotal, taxes, and a final total printed in nearby rows. A plausible structured result can assign the subtotal to the total field without any syntax error. Use field-specific references and inspect the source region for disagreements. The [official Donut repository](https://github.com/clovaai/donut) provides the model and task training context; adaptation to a new receipt format should preserve the chosen serialization and be evaluated on held-out documents, not only on familiar layouts.

## Preserve a stable downstream contract

Record the task prefix, checkpoint revision, decoding settings, and structural parser together. If an application changes field names or nesting, make that mapping explicit after extraction rather than pretending the model was trained for the new schema. Existing articles on [receipt field normalization](/journal/data-guide-sroie-receipt-field-normalization/) and [document provenance](/journal/document-markdown-json-provenance/) explain adjacent requirements. Donut's distinctive contract links task token, generated serialization, parser, and evidence-backed field meaning into one reproducible extraction path.
