Extract structured data from a document
The extraction prompt that gives you parseable JSON on the first try — including what to do when a field is missing.
When to use it
Pulling structured records out of a document when the output feeds code rather than a person.
What it prevents
Helpful inference. Without an explicit null rule, models fill missing fields with plausible guesses — and a plausible guess in a finance pipeline is worse than a blank, because nothing downstream can tell it apart from real data.
The prompt
Extract every invoice from the statement below.
### Output format
Return JSON and nothing else: [{"invoice": "string", "total": 0.00, "date": "YYYY-MM-DD"}]
### Requirements
- If a field is not present in the source, use null. Do not infer it.
- Preserve the invoice reference exactly as written, including any leading zeros.
### Example
[{"invoice": "INV-0104", "total": 82.50, "date": "2026-03-01"}]
### Statement
"""
INV-0104 01/03/2026 82.50
INV-0105 02/03/2026 19.00
"""Instant checks
States a concrete task
PassedAvoids vague language
PassedSpecifies an output format
PassedAvoids dangling references
PassedIncludes an example
PassedSeparates data from instructions
PassedAvoids over-aggressive phrasing
Passed
Why each part is there
Every section of that prompt exists because a specific failure happens without it. These are the checks it passes, and what each one is protecting you from:
- States a concrete task — why this matters
- Avoids vague language — why this matters
- Specifies an output format — why this matters
- Avoids dangling references — why this matters
- Includes an example — why this matters
- Separates data from instructions — why this matters
- Avoids over-aggressive phrasing — why this matters
How to adapt this one
Change the fields in the JSON shape and the example, and keep the null rule word for word: “if a field is not present, use null — do not infer it”. In an extraction that feeds code, a confident guess is more dangerous than a blank, because nothing downstream can tell an inferred value from a real one. The example row is not decoration; it pins the exact types you expect.
The mistake this prompt avoids
Omitting the null rule and getting helpful guesses. Ask a model to extract a field that is missing and it will supply a plausible value rather than admit the gap — a made-up date, a rounded total. In a pipeline, that plausible guess is the bug you find three weeks later in a reconciliation report. Forbid inference explicitly.
A variation
Extracting from scanned or OCR’d documents, where a field might be present but unreadable? Add a third state — “null for absent, the string “unclear” for present-but-illegible” — so a review queue can tell a genuinely missing field from one the OCR mangled. Collapsing both into null throws away the signal that tells you which pile to look in.
Check your version
Once you have adapted it, run it through the checker. The same nine checks that graded this page will grade yours, free and in your browser — paste it in, or build one from scratch by answering a few questions.