Extraction — turning unstructured text into structured fields — is one of the most valuable and testable uses of language models.
Define the Schema
List every field with its name, type, format and meaning:
invoice_number(string, exactly as printed);invoice_date(YYYY-MM-DD);total(number, including tax);currency(ISO code such as AUD);line_items(array of description, quantity, unit_price).
Handle Missing Data Explicitly
"Use null when a field isn't present. Never guess." This prevents invented values.
Show Examples
Include a sample document and its correct extraction, especially for tricky cases: multiple dates, totals with and without tax, handwritten corrections.
Use Structured Output Features
Where your API supports JSON schemas or tool calling, use them to guarantee valid structure.
Validate
- Parse and schema-check every result.
- Apply business rules: line items sum to the subtotal, dates are plausible.
- Route failures and low-confidence results to people.
Long or Multi-Page Documents
Extract page by page or section by section, then combine, keeping references to where each value came from.
Measure Accuracy
Evaluate field-level accuracy against a hand-checked sample of real documents, and track it over time.