Document Extraction
Pull structured data out of a PDF or Word document (delivery note, invoice, contract, prescription) against a JSON schema you control. Useful for any workflow where you receive documents from external parties and want to land the data in your system without manual entry.
The workflow at a glance
┌──────────────┐ ┌────────────┐ ┌──────────┐
│ Source │ │ Your app │ │ xander │
│ (mailbox, │ │ │ │ │
│ upload, …) │ │ │ │ │
└──────┬───────┘ └─────┬──────┘ └─────┬────┘
│ document │ │
│─────────────────>│ │
│ │ (optional) │
│ │ 1. upload │
│ │────────────────>│
│ │ pdfId │
│ │<────────────────│
│ │ │
│ │ 2. extract with │
│ │ JSON schema │
│ │────────────────>│
│ │ structured │
│ │ result │
│ │<────────────────│
│ │ persist │
Step 1 (optional): Upload the document and get an ID
There are two ways to get the document to xander:
- Inline as base64 in the extraction request: simpler, one round trip, good for small documents (up to a few MB).
-
Upload first via
POST /pdfstore/upload(Word:POST /docstore/upload) and reference by ID in the extraction request: better for larger documents and when you run several extractions on the same document with different schemas (once for header data, once for line items).
The upload route:
curl -X POST "$XANDER_BASE_URL/pdfstore/upload" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-F "pdf=@delivery-note-12345.pdf;type=application/pdf"
The response is the document ID as text:
"3f9c2b7e-…"
Use that ID in step 2 instead of the inline base64 file. Uploaded documents are retained only as long as subsequent calls need them; the exact retention is defined in your contract.
Step 2: Extract fields against your JSON schema
POST /prompt/pdf-informationextraction-structured takes the document (inline or by
ID), a JSON schema for the response and optionally further parameters for the template. xander
returns a JSON object matching your schema.
Inline (small documents)
curl -X POST "$XANDER_BASE_URL/prompt/pdf-informationextraction-structured" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"pdfInput": {
"pdfFile": {
"base64Content": "<base64-encoded PDF bytes>",
"fileName": "delivery-note-12345.pdf"
}
},
"queryParameter": [
{ "name": "UserInformationRequest", "value": "Extract supplier, recipient, delivery date, and all line items with quantity and unit." }
],
"outputStructure": {
"jsonSchemaDefinition": "{\"type\":\"object\",\"properties\":{\"supplier\":{\"type\":\"string\"},\"recipient\":{\"type\":\"string\"},\"deliveryDate\":{\"type\":\"string\",\"format\":\"date\"},\"deliveryNoteNumber\":{\"type\":\"string\"},\"lineItems\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"articleNumber\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"quantity\":{\"type\":\"number\"},\"unit\":{\"type\":\"string\"}},\"required\":[\"description\",\"quantity\",\"unit\"],\"additionalProperties\":false}}},\"required\":[\"supplier\",\"recipient\",\"deliveryDate\",\"lineItems\"],\"additionalProperties\":false}"
},
"options": {
"promptIdentification": {
"projectId": "<your project>",
"promptname": "document-extraction/delivery_note"
},
"sessionMetadata": {
"useCaseName": "pdf-document-extraction",
"useCaseSessionId": "<your document id or correlation id>"
}
}
}'
Whether and under which name the template expects an instruction text as
queryParameter (here UserInformationRequest) is agreed during setup. The
name user_query is reserved.
By ID (larger documents)
"pdfInput": {
"pdfId": "3f9c2b7e-…"
}
Everything else stays the same, just swap pdfFile for pdfId.
Word instead of PDF
"docInput": {
"docFile": {
"base64Content": "<base64-encoded DOCX bytes>",
"fileName": "contract.docx",
"contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
Or "docInput": { "docId": "…" } after uploading via POST /docstore/upload.
xander converts the document to PDF; template and schema stay the same. Set exactly one source per
call, pdfInput or docInput.
Response
{
"result": {
"supplier": "ACME Industrial Supplies AG",
"recipient": "XYZ Manufacturing GmbH",
"deliveryDate": "2026-04-09",
"deliveryNoteNumber": "LS-2026-04-12345",
"lineItems": [
{
"articleNumber": "F7-A4-PLEAT",
"description": "Pleated air filter F7, 595x595x96",
"quantity": 12,
"unit": "pcs"
},
{
"articleNumber": "BELT-V-A38",
"description": "V-belt type A 38\"",
"quantity": 4,
"unit": "pcs"
}
]
},
"gptResult": { "plainResponse": "..." },
"metaInformation": { "retries": 0, "appliedModel": "...", "transparency": null }
}
Designing your JSON schema
The schema in outputStructure.jsonSchemaDefinition is the contract: xander returns
data in exactly that shape. A few rules for schemas that work well:
-
additionalProperties: falseon every object. Forces the model to stay within your fields instead of inventing extra keys. -
requiredonly where a field really must be present. Optional fields work fine; the model omits them when the document does not contain the information. -
descriptionon every property. The model sees the descriptions and they improve accuracy a lot. "Date the delivery was completed in ISO format" is much better than just"deliveryDate". -
Constrain enums and formats. If a field is always one of a known set, declare
it as
enum. If it is a date, declare"format": "date". The model uses these constraints. -
Reuse with
$defsfor repeated structures (for example define anAddressonce for supplier and recipient, reference it twice).
Multiple extractions on the same document
If you need different aspects of the same document (header data, then line items, then
signatures), upload it once via POST /pdfstore/upload and call
POST /prompt/pdf-informationextraction-structured several times with different
schemas and the same pdfId. Each extraction is a separate billed call, but you save
the upload.
Free text instead of a schema
If you do not need a fixed JSON shape but a summary or an answer to a question about the
document, use POST /prompt/pdf-informationextraction. Same inputs, same template,
the answer comes back as text in the result field.
Gotchas and tips
-
Schema as JSON string.
jsonSchemaDefinitionis a string containing the schema, not a nested object. Serialise your schema before putting it into the request. - Scanned vs digital. xander handles both, but text quality matters. A scan from a multifunction printer extracts worse than a digital PDF generated by an ERP. If quality is poor and the source is a scan, ask the sender for the digital original.
- Multilingual documents. German, French, Italian and English work without configuration. If the prompt template is written in the document's language, results get better.
- Do not extract everything in one shot. A schema with 50 fields produces worse results than three focused schemas of 15 fields each, especially on long documents. Decompose by section.
- Cost. Document extraction is one of the more expensive call types because the entire document goes to the model. For high volumes, a pre-filter pays off (for example only extract documents from known suppliers).
Next
For workflows that mix documents and voice notes (a technician dictates the repair report and photographs the filled-in warranty form), combine this recipe with Field Service Voice Intake: run them in parallel and merge the results in your application.