Extract fields from documents into a table
Inputs
documents(required): The documents as text, each separated clearly (for example "--- Document 2 ---"), with an ID or file name for each if you have one.fields(required): The fields to extract, one per line, with the format you want and any rule for choosing between candidates (for example "invoice_date - date YYYY-MM-DD; use the issue date, not the due date").
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
- Read the field list and fix each field's type and format. If a field is ambiguous (for example "amount" on an invoice with net, tax and gross), use the rule given; if there is none, pick the most likely meaning, state it once in Issues to review, and apply it consistently.
- For each document, produce one row (or one row per line item, if the fields are line-level), starting with a document ID: the one given, or Doc 1, Doc 2 in order.
- For each field:
- Find the value stated in the document. Copy it exactly, then normalise to the requested format only when the conversion is certain: dates to ISO 8601 (YYYY-MM-DD) when the day and month order is clear from the document's language, country or another date in it; amounts as plain numbers with the currency in its own field and the decimal separator interpreted from context (1.234,56 versus 1,234.56).
- Leave the cell blank when the value is not in the document. Do not compute, look up or infer it, even when it seems obvious, unless the field rules ask for a derived value; then mark it derived.
- When the document contains several candidates (two dates, a revised amount), apply the field rule, or take the most authoritative one (the total line over a figure in the body text), and note the alternative.
- Add a confidence for each row (high, medium or low) and a short note naming any field that was hard to read, conflicting or normalised from an ambiguous form.
- Check what can be checked within each document: line items adding up to the subtotal, net plus tax equalling gross, IDs matching the expected pattern. Report mismatches; do not correct them.
CSV
The same table as CSV in a fenced code block, ready to paste into a spreadsheet.
Issues to review
Numbered: document, field, what is uncertain or inconsistent, the value used and the alternative. Write "None" if there are none.