✓ Takes 2 minutes • No credit card required • Instant on-screen output
✓ Takes 2 minutes • No credit card required • Instant on-screen output

How to Turn Messy PDFs and Scans Into Clean JSON and CSV With Claude

By Ashley Gross

·

·

Claude

Claude OCR data extraction pipeline converting scanned PDF documents into structured JSON and CSV

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.



[SCHEMA DEFINITION TEMPLATE]
Target Format: CSV
Required Fields:
1. invoice_number (String)
2. vendor_name (String)
3. invoice_date (Date, Format: YYYY-MM-DD)
4. line_item_description (String)
5. quantity (Integer)
6. unit_price (Decimal, 2 places)
7. total_amount (Decimal, 2 places)

Rules for Missing or Ambiguous Data:
- If a value is missing, output "NULL".
- If handwriting is unreadable, output "UNREADABLE". Do not guess

[SCHEMA DEFINITION TEMPLATE]
Target Format: CSV
Required Fields:
1. invoice_number (String)
2. vendor_name (String)
3. invoice_date (Date, Format: YYYY-MM-DD)
4. line_item_description (String)
5. quantity (Integer)
6. unit_price (Decimal, 2 places)
7. total_amount (Decimal, 2 places)

Rules for Missing or Ambiguous Data:
- If a value is missing, output "NULL".
- If handwriting is unreadable, output "UNREADABLE". Do not guess

[SCHEMA DEFINITION TEMPLATE]
Target Format: CSV
Required Fields:
1. invoice_number (String)
2. vendor_name (String)
3. invoice_date (Date, Format: YYYY-MM-DD)
4. line_item_description (String)
5. quantity (Integer)
6. unit_price (Decimal, 2 places)
7. total_amount (Decimal, 2 places)

Rules for Missing or Ambiguous Data:
- If a value is missing, output "NULL".
- If handwriting is unreadable, output "UNREADABLE". Do not guess

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.


Extract all line item details from the attached PDF. 
Strictly follow the Schema Definition rules below. 
Return ONLY a valid CSV inside a single code block. 
Do not include introductory prose or concluding conversational sentences.

[Paste Schema Definition Template]
Extract all line item details from the attached PDF. 
Strictly follow the Schema Definition rules below. 
Return ONLY a valid CSV inside a single code block. 
Do not include introductory prose or concluding conversational sentences.

[Paste Schema Definition Template]
Extract all line item details from the attached PDF. 
Strictly follow the Schema Definition rules below. 
Return ONLY a valid CSV inside a single code block. 
Do not include introductory prose or concluding conversational sentences.

[Paste Schema Definition Template]

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.


The attached document contains a table spanning multiple pages. 
Step 1: Count the total number of table rows across all pages.
Step 2: List the line items following our schema.
Step 3: Confirm that the extracted row count matches your initial count

The attached document contains a table spanning multiple pages. 
Step 1: Count the total number of table rows across all pages.
Step 2: List the line items following our schema.
Step 3: Confirm that the extracted row count matches your initial count

The attached document contains a table spanning multiple pages. 
Step 1: Count the total number of table rows across all pages.
Step 2: List the line items following our schema.
Step 3: Confirm that the extracted row count matches your initial count

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 UNREADABLE prevents corrupted figures from leaking into financial records.


Extract all fields from this scanned document photo. 
If handwriting or faint print is ambiguous, mark that specific field as "FLAG_FOR_REVIEW". 
Do not extrapolate missing numbers

Extract all fields from this scanned document photo. 
If handwriting or faint print is ambiguous, mark that specific field as "FLAG_FOR_REVIEW". 
Do not extrapolate missing numbers

Extract all fields from this scanned document photo. 
If handwriting or faint print is ambiguous, mark that specific field as "FLAG_FOR_REVIEW". 
Do not extrapolate missing numbers

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


Fields: invoice_num, vendor, date, item_desc, qty, price, line_total
Missing values: NULL
Unclear visual text: FLAG_REVIEW
Output: CSV format
Fields: invoice_num, vendor, date, item_desc, qty, price, line_total
Missing values: NULL
Unclear visual text: FLAG_REVIEW
Output: CSV format
Fields: invoice_num, vendor, date, item_desc, qty, price, line_total
Missing values: NULL
Unclear visual text: FLAG_REVIEW
Output: CSV format

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

  1. Prompting without a strict schema: Writing "extract the data" causes Claude to alter column names between files, ruining automated CSV imports.

  2. Ignoring row counts on multi-page files: Assuming Claude captured every row without explicit confirmation leads to dropped line items on multi-page tables.

  3. 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.