Defining fields
A definition is plain JSON. The fields you declare are the shape of extraction.data; the model is asked for the printed text of each value and Deskew’s normaliser turns it into the declared type. A value that cannot be normalised becomes null with a flag, never a guess.
{ "title": "Hospital invoice", "description": "Itemised bill from a hospital to a patient or insurer.", "locale": "en-IN", "document": { "must_contain": [], "reject_if": [], "languages": [], "min_pages": 1, "max_pages": null }, "fields": [ ... ], "rules": [ ... ], "output": { "format": "json", "include_evidence": true, "include_nulls": true, "on_reject": "error", "on_rule_error": "flag", "money": "number" }}| Key | Rules |
|---|---|
title |
Display name, up to 120 characters. Defaults to the name |
description |
What the document is, and is not, up to 2,000 characters. Read by the model for both the document check and extraction. Write it |
locale |
xx or xx-YY, default en-IN. Decides day-first date parsing; see Locale and dates |
document |
The document check and page expectations; see below |
fields |
At least one field |
rules |
Up to 100; see Rules |
output |
Output options; see below |
Unknown keys anywhere in the definition are rejected (extractor_invalid, with the path of the offending key).
Field types
Section titled “Field types”Every field has a name and a type (default string).
type |
Output in data |
Normalisation |
|---|---|---|
string |
string | Trimmed, inner whitespace collapsed to one space; optional uppercase / lowercase; optional match regex |
text |
string | Kept verbatim: no trimming or collapsing. For remarks, findings, addresses. match is allowed |
number |
number | Thousands separators removed in any grouping (1,84,300.00, 1.234,56, 1 234,50), (12.50) and a Dr suffix read as negative, a Cr suffix as positive, stray text around the digits ignored (Rs. 2,500/- is 2500) |
money |
number, or {"amount", "currency"} with output.money: "object" |
Parsed like number. The currency is detected from a symbol or code in the printed text, else inherited from the document’s currency field; see Money and currency |
percent |
number | Parsed like number. A value printed without % whose magnitude is between 0 and 1 is multiplied by 100, so 0.18 and 18% both give 18 |
date |
YYYY-MM-DD |
ISO input first; otherwise any printed form (12th Nov 2026, Dt: 02-11-26, 03/04/2026). Ordinal suffixes and Dt. / dated prefixes are stripped. Ambiguous numeric dates follow the locale |
datetime |
ISO 8601, with offset when the page had one | Same parser with time |
currency |
ISO 4217 code (INR, USD, EUR) |
Symbols and codes resolved: ₹, Rs., $, US$, €, £, ¥, A$, C$ and the common three-letter codes. Anything else is unparseable |
boolean |
true / false |
yes/no, y/n, 1/0, x, ticks and checkbox glyphs, checked, on/off, none, si/oui, haan/nahi |
enum |
one of values |
Case-insensitive exact match first, then a loose match where the printed text contains the value or the value contains the text (Pharmacy charges becomes pharmacy). Anything else is null with not_in_enum |
object |
nested object | A container with its own fields; same rules inside |
group |
array of objects | Repeating rows (line items, transactions). min_items / max_items; each row gets its own evidence box |
A blank or missing value becomes the field’s default if one is set, otherwise null.
Field options
Section titled “Field options”| Option | Applies to | Meaning |
|---|---|---|
name |
all | ^[a-z][a-z0-9_]{0,63}$. Not one of the reserved names evidence, flags, status, document, extractor, version. Unique among siblings |
type |
all | One of the types above; default string |
required |
all | A required scalar that is not found, or a required group with no rows, adds an error flag missing_required and makes the run flagged. The value is still null; nothing is invented |
description |
all | Up to 1,000 characters. The single biggest accuracy lever; see Writing descriptions |
examples |
scalars | Up to 10 strings shown to the model as examples of the printed value |
aliases |
all | Up to 20 other labels the value appears under on the page, for example ["Bill No", "Receipt No"] |
default |
scalars | Used when the value is blank or not found. An enum default must be one of values. Containers cannot have a default |
normalise |
scalars | {"trim": true, "collapse_whitespace": true, "uppercase": false, "lowercase": false}. Only affects string. uppercase and lowercase cannot both be set |
match |
string, text |
A regular expression, up to 300 characters, searched in the normalised value. A miss keeps the value and adds a warning flag pattern_mismatch |
mask |
scalars | true for account numbers, identity numbers and other sensitive values. Rules still check the full value; the output, the evidence source and the CSV keep only the last four characters (XXXXXXXX9012; values of four characters or fewer are masked entirely). The evidence entry gains masked: true and never carries raw. In a test set the expected value may be written in full or masked: both compare equal to the masked output |
values |
enum |
1 to 100 allowed strings. Required for enum, forbidden elsewhere |
fields |
object, group |
The members; at least one. Forbidden on scalars |
min_items, max_items |
group |
Fewer rows than min_items adds an error flag too_few_items; more than max_items adds a warning flag too_many_items. Rows are never dropped |
Object versus group
Section titled “Object versus group”An object is one nested record: a hospital with name, gstin, address. A group is a list of records that repeat on the page: line_items, transactions, medications.
{ "name": "patient", "type": "object", "fields": [ { "name": "name", "type": "string", "required": true }, { "name": "date_of_birth", "type": "date" } ] },{ "name": "line_items", "type": "group", "required": true, "min_items": 1, "fields": [ { "name": "description", "type": "string", "required": true }, { "name": "amount", "type": "money", "required": true } ] }In data, objects are nested objects and groups are arrays. In rules and evidence, members are addressed with dots and brackets: patient.name, line_items[0].amount, line_items[].amount for all rows. A group row whose members are all null is dropped. Objects and groups can nest up to three levels deep.
Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Fields, counted at every level | 200 |
| Nesting depth | 3 (a group inside an object inside the top level) |
| Rules | 100 |
description per field |
1,000 characters; 2,000 for the extractor |
examples, aliases, values |
10, 20, 100 entries |
must_contain, reject_if |
20 entries each |
| Document text read for extraction | Documents are read in parts of up to 6 pages or 40,000 characters of Markdown, each with its own page images, and the parts are merged: the first non-null value wins for a scalar, repeating rows are concatenated in order, and a scalar that differs between parts adds a warning flag conflict naming both values. A run over several parts carries the warning long document: read in n parts and merged |
| Document text read for the document check | First 2 pages, 12,000 characters |
Extractor names (the name you create with, distinct from field names) are ^[a-z][a-z0-9_-]{0,63}$; the API lowercases what you send and rejects anything else with validation_error.
The document block
Section titled “The document block”"document": { "must_contain": ["itemised charges", "a total", "a hospital or clinic name"], "reject_if": ["the document is a prescription or clinical note"], "languages": ["en", "hi"], "min_pages": 1, "max_pages": 40}must_contain and reject_if are plain-language statements read by the model. When either list is non-empty, every run begins with a document check (1 credit) over the first two pages that returns matches, confidence, detected_type and reason. A mismatch is handled by output.on_reject: error (default) fails the request with 422 document_mismatch and charges nothing; result completes the job with extraction.status: "rejected", data: null, and only parsing plus the check charged. With both lists empty there is no check and document.matches is always true.
min_pages and max_pages add a warning flag (too_few_pages or too_many_pages) when the page count is outside the range; extraction still runs. languages is passed to the model as a hint and tells it to keep values in the original language.
Locale and dates
Section titled “Locale and dates”locale defaults to en-IN. Every locale except those ending in -US parses ambiguous numeric dates day first: 03/04/2026 is 3 April. With en-US it is 4 March. Unambiguous dates (2026-04-03, 12 Nov 2026, Nov 12, 2026) parse the same everywhere. Output is always YYYY-MM-DD for date and ISO 8601 for datetime.
Money and currency
Section titled “Money and currency”money fields output a plain number by default. Set output.money: "object" to get {"amount": 25500.0, "currency": "INR"} per field instead. Rules treat both forms as the number.
Currency is resolved per money field in this order:
- A symbol or code in the printed amount (
₹ 1,84,300.00,USD 1,200). - The document’s currency field: the first top-level field of type
currency, if the page states it. - Otherwise
nullin object mode.
When you declare a top-level currency field and the page never names the currency outright, Deskew infers it from the symbols seen on the money fields (the most common one wins) and records that in the evidence with reason: "inferred_from_amounts" and confidence 0.6. If no symbol is seen either, the field’s default applies. Declare {"name": "currency", "type": "currency", "default": "INR"} and the whole document has a currency you can rely on.
Output options
Section titled “Output options”output.* |
Values | Default | Effect |
|---|---|---|---|
format |
json, csv, both |
json |
csv and both add extraction.csv: one row per row of the first group (or one row total), with top-level scalars repeated on every row and group columns named group.member. Money objects are flattened to their amount |
include_evidence |
boolean | true |
Omit extraction.evidence entirely |
include_nulls |
boolean | true |
With false, fields that are null are left out of data instead of being present as null |
on_reject |
error, result |
error |
What a failed document check does; see above |
on_rule_error |
flag, reject |
flag |
flag: an error flag makes the run flagged and returns the data. reject: the run is rejected instead (data is still returned, document.reason is "rule errors") |
money |
number, object |
number |
Output form of money fields |
Writing good descriptions
Section titled “Writing good descriptions”The model reads your description, aliases and examples for every field, and the extractor’s description for the document as a whole. The quality of those sentences is the main accuracy lever you have.
- Say what the value is and what it is not: “The hospital’s own bill number. Not the claim or policy number.”
- Say where it usually appears: “Printed top right under the hospital name.”
- Name the labels the page uses in
aliasesrather than in prose, so the compiler can present them consistently. - Give two or three real
examplesfor identifiers with a format ("INV-2026-00912","B/4471/26"), and pin the format withmatch. - For
enum, describe how to classify when the page has no explicit category: “Classify from the description if the bill has no category column.” - Mark only fields that are always present as
required. A required field that is often absent produces a flag on every run and trains nobody to read the flags. - Prefer flat definitions. One group of line items is reliable; a group inside an object inside a group is slow and inconsistent.
- Keep money and currency apart: one
currencyfield at the top level,moneyfields everywhere else.