Skip to content

Test sets and publishing

An extractor carries its own test set: sample documents, each with the JSON you expect back. A test run extracts them all with the draft (or a version) and reports field accuracy and a per-field diff. Publishing turns the draft into an immutable version and is refused while the test set fails.

Attach a document either by uploading it or by copying the original file of an existing job.

Terminal window
# Upload with the expected output
curl https://api.deskew.dev/v1/extractors/hospital-invoice/test-documents \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-F "file=@samples/bill-0912.pdf" \
-F 'expected={"invoice_number":"INV-2026/0912","total":29800,"line_items":[{"amount":25500},{"amount":4300}]}'
# From a job you already ran (expected is pre-filled from that job's extraction)
curl https://api.deskew.dev/v1/extractors/hospital-invoice/test-documents \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-F "job_id=job_01JE4K9QW2M3N4P5Q6R7S8T9V0"
{
"object": "extractor_test_document",
"id": "etd_01JE4KJ2M3N4P5Q6R7S8T9V0W1",
"file_name": "bill-0912.pdf",
"file_type": "pdf",
"file_size": 184233,
"pages": null,
"has_expected": true,
"expected": { "invoice_number": "INV-2026/0912", "total": 29800, "line_items": [{ "amount": 25500 }, { "amount": 4300 }] },
"source": "upload",
"job_id": null,
"created_at": "2026-12-04T10:14:52.001Z"
}
  • expected is optional. A document without it is still run (it proves the extractor does not reject or crash on it) but is not scored. Set or change it later with PUT .../test-documents/{id} and a body of {"expected": {...}}; null clears it.
  • expected only needs the fields you care about. Paths you leave out are not scored. A field you expect to be absent is written as null.
  • With job_id, the job’s original file is copied into the test set, so it survives the job’s 24-hour retention. If the job used this extractor and completed, expected is pre-filled with what it produced, for you to correct. A job whose file has already expired answers 404 job_file_expired.
  • Files are limited to 25 MB (413 payload_too_large) and go through the same type detection and hostile-input checks as POST /v1/extract.
  • Test documents are stored outside job retention and are kept until you delete them (DELETE .../test-documents/{id}, 204) or the extractor is archived.
Plan Extractors per project Test documents per extractor
Early access (everyone today) 10 50
Free (when plans launch) 2 10
Pro 10 50
Scale, Enterprise Unlimited Unlimited

Exceeding either answers 403 plan_limit with limit in the error. Archived extractors do not count.

Terminal window
curl -X POST https://api.deskew.dev/v1/extractors/hospital-invoice/test-runs \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"target": "draft"}'
Body field Default Meaning
target draft draft runs the current draft definition; version runs a published version
version published version With target: "version", which one
document_ids all Restrict the run to some test documents

The response is 202 with the run in status: "running". Every test document becomes one ordinary job in test mode (extractor=hospital-invoice@draft, mode=async), so test runs never touch the live allowance, count against the test key’s 50 pages a day, and show up in the dashboard’s test-mode job list and in GET /v1/extractors/{name}/runs. Poll the run until status is completed:

Terminal window
curl https://api.deskew.dev/v1/extractors/hospital-invoice/test-runs/etr_01JE4KM6N7P8Q9R0S1T2U3V4W5 \
-H "Authorization: Bearer $DESKEW_API_KEY"
{
"object": "extractor_test_run",
"id": "etr_01JE4KM6N7P8Q9R0S1T2U3V4W5",
"target": "draft",
"version": null,
"status": "completed",
"documents": 2,
"summary": {
"documents": 2,
"passed": 1,
"failed": 1,
"failed_jobs": 0,
"scored_documents": 2,
"field_accuracy": 0.75,
"fields_matched": 3,
"fields_total": 4,
"flags": 1,
"worst_fields": [{ "field": "total", "misses": 1 }],
"credits": 14,
"complete": true
},
"started_at": "2026-12-04T10:20:03.117Z",
"finished_at": "2026-12-04T10:20:41.902Z",
"results": [
{
"document_id": "etd_01JE4KJ2M3N4P5Q6R7S8T9V0W1",
"file_name": "bill-0912.pdf",
"job_id": "job_01JE4KM7A1B2C3D4E5F6G7H8J9",
"job_status": "completed",
"extraction_status": "ok",
"flags": [],
"actual": { "invoice_number": "INV-2026/0912", "total": 29800.0, "...": "..." },
"comparison": {
"scored": true,
"passed": true,
"matched": 2,
"total": 2,
"fields": {
"invoice_number": { "status": "match", "expected": "INV-2026/0912", "actual": "INV-2026/0912" },
"total": { "status": "match", "expected": 29800, "actual": 29800.0 },
"currency": { "status": "extra", "expected": null, "actual": "INR" }
}
},
"passed": true
},
{
"document_id": "etd_01JE4KJ9X0Y1Z2A3B4C5D6E7F8",
"file_name": "bill-0913.pdf",
"job_id": "job_01JE4KM7K1L2M3N4P5Q6R7S8T9",
"job_status": "completed",
"extraction_status": "flagged",
"flags": [{ "rule": "items_sum", "severity": "error", "message": "Line items do not add up", "fields": ["line_items[].amount", "subtotal", "total"], "detail": "line_items[].amount=[2 items], subtotal=None, total=31000.0" }],
"actual": { "invoice_number": "INV-2026/0913", "total": 31000.0, "...": "..." },
"comparison": {
"scored": true,
"passed": false,
"matched": 1,
"total": 2,
"fields": {
"invoice_number": { "status": "match", "expected": "INV-2026/0913", "actual": "INV-2026/0913" },
"total": { "status": "mismatch", "expected": 29800, "actual": 31000.0 }
}
},
"passed": false
}
]
}
Field Meaning
documents Test documents in the run
passed, failed Documents that passed and did not. A document passes when every expected field matches and the extraction was not rejected. A document without expected passes when its job completed with an extraction
failed_jobs Documents whose job failed (for example document_mismatch with on_reject: error); these count as failed
scored_documents Documents that had expected
field_accuracy fields_matched / fields_total over scored documents, 4 decimals; null with nothing scored
fields_matched, fields_total Expected field paths that matched, and in total
flags Flags across all documents, errors and warnings
worst_fields Up to 10 field paths with the most missing or mismatch results, row indices collapsed to []
credits Test-mode credits the run consumed
complete false while jobs are still running; the summary is partial

comparison.fields is keyed by flattened path (line_items[1].amount). Money objects compare by their amount.

status Meaning
match Equal after normalising: numbers within 0.011, strings compared trimmed, whitespace-collapsed and case-insensitively, booleans exactly, lists exactly. An expected null matches an absent or null field
mismatch A value was returned but it differs
missing Expected a value, got null or nothing
extra The extractor returned a field that expected does not mention. Reported, never counted as a failure

The listing GET .../test-runs (newest first, limit 1 to 50) returns runs without results; fetch one run for the diff.

Terminal window
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": "tightened invoice_number pattern"}'

Publishing looks at the most recent test run of the draft:

Situation Outcome
The run completed with no failures 201; the version records test_summary and the run id
The run completed with failures 409 extractor_tests_failing with the summary and test_run_id in the error. Fix the definition and run again, or send "force": true to publish anyway (the version still records the summary)
The draft was edited after the run started 201 with the warning The test set has not been run since the draft was last edited. and no test_summary
The run has not finished 201 with the warning The latest test run has not finished.
There are test documents but no run ever 201 with the warning The test set has never been run on this draft.
No test documents 201, no warnings

Publishing also re-validates the draft; a draft that fails validation answers 422 extractor_invalid. notes (up to 2,000 characters) is kept on the version.

{
"object": "extractor_version",
"name": "hospital-invoice",
"version": 2,
"notes": "tightened invoice_number pattern",
"published_by": null,
"published_at": "2026-12-04T11:02:40.558Z",
"test_summary": { "documents": 2, "passed": 2, "failed": 0, "field_accuracy": 1.0, "...": "..." },
"warnings": []
}

Versions are numbered from 1 and never change once published. The draft is separate: after publishing, the draft is identical to the new version until you edit it again, and draft_ahead on the extractor object tells you whether unpublished edits exist.

extractor= Resolves to
hospital-invoice The current published version. Changes when you publish
hospital-invoice@3 Version 3, forever. Pin in production integrations whose downstream code depends on the shape
hospital-invoice@draft The draft, recompiled on every change. For trying edits on real documents before publishing. Results show "version": null

An extractor with no published version answers 409 extractor_unpublished when called by bare name; @draft works. An unknown version is 404 extractor_version_not_found. The reference is checked when the request is accepted, so these are synchronous errors, never failed jobs.

GET /v1/extractors/{name}/versions lists versions newest first with notes, published_at and test_summary; GET .../versions/{n} includes the full definition.

Terminal window
curl -X POST https://api.deskew.dev/v1/extractors/hospital-invoice/rollback \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"version": 1}'

Rollback publishes a new version whose definition is a copy of the old one, with notes rolled back to v1, and resets the draft to it. Nothing is rewritten, so the history stays honest: after rolling back from 2 to 1 you have versions 1, 2 and 3, with 3 identical to 1 and current. Callers pinned to @2 are unaffected.

DELETE /v1/extractors/{name} archives the extractor: it leaves the default listing, can no longer be called (404 extractor_not_found), and no longer counts against the plan limit. Its versions and runs remain readable with GET /v1/extractors/{name} and ?include_archived=true on the list. Posting the same name to the legacy POST /v1/schemas un-archives it; POST /v1/extractors with that name answers 409 extractor_exists.

GET /v1/extractors/{name}/runs lists the jobs that used the extractor in the key’s mode (test or live), newest first, each with its extraction summary, and a counts object by status:

{
"object": "list",
"data": [ { "id": "job_01JE4K9QW2M3N4P5Q6R7S8T9V0", "object": "job", "status": "completed", "extraction": { "extractor": "hospital-invoice", "version": 1, "status": "ok", "flags": 0 }, "...": "..." } ],
"has_more": false,
"counts": { "ok": 41, "flagged": 6, "rejected": 2 }
}

Filter with status=ok|flagged|rejected, page with limit (1 to 100, default 20) and starting_after=<job id>. A document rejected with on_reject: error is recorded as a rejected run whose job status is failed. Requires jobs:read.