Document Extraction with LLMs: Prompt Templates and a Review Workflow for Invoices, Forms, and Contracts
document AILLM document extractionprompt templatesOCRinvoice automationcontract analysis

Document Extraction with LLMs: Prompt Templates and a Review Workflow for Invoices, Forms, and Contracts

DDatawizard Editorial Team
2026-12-03
7 min read

Build reliable LLM document extraction with practical prompts, schemas, validation rules, and human review workflows for invoices, forms, and contracts.

Reliable LLM document extraction is less about asking a model to “read a PDF” and more about designing a controlled workflow. This guide provides reusable prompt templates for invoices, application forms, and contracts, plus a review checklist for OCR quality, missing values, validation, confidence handling, and human approval.

Overview

LLM document extraction converts unstructured or semi-structured files into structured data such as JSON. It can support accounts payable, customer onboarding, recruiting, procurement, legal operations, and internal search. However, extraction should be treated as a data-processing pipeline rather than a single prompt.

A dependable workflow usually has these stages:

  1. Classify the document: identify whether the file is an invoice, application form, contract, or an unsupported document type.
  2. Check input quality: determine whether the document contains selectable text, readable scans, tables, handwriting, rotated pages, or missing pages.
  3. Extract defined fields: request a strict schema and clear rules for absent, ambiguous, or conflicting values.
  4. Validate the result: apply deterministic checks for dates, totals, identifiers, required fields, and allowed values.
  5. Review exceptions: route low-confidence or failed records to a person instead of silently accepting them.
  6. Store provenance: retain the source document, page references, extracted values, validation results, and review decisions.

Before writing a prompt, create a field-definition worksheet. For each field, record its name, data type, required status, accepted format, source location, normalization rule, and review condition. For example, an invoice field named invoice_total might require a decimal number, use the total shown on the invoice, exclude currency symbols, and require review if tax and subtotal calculations do not reconcile.

Keep extraction separate from interpretation where possible. A first pass can identify and normalize facts. A later step can classify risk, summarize terms, or compare the extracted data with a business rule. This prompt chaining approach makes failures easier to test and explain.

Checklist by scenario

Invoices

Invoices often contain repeated labels, line-item tables, tax information, discounts, purchase-order references, and several possible totals. Define which value takes precedence when more than one total appears.

  • Identify the supplier name, supplier address, invoice number, invoice date, due date, currency, purchase-order number, line items, subtotal, tax, discount, shipping, and invoice total.
  • Represent line items as an array with description, quantity, unit price, tax rate if shown, and line total.
  • Return null when a field is not present; do not infer a missing value from context.
  • Preserve the document’s currency and date meaning, then normalize them only according to a documented rule.
  • Flag arithmetic mismatches, duplicate invoice numbers, unclear supplier identity, and unreadable table rows.

Reusable invoice prompt template:

Extract the invoice into the JSON schema below. Use only information visible in the document. Do not guess or calculate missing values. If a field is absent or unreadable, return null and add a review flag. Include a page reference for each top-level field when available. Preserve line items as separate objects.

Schema:
{
  "document_type": "invoice",
  "supplier_name": "string|null",
  "invoice_number": "string|null",
  "invoice_date": "YYYY-MM-DD|null",
  "due_date": "YYYY-MM-DD|null",
  "currency": "string|null",
  "purchase_order_number": "string|null",
  "line_items": [],
  "subtotal": "number|null",
  "tax": "number|null",
  "discount": "number|null",
  "total": "number|null",
  "review_flags": []
}

Application forms

Forms are usually easier to model when the required fields are known in advance, but they still create problems when applicants use alternate formats, leave sections blank, or provide multiple answers.

  • List every expected field, including optional fields, rather than asking for “all relevant information.”
  • Distinguish between blank, not applicable, illegible, and conflicting responses.
  • Preserve the applicant’s answer separately from any normalized value.
  • Use controlled values for fields such as employment status, country, department, or eligibility category.
  • Flag signatures, consent checkboxes, attachments, and required sections that cannot be verified.

Reusable application-form prompt template:

Extract the applicant’s responses using the schema. Do not infer answers from demographic clues, surrounding text, or typical form behavior. Return the exact response in raw_value, and place a standardized version in normalized_value only when the mapping is unambiguous. Mark blank, illegible, conflicting, and not-applicable values distinctly.

Contracts

Contract extraction requires a narrower scope than general legal analysis. Start with factual metadata and explicitly named clauses. Avoid asking the model to make an unqualified legal judgment.

  • Extract parties, effective date, term, renewal language, governing law, payment terms, notice periods, termination provisions, confidentiality references, and liability language when those fields are in scope.
  • Return a short quote or page reference for material clauses so a reviewer can locate the source.
  • Distinguish “not found” from “found but ambiguous.”
  • Preserve clause wording before producing a normalized interpretation.
  • Route unusual amendments, handwritten changes, exhibits, and conflicting definitions for human review.

Reusable contract prompt template:

Review this document only for the fields listed below. Extract factual text and cite the page or section where possible. Do not provide legal advice or resolve ambiguity. If two clauses conflict, return both passages and add a conflict flag. If a field is not present, return null rather than inferring it.

What to double-check

Input and OCR quality

Confirm whether the model receives native text, OCR output, images, or a combination. Test rotated pages, low contrast, multi-column layouts, stamps, tables, footnotes, and documents with mixed languages. A confident extraction from defective OCR is still defective data. If OCR quality is poor, stop or route the document for reprocessing instead of treating the output as complete.

Schema and missing-value behavior

Use explicit types and permitted values. Decide whether dates must be ISO-formatted, whether numbers may contain decimals, and how currencies are represented. Require null or a defined status for missing fields. Never make “best effort” guessing the default for financial, identity, or contractual data.

Confidence and evidence

A model-generated confidence score is not proof of correctness. Combine it with evidence such as a page number, source quote, OCR quality signal, validation result, and document classification. Establish review thresholds using a labeled test set that represents real document variation.

Validation rules

Apply code-based checks after extraction. For invoices, compare subtotal, tax, discounts, and total where the document provides enough information. For forms, check required fields and allowed values. For contracts, check that dates use a valid format and that extracted clauses include source evidence. Validation should produce actionable error codes rather than a single pass-or-fail label.

Security and retention

Define which documents may be sent to an external model, how access is controlled, how long source files and extracted data are retained, and whether sensitive fields should be masked. Log prompt and schema versions without exposing unnecessary document contents. These decisions belong in the application design, not as an afterthought.

Common mistakes

  • Using one universal prompt: invoices, forms, and contracts have different schemas, evidence needs, and failure modes.
  • Requesting a summary instead of structured extraction: summaries can omit fields and make downstream validation difficult.
  • Allowing silent inference: a plausible completion can be more dangerous than an explicit missing value.
  • Ignoring page references: reviewers need a fast way to verify important values.
  • Trusting valid JSON: syntactically valid output may still contain wrong types, fabricated values, or incomplete arrays.
  • Testing only clean samples: include scans, unusual layouts, amendments, blanks, duplicates, and borderline cases.
  • Changing prompts without regression tests: keep representative documents and compare field-level results after every model, schema, or prompt change.
  • Skipping human approval for high-impact records: automate routing and validation, but preserve a review path for exceptions and consequential decisions.

When to revisit

Revisit this workflow before seasonal planning cycles, when document layouts or business requirements change, and whenever the underlying model, OCR component, file parser, or API provider changes. Also review it after adding a new supplier, form version, contract type, language, or page format.

At each review, sample recent failures and classify them: wrong document type, OCR error, missing field, incorrect normalization, table error, unsupported layout, hallucinated value, or validation defect. Update the field worksheet, prompt examples, schemas, and deterministic rules together. Re-run the same evaluation set and compare field-level accuracy, missing-value handling, review rate, and processing cost.

For an implementation checklist, pair this workflow with the LLM application evaluation guide and the LLM application release checklist. If the extraction service is deployed as an API, use the cloud production readiness checklist. Before changing providers, compare prompt, schema, file-input, and validation behavior using the AI provider migration checklist.

Next action: choose one document type, define no more than the fields your process actually needs, collect representative examples, and implement the flow as classify, extract, validate, review, and record evidence. Expand coverage only after the first version produces measurable, reviewable results.

Related Topics

#document AI#LLM document extraction#prompt templates#OCR#invoice automation#contract analysis
D

Datawizard Editorial Team

AI Development Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.