---
title: "Discussion on \"How to Automate PDF Invoice OCR and Math Reconciliation in Google Sheets Using n8n and GPT-4o-mini\" | Hashnode"
description: "Discussion on \"How to Automate PDF Invoice OCR and Math Reconciliation in Google Sheets Using n8n and GPT-4o-mini\". Manual invoice data entry is slow, and relying solely on Large Language Models (LLMs) to extract financial figures introduces a hidden risk: arithmetic hallucinations. While models like GPT-4o-mini ex"
url: "https://hashnode.com/posts/how-to-automate-pdf-invoice-ocr-and-math-reconciliation-in-google-sheets-using-n8n-and-gpt-4o-mini/6b03ae21124de1989d11396a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to Automate PDF Invoice OCR and Math Reconciliation in Google Sheets Using n8n and GPT-4o-mini](https://kronix700.hashnode.dev/how-to-automate-pdf-invoice-ocr-and-math-reconciliation-in-google-sheets-using-n8n-and-gpt-4o-mini?utm_source=hashnode&utm_medium=feed)

Manual invoice data entry is slow, and relying solely on Large Language Models (LLMs) to extract financial figures introduces a hidden risk: arithmetic hallucinations. While models like GPT-4o-mini ex

Nov 23 · 4 min read · kronix700.hashnode.dev  
Read the article

-   [#n8n](https://hashnode.com/tag/n8n)
-   [#automation](https://hashnode.com/tag/automation)
-   [#openai](https://hashnode.com/tag/openai)
-   [#google-sheets](https://hashnode.com/tag/google-sheets)

## Written by

[Kronix700](https://hashnode.com/@kronix700)

@kronix700

  
[View profile](https://hashnode.com/@kronix700)

Building turnkey n8n automation workflows, AI document extraction pipelines, and accounting reconciliation tools.

## Responses 2

Markdown supported · ⌘↵ to post

[Hayrullah Kar](https://hashnode.com/@magesheet)

[Nov 23](https://hashnode.com/posts/how-to-automate-pdf-invoice-ocr-and-math-reconciliation-in-google-sheets-using-n8n-and-gpt-4o-mini/6b03ae21124de1989d11396a/comment/6b03f7f148d6febd77cd376e)

Doing the reconciliation in a Code node instead of trusting the model's arithmetic is a sensible split, and putting the variance next to the flag makes the review queue easy to sort. There is one gap I would close before this touches real books. Extract from File only reads a PDF's text layer, so a scanned or photographed invoice comes through as empty or near-empty text. The model then has nothing to read and may return nulls. The || 0 fallbacks turn all three amounts into 0, and since 0 + 0 = 0 the invoice passes as VERIFIED. So the status is most confident in exactly the case where extraction failed. A small guard fixes it: check the extracted text length before the OpenAI call, and in the Code node mark anything with total\_amount <= 0 or a missing invoice\_number as NEEDS\_REVIEW instead of VERIFIED. Also, json\_object mode guarantees valid JSON but not that every key is present. A strict json\_schema response format would enforce the field list.

[Kronix700](https://hashnode.com/@kronix700)

[6d ago](https://hashnode.com/posts/how-to-automate-pdf-invoice-ocr-and-math-reconciliation-in-google-sheets-using-n8n-and-gpt-4o-mini/6b03ae21124de1989d11396a/comment/6b03f7f148d6febd77cd376e#reply-6b04d3614fbbd1ca30494fa6)

Catching the 0 + 0 = 0 false positive on image-only PDFs is a critical safeguard. v1.1 is now live across the repo and kit with both fixes: a NEEDS\_REVIEW guard in the Code node when extracted text is under 15 characters, total\_amount <= 0, or invoice\_number is empty, plus strict json\_schema enforcement on the OpenAI extraction node.
