Skip to content
Docs menu

Finance extraction

How Petawork Finance reads a document with your organisation's vision model. What is sent and what is not, the seven document types, statement files read with no model, the monthly document count and the daily AI limit, the failure states, and the MCP tool to read a document again.

View .md

Every original document sent to Finance documents is read on its own: Petawork Finance works out what kind of document it is, then reads its fields (the vendor, the number, the dates, the amounts, the lines) into a fixed schema with a confidence for each field. Then the checks after extraction run: a read that passes every check is confirmed, and anything else is needs_review for a person, with the reasons.

Reading uses your organisation's vision gear (the model you route vision requests to). Calls go through Petawork's own key for Finance, so they show in your usage and cost like any other request. Statement files (CSV, XLSX, MT940, CAMT.053, OFX) are parsed without a model.

Document types

Type Main fields
vendor_invoice vendor, tax ID, invoice number and date, due date, PO number, currency, subtotal, tax, total, bank details, lines
receipt merchant, date, payment method, currency, subtotal, tax, tip, total, lines
credit_note vendor, credit note number and date, the invoice it credits, currency, amounts, lines
bank_statement bank, account number, period, currency, opening and closing balance, transactions
settlement_statement provider, settlement ID and date, period, currency, gross, fees, refunds, net, transactions
folio hotel, guest, folio number, arrival and departure, room, currency, total, charges and payments
purchase_order buyer, vendor, PO number and date, delivery date, currency, amounts, lines

Amounts are kept in minor units of the document's currency (136250 is SGD 1,362.50; yen has no minor unit). Dates are YYYY-MM-DD. Each field has a confidence from 0 to 1 and, where the model gave one, where it is on the page (in PDF points for a text layer, in pixels for a picture). A confidence below 0.85 is marked low on the page.

A document the classifier cannot place is needs_review with the warning unknown_type, and nothing more is read.

What is sent to the model

  • A PDF with a text layer: its text with each line's position, up to 20 pages and 60,000 characters. The PDF itself is not sent.
  • A scanned PDF: up to 4 pages as PNG images, rendered at no more than 150 dpi.
  • A picture (PNG, JPEG, WebP, GIF, up to 6 MB): the picture. HEIC and TIFF are not sent; they are needs_review with the warning picture_type (picture_too_large for a bigger picture).
  • A statement file: nothing. It is parsed here.

Prompts are in English and Bahasa Indonesia, picked from the document's language. The instructions are fixed per type and language and never contain the document. The document is sent as a separate message between markers, as data: text in it that looks like an instruction is not followed, and a reply with a field the schema does not have is refused.

The reply

The reply must fit the type's schema exactly: every field present (null when absent), no extra fields, amounts as text, real calendar dates. A reply that does not fit is sent back once with the list of what was wrong. A second reply that does not fit ends the read as failed with the reason; nothing from it is kept.

Statuses and reasons

Document status Why
received Waiting to be read, or waiting for a limit (the row says which and until when)
extracting Being read
needs_review Read, and a check failed; check the fields. Also when there is no vision model, the type is unknown, or the file could not be sent
confirmed Read, and every check passed
failed schema_invalid (two replies that did not fit), model_error (the model answered with an error), pdf_invalid, pdf_encrypted, pdf_too_large, pdf_too_many_pages or pdf_render_timeout (a PDF that cannot be read), crashed (three attempts that never finished), not_extracted (the document became a duplicate or was rejected before it was read)

Every change is an event on the Finance audit trail: finance.document.extracting, finance.document.extracted, finance.document.extraction_failed and, for a read asked for again, finance.document.extraction_queued.

With no vision model configured, a document is needs_review with the warning no_vision_model and no call is made. Add a vision route in your gears and press Run again.

Limits

  • Documents a month: each document read by a model counts once in a UTC month against your plan's documents_month, before any model call. Reading the same document again that month does not count again; statement files and documents not sent to a model never count. Past the limit, a document waits as received until the month starts again, and finance_document_extract answers 429 plan_limit_reached.
  • A daily AI limit: Finance document reading on the AI spend page, $5 a UTC day by default, $0 to $500. Past it, a document waits as received until the next day. Owners and admins change it there.

Reading a document again

On Finance > Documents, Details on a row shows what was read: each field with its confidence, the warnings, the reason for a failure or a wait, and the number of lines. Run again reads it again as a new version (the earlier one is kept). The first read needs capture.upload; reading again needs capture.review (controller, AP clerk). Duplicates, rejected documents and confirmed documents are not read.

Reading runs in the background: right after an upload, and every minute (/api/cron/finance-extract). A picture or a statement file is read right after the upload. A PDF is read by the minute's job only, the one place the PDF engine runs, so it is read within about a minute of the upload. A read that stops halfway is picked up again after five and a half minutes, and is never written twice.

MCP tools

Tool What it does OAuth scope
finance_document_get Now includes extraction: the latest read with its fields, lines, warnings, status and cost finance:read
finance_document_list Each document carries a short extraction (status, type, reason) finance:read
finance_document_extract Read a document (again): id. Answers the waiting read if there is one finance:write

REST twin: POST /api/v1/finance/documents/{id}/extract.