Extractors overview
An extractor describes one kind of document and exactly what you want out of it: the fields, their types and formats, the rules that must hold, and the sample documents that prove it works. You build it once, publish a version, and every call to POST /v1/extract with extractor=hospital-invoice returns that JSON. Extractors replace the bare JSON Schemas of /v1/schemas; see Migrating from schemas.
What an extractor adds over parsing
Section titled “What an extractor adds over parsing”Plain parsing turns a file into Markdown, tables and blocks. fields=true adds a generic key-value guess. An extractor adds five things on top:
| What it does | Where to read more | |
|---|---|---|
| Reject the wrong document | A cheap check before extraction decides whether the file is the kind the extractor describes. A prescription sent to an invoice extractor is a 422 document_mismatch, not a page of invented fields |
Defining fields |
| Normalise | Dates become YYYY-MM-DD, amounts become numbers, currencies become ISO codes, enums become one of your values. Deterministic code does this, not the model |
Defining fields |
| Validate | Rules such as “line items add up to the total” or “discharge is after admission” run after extraction. Failures become flags, never guesses | Rules |
| Evidence | Every value carries the page, a bounding box and the text it was read from, so a reviewer can verify it in seconds | Evidence |
| Test sets and versions | Sample documents with expected output. A test run tells you field accuracy before you publish; versions are immutable and can be pinned | Test sets and publishing |
Lifecycle
Section titled “Lifecycle”create ──► edit the draft ──► run the test set ──► publish ──► call it ▲ │ └──────────── edit again ◄───────────┘ (draft and published version coexist)- Create an extractor with a name and a definition. It starts as a draft.
- Edit the draft with
PUT /v1/extractors/{name}/draftas often as you like. Each edit is validated and compiled; problems come back with a path. - Test it: attach sample documents with expected JSON, start a test run, read the per-field diff.
- Publish. The draft becomes version 1, then 2, and so on. Publishing is refused while the latest test run has failures unless you force it.
- Call
POST /v1/extractwithextractor=<name>for the published version,<name>@3to pin, or<name>@draftto try unpublished changes.
End to end
Section titled “End to end”The running example in these pages is a hospital invoice. It has a document check, a few scalars, a repeating group of line items and three rules.
1. Create
Section titled “1. Create”curl https://api.deskew.dev/v1/extractors \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "hospital-invoice", "definition": { "title": "Hospital invoice", "description": "Itemised bill from a hospital to a patient or insurer.", "document": { "must_contain": ["itemised charges", "a total"], "reject_if": ["a prescription"] }, "fields": [ { "name": "invoice_number", "type": "string", "required": true, "match": "^[A-Z0-9/-]{3,24}$", "normalise": { "uppercase": true }, "aliases": ["Bill No", "Receipt No"] }, { "name": "currency", "type": "currency", "default": "INR" }, { "name": "admission_date", "type": "date", "required": true }, { "name": "discharge_date", "type": "date" }, { "name": "line_items", "type": "group", "required": true, "min_items": 1, "fields": [ { "name": "description", "type": "string", "required": true }, { "name": "category", "type": "enum", "values": ["room", "pharmacy", "other"] }, { "name": "amount", "type": "money", "required": true } ] }, { "name": "subtotal", "type": "money" }, { "name": "total", "type": "money", "required": true }, { "name": "paid", "type": "boolean" } ], "rules": [ { "id": "items_sum", "check": "abs(sum(line_items[].amount) - (subtotal ?? total)) <= 1", "message": "Line items do not add up" }, { "id": "dates", "check": "discharge_date == null || discharge_date >= admission_date" }, { "id": "recent", "check": "admission_date >= today() - days(365)", "severity": "warning" } ] } }'201 Created returns the extractor with published_version: null and is_draft: true.
2. Publish
Section titled “2. Publish”curl -X POST https://api.deskew.dev/v1/extractors/hospital-invoice/publish \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -H "Content-Type: application/json" \ -d '{"notes": "first version"}'{ "object": "extractor_version", "name": "hospital-invoice", "version": 1, "notes": "first version", "published_by": null, "published_at": "2026-12-04T10:02:11.418Z", "test_summary": null, "warnings": []}With no test documents attached there is nothing to gate on. Once you have a test set, publishing checks the latest run first; see the publish gate.
3. Extract
Section titled “3. Extract”curl https://api.deskew.dev/v1/extract \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -F "file=@bill.pdf" \ -F "extractor=hospital-invoice"# pip install deskew-sdkfrom deskew_sdk import Deskew, DocumentMismatch
client = Deskew() # reads DESKEW_API_KEYtry: result = client.extract("bill.pdf", extractor="hospital-invoice", wait=True)except DocumentMismatch as e: print("not an invoice:", e.detected_type)else: ext = result.extraction print(ext.status, ext.data["total"], [f.rule for f in ext.flags])// npm install @deskew/sdkimport { Deskew, DocumentMismatchError, isJob } from "@deskew/sdk";
const client = new Deskew(); // reads DESKEW_API_KEYtry { const result = await client.extract({ file: "bill.pdf", extractor: "hospital-invoice", wait: true }); if (isJob(result)) throw new Error("unreachable with wait: true"); const ext = result.extraction!; console.log(ext.status, ext.data?.total, ext.flags.map((f) => f.rule));} catch (e) { if (e instanceof DocumentMismatchError) console.log("not an invoice:", e.detectedType); else throw e;}"hospital-invoice@3" pins a version and "hospital-invoice@draft" tries the draft. The usual 200 / 202 split applies (the SDKs’ wait follows a queued job for you). Everything else in the result (markdown, tables, page_results, usage) is unchanged; the result gains one extraction object.
Just the data
Section titled “Just the data”Most integrations only want the fields. output=data strips the result down to extraction (data, flags and the document check, no evidence) and usage: no Markdown, text, blocks, tables or page results.
curl https://api.deskew.dev/v1/extract \ -H "Authorization: Bearer $DESKEW_API_KEY" \ -F "file=@bill.pdf" \ -F "extractor=hospital-invoice" \ -F "output=data"result = client.extract("bill.pdf", extractor="hospital-invoice", output="data", wait=True)row = result.extraction.data # {"invoice_number": "INV-2026/0912", "total": 29800.0, ...}if result.extraction.status == "flagged": review(row, result.extraction.flags)const result = await client.extract({ file: "bill.pdf", extractor: "hospital-invoice", output: "data", wait: true });if (!isJob(result)) { const row = result.extraction!.data; // { invoice_number: "INV-2026/0912", total: 29800, ... } if (result.extraction!.status === "flagged") review(row, result.extraction!.flags);}{ "id": "job_01M…", "status": "completed", "pages": 2, "extraction": { "extractor": "hospital-invoice", "version": 1, "status": "ok", "document": { "matches": true, "confidence": 0.95, "detected_type": "hospital invoice" }, "data": { "invoice_number": "INV-2026/0912", "currency": "INR", "total": 29800.0, "line_items": [ … ] }, "flags": [] }, "usage": { "pages": 2, "credits": 7, "premium_credits": 5, "engines": { "text-layer": 2 }, "extractor_credits": 5 }, "warnings": []}To drop null fields as well, set output.include_nulls: false in the definition. Evidence is only ever returned with output=json or markdown; the workspace and the playground always fetch it.
4. Read extraction
Section titled “4. Read extraction”{ "extraction": { "extractor": "hospital-invoice", "version": 1, "status": "ok", "document": { "matches": true, "confidence": 0.95, "detected_type": "hospital invoice", "reason": "itemised charges with a grand total" }, "data": { "invoice_number": "INV-2026/0912", "currency": "INR", "admission_date": "2026-11-02", "discharge_date": "2026-11-05", "line_items": [ { "description": "Deluxe room 3 nights", "category": "room", "amount": 25500.0 }, { "description": "Pharmacy", "category": "pharmacy", "amount": 4300.0 } ], "subtotal": null, "total": 29800.0, "paid": null }, "evidence": { "invoice_number": { "page": 1, "bbox": [0.1, 0.12, 0.9, 0.15], "source": "Bill No: INV-2026/0912", "confidence": 1.0 }, "admission_date": { "page": 1, "bbox": [0.1, 0.12, 0.9, 0.15], "source": "Admission: 02/11/2026", "confidence": 1.0 }, "line_items[0]": { "page": 1, "bbox": [0.1, 0.3, 0.9, 0.33], "source": null, "confidence": 1.0 }, "line_items[0].amount": { "page": 1, "bbox": [0.1, 0.3, 0.9, 0.33], "source": "25,500.00", "confidence": 1.0 }, "total": { "page": 2, "bbox": [0.5, 0.8, 0.95, 0.84], "source": "Grand Total Rs. 29,800.00", "confidence": 1.0 }, "subtotal": { "page": null, "bbox": null, "source": null, "confidence": 0.0, "reason": "not_found" }, "paid": { "page": null, "bbox": null, "source": null, "confidence": 0.0, "reason": "not_found" } }, "flags": [] }, "usage": { "pages": 2, "credits": 7, "premium_credits": 5, "engines": { "text-layer": 2 } }}| Field | Meaning |
|---|---|
extractor, version |
Which definition ran. version is null for @draft |
status |
ok, flagged or rejected; see below |
document |
The document check: matches, confidence, detected_type, reason. When the definition has no document.must_contain or reject_if, the check is skipped and this is {"matches": true, "confidence": null, "detected_type": null} |
data |
Your fields, normalised. Values not found are null (or omitted with output.include_nulls: false). null when the document was rejected |
evidence |
Page, box and source text per field path, plus one entry per group row. Omitted with output.include_evidence: false. See Evidence |
flags |
Failed rules and normalisation problems: {rule, severity, message, fields, detail?}. See Rules |
csv |
Flattened rows, only when output.format is csv or both |
The full field reference is in the Result object.
Status
Section titled “Status”status |
Meaning | What to do |
|---|---|---|
ok |
The document matched, every required field was found, no rule with severity error failed. Warnings may still be present in flags |
Use data as is |
flagged |
Extraction completed but at least one error-severity flag is present: a failed rule, a required field not found, a value that could not be normalised, an enum value outside the list |
Route to a human; the flag’s fields and detail say where to look |
rejected |
The document check said this is not the expected kind (output.on_reject: result), or an error flag fired with output.on_rule_error: reject. data is null in the first case |
Check document.detected_type and send the file to the right extractor |
With the default output.on_reject: error, a rejected document never produces a result at all: a synchronous request answers 422 document_mismatch with detected_type, confidence and reason in the error, and a background job fails with the same code in error. Nothing is charged for it.
The same status is on the job object and in the job.completed webhook payload, so you can route flagged runs to a review queue without fetching the result.
Credits
Section titled “Credits”| Step | Credits |
|---|---|
| Parsing | The normal per-page price (1 per PDF page, and so on; see Concepts) |
| Document check | 1 per run, only when the definition has document.must_contain or reject_if |
| Field extraction | 2 per page |
| Normalisation, rules, evidence | Free |
The two-page example above costs 2 + 1 + 4 = 7 credits. The job’s credits.estimated adds 2 per page and 1 for any extractor, before the document check is known to run. A document rejected with on_reject: error is not charged; one rejected with on_reject: result is charged for parsing and the document check only. Test runs create jobs in test mode and count against the test key’s daily page cap, not the live allowance. extraction on the job object reports the extractor’s share as credits.