Skip to content

Prompting for Data Extraction

Pulling structured fields from invoices, emails and documents reliably with clear schemas, examples and validation.

Editorial team 1 min read

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.

More in Prompting

All Prompting guides →
Prompting Guide · 1 min

Anatomy of an Effective Prompt

The parts of a prompt that reliably produce good results, with a template you can adapt for almost any task.

Prompting 1 min read 1 Nov 2025

Prompting Guide · 2 min

Giving Models Context

Why most weak outputs come from missing context, and what background information to include in a prompt.

Prompting 2 min read 31 Oct 2025

Prompting Guide · 1 min

Role Prompting: When It Helps and When It Doesn't

Telling a model to act as an expert or a persona can shape tone and focus — but it isn't a substitute for clear instructions.

Prompting 1 min read 30 Oct 2025