OCR/Data Extractor

TS-06-01

Automatically extract structured, actionable data from court forms, PDFs, contracts, and images to populate case management systems and support legal service workflows.

OCR/Data Extractor

About This Task

Legal help providers routinely receive documents that contain critical information locked inside unstructured formats: court filings, eviction notices, scanned intake forms, handwritten notes, credit card statements, BMV driving records, leases, and correspondence. Manually reviewing these documents and entering key fields into a case management system is slow, error-prone, and hard to scale.

This task is a system that takes in a legal document in any common format (scanned PDF, image, fillable form, Word file, email attachment), extracts specific data fields (case numbers, party names, filing dates, rent demands, deadlines, hearing times, amounts owed), and outputs that information in a structured format ready for import into LegalServer, Salesforce, Pika, or any other downstream system.

The architecture that has emerged from six independent implementations follows a four-stage pipeline: ingest the document, run OCR or vision processing to get text, use an LLM to extract structured fields, then validate the output against expected rules. This pattern was discovered independently by teams at Stanford, Ohio Legal Help, Massachusetts Courts, Duke, LSC, and Rice β€” convergent evolution that provides strong evidence the approach is sound.

Who this serves: Legal aid data managers, court clerks, researchers analyzing case data, legal help website users uploading documents, and any organization that needs structured data from unstructured legal documents.

What Success Looks Like

Key fields are extracted correctly: the case number is right, the party names are right, the hearing date is right, the amounts are right. The system handles the variety of real-world documents: clean digital PDFs, messy scans, handwritten forms, multi-column layouts, tables, checkboxes, stamps, and signatures. A legal worker can review the extracted data quickly and trust it enough to act on it.

A Key Finding: Invest in OCR Quality

Multiple teams converged on the same lesson: spend your money on OCR quality, not on a more expensive LLM. Stanford tested this directly β€” cheap OCR plus an expensive LLM versus expensive OCR plus a cheap LLM. The expensive OCR won. Small mistakes in the OCR stage (a missing comma, a "1" read as "I", a decimal point dropped) have outsized impact downstream. Azure Document Intelligence, run as the first stage, produces markdown output that preserves tables, checkboxes, and layout. A cheaper model like Gemini Flash can then extract structured fields from that clean input for a fraction of the cost.

The working group's informal formula: good input + cheap LLM beats bad input + expensive LLM.

Who Is Building This

This task has the largest active working group in the Legal Help Commons ecosystem. Participants and their projects:

Stanford Legal Design Lab (Othman, Vasyl, Margaret): Extracting data from LA Superior Court debt complaints and eviction filings. Using Azure Document Intelligence for OCR, then Gemini 2.0 Flash for extraction via LangChain. Processing complaints, declarations, and credit card statement images. Developed the schema-first extraction approach and the evaluation rubric.

Ohio Legal Help (Matt): Building a consumer-facing tool where users upload BMV driving records and eviction notices. Uses Tesseract for orientation detection, then Anthropic Claude via LangChain for extraction into Pydantic schemas. Running on Drupal with a web form upload interface. Near-100% accuracy on newer models for standard documents.

Massachusetts Courts / Pew (Casey, Aarushi, Lester): Extracting data from handwritten court forms (marriage/divorce records) for transfer to Office of Vital Statistics. Running Llama Vision 3.2 locally on NVIDIA GPU (court AI policy prohibits cloud). Achieved 90% accuracy on messy handwriting after 6 prompt iterations. Also replicating the LA default assistant architecture for Indiana debt courts.

Duke (Keith): Processing Justice of the Peace financial reports, land deeds going back to the 1790s, and eviction records. Using Gemini 2.5 Flash. Processing 5,000 handwritten financial records with only 10 errors. Building student tools for scraping and human verification workflows.

LSC (Logan): Analyzing 30,000 medical debt court documents from Arkansas using ChatGPT. Partnered with Georgia Tech on LLM comparison. Found that sending documents directly to vision models outperformed traditional OCR-then-LLM pipelines for their use case.

Rice University (Andrew, Steve, Ualas): Researching eviction filing patterns through appeals courts in Texas. Building extraction pipeline for county court records. Handling pro se filings that don't follow standard e-filing format requirements.

Lonestar Legal Aid (Luigi Bai): LACI software monitors legal authorities across 50 states. Detects when statutes, rules, or citations change and flags dependent documents for review. Expanding to integrate AI summarization of flagged changes. Working with Ohio Legal Help, Texas, Wisconsin, Minnesota, Idaho.

Michigan Indian Legal Services (Cameron): Building a tribal law knowledge base from codes, court rules, forms, and opinions that aren't available commercially. Much of the source material is not yet digitized.

The Recommended Architecture

The four-stage pipeline, validated by six teams:

Stage 1 β€” Ingest: Accept documents in any format (PDF, PNG, JPG, TIF, Word). Detect orientation and correct rotation (Tesseract or similar). Handle multi-page documents.

Stage 2 β€” OCR / Vision Processing: Convert document images to structured text. Azure Document Intelligence produces the best output (markdown with tables, checkboxes, layout preserved) but costs ~$0.05/page. Tesseract is free and handles standard printed text. Llama Vision 3.2 runs locally for organizations with GPU hardware and restrictive AI policies. Gemini Flash offers high throughput at ~$0.0002/page.

Stage 3 β€” Structured Extraction via LLM: Pass the OCR output to a language model with a schema definition (Pydantic/JSON) specifying exactly which fields to extract and what format to expect. Use schema-first prompting: define the expected output structure before asking the model to fill it. Use a cheaper model here (Gemini Flash, Claude Haiku) β€” the expensive work was in Stage 2.

Stage 4 β€” Validation and Review: Apply deterministic rules to check extracted values (date formats, amount ranges, known court directories, fee schedules). Flag low-confidence fields for human review. Provide a review interface where a human can see the source document alongside the extracted fields and correct any errors. A two-pass extract-then-validate approach (run extraction, then run a second pass asking the model to check its own work) has been shown to improve accuracy.

Cost Model

Monthly costs vary by scale and approach:

Minimal (~$110/month + 5 hours/week staff): Single document type, Tesseract OCR plus cheap LLM API, under 500 documents/month. Suitable for a pilot project or single-office clinic.

Moderate (~$600/month + 15 hours/week staff): Multiple document types, Azure Document Intelligence for complex layouts plus mid-tier LLM, 500-5,000 documents/month. Suitable for a statewide legal help tool or court data pipeline.

Full (~$3,200/month + 40 hours/week staff): High-volume multi-document pipeline with orchestration, dedicated review staff. Suitable for a statewide court system processing all filings.

What to Watch Out For

Security specifications are the biggest gap. No implementation has fully documented its encryption standards, access control model, audit logging, or data retention policies. These systems handle SSNs, financial data, and other high-risk PII. Document your security configuration before deploying.

No comparative evaluation exists yet. Each team has tested their own approach, but no one has run multiple approaches against the same document corpus. The component comparison is based on separate evaluations with different documents and metrics.

Handwriting remains the hardest problem. Massachusetts achieved 90% accuracy after 6 prompt iterations, which is impressive but still means 1 in 10 fields may be wrong. Handwritten documents need human review built into the workflow.

Prompt maintenance is an open question. Extraction prompts may degrade as models update. No team has tracked this over a full model generation cycle yet.

Quality Standards

What does good performance look like for this task? Use these criteria to evaluate systems.

This rubric was developed by the Stanford Legal Design Lab's Data Extraction working group to evaluate OCR and data extraction tools on real legal documents. Each dimension is scored 1-3 (1 = Not OK, 2 = OK with cleanup, 3 = Good). A Hard Fail on any dimension overrides the overall score.

Hard Fail Conditions

Any of the following means the output is Not OK regardless of dimension scores:

The output is not usable text or data: garbled, missing most text, or wrong file processed. Key fields are consistently wrong or swapped (e.g., case number becomes hearing date). The system gives no way to spot uncertainty: no confidence flags, no review view. Processing creates a privacy or security problem: uploads stored unnecessarily, no access control, unclear data handling.

Dimension 1: Input Coverage

Can the system ingest common legal document formats?

Score 3 (Good): Ingests PNG, JPG, TIF, and PDF (including scanned PDFs) reliably. Handles multi-page documents without loss.

Score 2 (OK with cleanup): Handles most common formats but fails on some (e.g., scanned PDFs with mixed orientation, TIF files). Multi-page documents mostly work but occasionally drop pages.

Score 1 (Not OK): Cannot reliably process scanned PDFs or images. Fails on multi-page documents. Limited to a single input format.

Dimension 2: Accuracy of Extraction

Did the system correctly read the text and numbers, and extract the right values?

Score 3 (Good): Key fields are read correctly: case number, party names, dates, amounts, addresses. Values are assigned to the correct field labels (no "field swaps"). Errors are rare and minor β€” they don't change the meaning.

Score 2 (OK with cleanup): Most key fields are correct but some have character-level errors that affect meaning (e.g., "1,250"readas"1,250" read as " 1,250"readas"I,25O"). Some field swaps occur. A reviewer can fix errors in reasonable time.

Score 1 (Not OK): Frequent errors in key fields. Field swaps are common. Character-level mistakes change legal meaning (wrong dates, wrong amounts, wrong case numbers).

Dimension 3: Coverage Across Document Types

Does the system work on the real-world variety of legal documents?

Score 3 (Good): Works on scanned forms, letters, notes, screenshots, and contracts. Handles both clean prints and messy scans (skew, stamps, faint text). Captures most required fields across formats, not just one "happy path" form.

Score 2 (OK with cleanup): Works well on clean documents but degrades on messy scans. Handles the primary document type well but struggles with variations.

Score 1 (Not OK): Only works on one specific document format. Fails on scanned documents, messy formatting, or any deviation from the expected layout.

Dimension 4: Structure and Layout

Does the system preserve layout and correctly pair labels with values?

Score 3 (Good): Form fields are paired correctly (label stays with its value). Tables are captured with correct rows and columns. Multi-column pages are read in the right order.

Score 2 (OK with cleanup): Most label-value pairs are correct but some are mismatched. Tables mostly work but some cells are in the wrong position. Minor column-reading order issues.

Score 1 (Not OK): Labels and values are frequently mismatched. Tables are scrambled. Multi-column pages produce garbled output.

Dimension 5: Handwriting

Can the system read handwriting when it appears?

Score 3 (Good): Handwritten names, notes, and dates are captured accurately enough to be useful. When unsure, the system flags handwriting fields for human review rather than guessing confidently.

Score 2 (OK with cleanup): Handwriting is partially captured. Some fields are correct, others are wrong or missing. Flagging is inconsistent.

Score 1 (Not OK): Handwriting is not captured or is consistently wrong. No flagging of uncertain handwriting fields. System treats handwriting with the same confidence as printed text.

Dimension 6: Data Cleanliness

Is the extracted data clean and consistently formatted for downstream use?

Score 3 (Good): Dates are normalized (e.g., MM/DD/YYYY) and not ambiguous. Names and addresses are cleanly parsed without random symbols or noise. Currency amounts are consistent (e.g., $1,250.00, not "I,25O.OO").

Score 2 (OK with cleanup): Mostly clean but some normalization issues. A developer can write cleanup rules to handle the remaining inconsistencies.

Score 1 (Not OK): Output contains frequent noise, mixed formats, and unparseable values. Requires extensive manual cleanup before downstream use.

Dimension 7: Error Transparency and Review

Can a human quickly verify and fix mistakes?

Score 3 (Good): Flags low-confidence fields (blurry, conflicting, partial). Provides a review interface showing highlighted fields on the source document page. Allows quick correction and export of revised structured data.

Score 2 (OK with cleanup): Some confidence flagging but incomplete. Review requires switching between source document and extracted data manually. Corrections are possible but cumbersome.

Score 1 (Not OK): No confidence flagging. No way to compare extraction against the source document. Corrections require re-processing.

Dimension 8: Output and Integration

Is the output easy to import into a case management system or database?

Score 3 (Good): Produces structured output (CSV or JSON) with stable, predictable field names. Field mapping is clear and consistent across runs. Minimal manual rework before import.

Score 2 (OK with cleanup): Structured output exists but field names or formats vary between runs. Some mapping work required before import.

Score 1 (Not OK): Output is unstructured or inconsistently structured. Significant manual work required to map fields for import.

Dimension 9: Speed and Reliability

Is the system fast and predictable enough for real legal workflows?

Score 3 (Good): Finishes in under 1 minute for typical documents. Does not crash or time out on common files. Produces consistent results when rerun on the same document.

Score 2 (OK with cleanup): Usually finishes in reasonable time but occasionally slow or inconsistent. Rare crashes or timeouts.

Score 1 (Not OK): Frequently slow, crashes, or produces different results on the same document.

Overall Result

NOT OK: Any Hard Fail, or 2 or more dimensions scored "1."

OK WITH CLEANUP: No Hard Fail. Mostly "2" scores. A trained reviewer can fix the remaining issues in reasonable time.

GOOD: No Hard Fail. Mostly "3" scores. Output is ready for import into downstream systems with minimal human review.

Evaluation Protocol

Step 1: Build a Test Corpus

Select 50-100 documents across the document types your system will process. Include clean digital PDFs, messy scans, documents with tables, documents with handwriting, and documents with stamps or signatures. For each document type, pick 5-10 key fields to test (see the field list below).

Step 2: Create Gold-Standard Labels

Have a human expert manually extract the correct values for each key field in every test document. Record the exact text, position, and expected format. This is your ground truth. Double-label 10-20% of documents to check consistency.

Step 3: Run Extraction and Score

Run your system on the full test corpus. Compare extracted values to gold-standard labels. Measure field-level accuracy: precision, recall, and F1 score for each field type. Measure the Hard Fail rate: what percentage of documents trigger any Hard Fail condition.

Step 4: Stress Tests

Run the same evaluation on deliberately difficult inputs: low-resolution scans (150 DPI or lower), rotated or skewed pages, documents with heavy stamps or watermarks, handwritten sections, multi-column layouts, and non-English content. Report accuracy separately for each stress condition.

Step 5: Utility Review

Have a legal worker review 20+ extraction outputs and rate each on a simple scale: "Can I use this data for its intended purpose without re-reading the source document?" This catches problems that automated metrics miss: field swaps that are technically "accurate" for each field but meaningless in combination, or over-extraction of irrelevant data that buries the important fields.

Key Fields to Test

Pick 5-10 per document type: case number, court name and location, party names (plaintiff and defendant), address and property address, hearing date and time, document date, rent amount or amount claimed, deadlines (e.g., "within 5 days"), checkbox status (selected or unselected) if forms are present, table cell contents (fees, ledger rows) if tables are present.

Using This Rubric

For researchers: The 9 dimensions provide a standard evaluation framework. Use the Hard Fail conditions as binary classifiers for safety-critical assessment. Report field-level precision and recall by entity type. The stress test protocol gives you a reproducible methodology for comparing systems.

For builders: Use the rubric during development as a checklist. Test against each Hard Fail condition first. Invest in OCR quality (Stage 2 of the pipeline) before optimizing LLM prompts (Stage 3). The two-pass extract-then-validate pattern consistently improves accuracy. Build the human review interface early: even the best systems need a human in the loop.

For funders: Require field-level accuracy metrics on a documented test corpus, not just demo-quality outputs on cherry-picked documents. Ask for the Hard Fail rate. Ask for stress test results on messy scans and handwriting. Ask for the cost model: what does this cost per document at the volume the organization actually processes?

Projects Building This Task

3 projects are working on this task across the field.

Other Administration & Strategy Tasks

Explore related tasks in the same workflow category.