Extract Invoice Data with AI
Invoice number, vendor, dates, total, currency — extracted into clean fields with strict no-inference rules, ready for accounts payable.
Free text in, named fields out. The extraction prompt pattern that turns any unstructured text into consistent, parseable records.
Asking a model to "pull out the important information" produces different fields every run. Reliable extraction means naming the fields, describing what each one holds, and deciding two things up front: what happens when a value is missing, and how much inference is allowed. This resource loads a lead-form extraction — free text from a contact form into six named CRM fields, strict ambiguity, null for anything absent — the smallest complete example of the pattern that works on any text.
Name the fields, not the wish
Replace "important details" with lead_name, email, use_case — fields the consumer can rely on existing.
Decide the missing-data behavior
Null keeps keys stable for pipelines; empty or "unknown" keeps gaps visible for humans. Decide once, in the prompt.
Set the ambiguity policy
Strict for data you'll act on, best guess for data you'll review. The default drift between the two is where inconsistency comes from.
It sets that field to null and keeps the key. The MISSING DATA rule says "If a field is not found in the source, set it to null — do not omit the key," and "Never invent or guess a value." With the AMBIGUITY POLICY — extract only what's "explicitly stated" — the six-field shape stays stable every run. You run the prompt; downstream code consumes the JSON.
An explicit EXTRACTION RULE handles it: "team_size: Extract as a digit, not words," and the valid-extraction example shows "team_size": 3 unquoted. That keeps the field parseable for a spreadsheet or CRM rather than yielding "three." The prompt instructs the model on this; whether your assistant honors it perfectly is something you verify — the AI Output Validator is the separate step for that.
Extraction pulls named values that exist in the text into fields like use_case and email; classification assigns a label from a fixed set, which the notFor line calls out as a different job. Here the model reads free text and returns the six defined fields as one JSON object with no extra fields. If you need fixed-label tagging instead of value extraction, this preset isn't the pattern.
Invoice number, vendor, dates, total, currency — extracted into clean fields with strict no-inference rules, ready for accounts payable.
The most consequential setting in any extraction prompt: what the model does when the field isn't in the text. Four behaviors, and when each is right.
Parties, effective date, term, payment, termination notice, governing law — key terms into a contract register, with "unknown" marking every gap loudly.
Stop getting 'Sure, here is the JSON…' — the output-contract pattern that forces models to return only parseable JSON: schema, example, and a strict rule block.
Billing, Technical, Account, How-To, Feature Request — ticket triage with definitions that decide the borderline cases for the model.
The JSON won't parse and you can't see why. Deterministic cause-sniffing — trailing commas, single quotes, unclosed brackets — and the repair prompt that fixes it.
Build prompts that extract defined fields from unstructured text — emails, invoices, tickets, résumés.
The full path to an AI document processing system — define the use case, design the intake pipeline, extract fields from unstructured documents, classify and route them, pin the output contract, evaluate accuracy, then ship it monitored.
The full path to an AI content moderation system — define the policy and label taxonomy, extract signals from user content, classify it against policy, emit structured decisions, evaluate false positives and negatives, wire enforcement and review queues, review abuse risks, then ship.
The full path to an AI research assistant — define its scope, organize the source corpus, ground responses in references, extract key facts, synthesize findings, check groundedness, then validate it for use.
The full path to a retrieval system that returns grounded answers — understand the corpus, chunk and ground it, extract and classify the metadata, then evaluate that retrieval actually works.
The full path to pages that rank at scale, not penalty bait — map the intents, build the data set, structure it, template the page, then QA before publishing hundreds.
The full path to knowledge that's findable by people and AI — plan the taxonomy, structure it for search, write the articles, tag the metadata, make it retrievable, then ship it maintainable.
The full path to a pipeline that moves data without corrupting it — design the ingestion and transforms, extract and structure the sources, gate the quality, store it, then deliver and ship it monitored.
Turn messy text into structured data you can trust enough to feed another system — bound the source, extract the fields, force clean JSON, and validate before it flows downstream.