Dharma Field Extractor: Turning Documents into Structured JSON
Dharma Field Extractor: Turning Documents into Structured JSON Dharma AI has introduced a field extraction model designed to convert document images into structured JSON. The 2...
By AI Engineering Team
Dharma Field Extractor: Turning Documents into Structured JSON
Dharma-AI has introduced a field-extraction model designed to convert document images into structured JSON. The 2-billion-parameter model supports both open-ended extraction and schema-directed requests, returning typed fields, nested structures, table rows, and null values for requested data that is absent.
From OCR Text to Usable Fields
Dharma-AI previously released DharmaOCR-LITE, an OCR model for documents such as contracts, court filings, invoices, identification documents, and forms. Its accompanying paper evaluated how a task-specialized model could perform against general-purpose frontier APIs.
OCR is useful when the goal is to preserve and read an entire page. It returns the text and layout, which suits tasks such as digitizing a manuscript or reviewing a contract from beginning to end.
Many document-processing workflows require something narrower: selected values in a format that another system can consume. An invoice may require every line item as a list. A medical requisition may need the patient name, examination type, and date. An identification document may need values mapped to employee-record columns.
Raw OCR returns all printed content, but it does not necessarily identify which string represents an examination type, date, total, or other business field. Additional code is still needed to map the extracted text into a database schema.
General-purpose LLMs can perform this mapping with carefully designed prompts. However, API pricing and latency can become significant when a well-defined extraction task must run at high volume.
The Field Extractor addresses this use case by accepting a document image and either a request to identify available fields or an explicit schema. It returns structured JSON, with typed values and nested structures where appropriate. An invoice can include ordered line items with quantities and values alongside its totals. An identification document can use the field names already expected by a downstream system. The same checkpoint supports these document types without per-type fine-tuning.
Two Extraction Modes
The model supports two request styles:
- Open: No schema is supplied. The model uses document context and layout to identify structured fields, such as labels followed by values or tables with header rows, and returns the fields it finds as key-value pairs.
- Schema-directed: The requester specifies the exact output shape and the type of each field, using strings, numbers, or booleans. The requested keys are preserved in the result. Tables are returned row by row and column by column. If a requested field is not present, the model returns
nullrather than generating a value.
Open extraction is intended for documents whose contents are not known in advance. Schema-directed extraction is suited to workflows where the output must match an existing system or database structure.
In both modes, the result is JSON. Values use the requested types, missing values are represented by null, and schema-directed responses contain the specified keys without additional fields.
Training and Data
The base model is DharmaOCR-LITE v1.1, a 2-billion-parameter version optimized from the model described in the OCR paper. It was specialized for OCR through supervised fine-tuning and Direct Preference Optimization (DPO). Dharma-AI trained a LoRA adapter on 43,384 examples covering both extraction modes.
The training data was divided into three streams:
- English multi-domain data: Publicly collected documents covering a range of document types.
- Brazilian domain data: Internally sourced real Brazilian documents written in Portuguese.
- Multilingual data: A smaller collection covering additional European and Asian languages.
All three streams were annotated at the field level. The collection included receipts, commercial invoices, forms, bank statements, identification documents, and synthetic documents, rather than focusing on a single document category.
Benchmark Design and Results
The benchmark included 546 documents and three request scenarios, for 1,638 total cases:
- Extract every field without a schema.
- Use a partial schema containing only fields that exist in the document.
- Use a schema that also includes deliberately nonexistent fields.
The score combines field-level F1, matched by path and table position, with Levenshtein similarity for matched values and the proportion of outputs that are valid JSON.
Dharma-AI compared the model with four general-purpose frontier configurations. The quality difference ranged from 1.8 points against Claude Opus 5, the closest result, to 9.3 points against GPT-5.6 Luna, the largest difference.
The cost comparison ranged from approximately 6 times lower than GPT-5.6 Luna to approximately 147 times lower than GPT-5.6 Sol. Frontier-model estimates used measured average input and output tokens per page, including reasoning tokens, and each provider's published list pricing. All frontier models used low reasoning settings. Claude Opus 5 used adaptive effort, which can skip reasoning on simpler pages while remaining at the low level.
The Field Extractor was self-hosted rather than billed per token. Its reported cost represents GPU time on a single L40S priced at $2.24 per hour. Actual self-hosted costs depend on hardware, processing volume, and required latency.
Generalization Tests
SROIE and FUNSD were included in the benchmark but were not used for training.
For a SROIE receipt, the model was asked to extract all 18 printed fields. The result correctly captured the multiline, unlabeled billing address as one field, returned null for the blank salesperson and reference fields, and matched the receipt's numerical values to the cent.
For a FUNSD photocopying variance form, the task included twelve boolean fields and one nested group containing five sub-options. The model marked only the checked box, corresponding to a poor-quality original with a handwritten “faded” note, as true, and marked the other eleven options as false. It also correctly read the handwritten Bates ID and returned null for the two blank fields.
Quality and Operating Cost
On the reported benchmark, the 2-billion-parameter model scored 0.834. This exceeded the tested frontier configurations, including Claude Opus 5 at 0.816 and GPT-5.6 Luna at 0.741. It also ran on a single L40S at a lower reported extraction cost than every API in the comparison.
Dharma-AI described this result as part of a broader pattern. Its earlier OCR paper evaluated DharmaOCR-LITE, a 3-billion-parameter model, against commercial frontier APIs on Brazilian Portuguese. Three months later, newer models were available, but the reported gap remained. The Field Extractor extends the same evaluation approach to document field extraction with a 2-billion-parameter model.
The benchmark's reported cost difference ranged from 6 to 147 times lower than the compared frontier configurations. The results support the use of smaller, task-specialized models for bounded extraction workflows, particularly when structured output and deployment cost are important considerations.
Sources
- BID, Brazilian Identity Document Dataset. Soares, Neves Jr., Bezerra (2020), “BID Dataset: a challenge dataset for document processing tasks,” Anais Estendidos XXXIII SIBGRAPI.
- CORD. Park et al., NAVER CLOVA (2019).
- DocVQA. Mathew et al., WACV 2021, based on ICDAR 2019.
- WildReceipt. Sun et al., IJCAI 2021.
- SROIE, ICDAR 2019, held out from training and used for evaluation only.
- FUNSD. Jaume et al., held out from training and used for evaluation only.
- Zenodo Invoices (PT). Cruz and Castelli, NOVA IMS (2022).
line_items. Sagarjha456, Hugging Face.- Katanaml Invoices (Donut). Kozłowski and Weichbroth (2021), Mendeley Data.
- HumynLabs Brazilian Bills and Invoices.
- Tech4Humans BR-Doc Extraction.
- Cardoso, Gabriel Pimenta de Freitas, et al. “DharmaOCR: Specialized Small Language Models for Structured OCR that outperform Open-Source and Commercial Baselines.” arXiv preprint arXiv:2604.14314 (2026).