How to Turn Messy PDFs and Scans Into Clean JSON and CSV With Claude
By Ashley Gross
·
·
Claude

Manual data entry from PDFs takes hours, and basic AI extraction frequently skips table rows or alters formatting between files. You do not need complex web scrapers or manual data teams to process messy documents. Defining a strict target schema upfront gives you clean, consistent data ready for your database or spreadsheet.
What You Need
Plan level: Pro, Team, or Enterprise plan (Free accounts hit context limits quickly on multi-page files).
Source files: Sample PDFs, scanned receipts, photos, or forms.
Fields list: A list of exact field names, data types, and default values.
Step-by-Step Walkthrough
1. Define Your Schema First
When you ask Claude to "extract data," it invents header names on the fly, yielding inconsistent outputs across documents. Draft a strict schema defining field names, expected data types, and explicit instructions for missing values before uploading any files.
Why it matters: Specifying key names and missing value defaults ensures every processed file matches your target database structure.

2. Extract Data From Clean Text-Based PDFs
Upload your native text PDF directly to the chat interface using the paperclip button. Combine your uploaded document with your defined schema prompt, explicitly requesting a raw CSV code block.
Why it matters: Asking for code block formatting prevents conversational text from contaminating your data output, making raw copying seamless.

3. Process Multi-Page Tables Without Dropping Rows
When tables span across page breaks, standard vision models often omit page headers or drop final rows. Force a explicit row validation check by requiring Claude to count and report total line items before returning data.
Why it matters: Explicit row counts prevent silent omissions on long financial tables that span multiple pages.

4. Extract Data From Scans, Photos, and Handwriting
Claude processes PDFs up to 100 pages with full visual analysis, allowing it to evaluate scanned images, receipts, and handwritten forms alongside text. For low-quality scans or handwriting, instruct the model to flag uncertain extractions rather than guessing values.
Why it matters: Marking low-confidence fields as
UNREADABLEprevents corrupted figures from leaking into financial records.

5. Verify and Export Output
Inspect the output table inside the chat interface. You can copy the code block directly into a text editor, save it as a .csv file, or request a downloadable CSV artifact directly within the chat window.
Why it matters: Exporting to standardized formats allows immediate import into Excel, Google Sheets, or internal SQL databases.

6. Scale Extraction via Chat Batching or API
You can upload up to 20 files per chat session (up to 30MB per file) on web interfaces. For enterprise volumes, use the Claude API Structured Outputs feature (output_config.format). Programmatic structured outputs apply constrained decoding to guarantee responses match your JSON schema mathematically.
Why it matters: API-level JSON schemas eliminate syntax errors entirely, permitting automated batch processing of thousands of files.

Real Example: Accounts Payable Invoice Processing
An accounts payable team needed to process 25 vendor invoices with varied layouts, including three scanned receipts and one multi-page line-item invoice.
The Schema
The Initial Build Prompt
"Process the attached 25 invoice files according to our Schema Definition. Output a single combined CSV code block containing all line items across all vendor files."
The Row-Count Check Catch
On a multi-page invoice from a equipment vendor, the initial draft extracted 12 line items. The operator ran a verification prompt:
"Count the visual rows on page 2 of document Vendor_Equipment_04.pdf and compare it to the CSV output."
Claude re-scanned the visual layout, identified three omitted line items buried beneath a page break footer, and updated the CSV to reflect 15 total items.
Final Delivery
The final CSV block was copied into Excel, automatically populated across seven accounting columns, and uploaded to the ERP system in under ten minutes.
Common Mistakes
Prompting without a strict schema: Writing "extract the data" causes Claude to alter column names between files, ruining automated CSV imports.
Ignoring row counts on multi-page files: Assuming Claude captured every row without explicit confirmation leads to dropped line items on multi-page tables.
Allowing the model to guess blurry numbers: Omitting rules for missing values forces the model to invent plausible numbers for illegible text.
Take It Further
Build a dedicated Project named "Invoice Extraction Workspace" inside Claude. Add your schema definition text directly into the Project Instructions panel. Whenever you or your team drop new invoice PDFs into that Project chat, Claude reads your schema automatically and outputs identical CSV formats every time.
