Skip to content
agentusehub
Sign in+ Submit
Receipt OCR with Gemini and n8n: Validate JSON Before Logging
OperationsIntermediateAny

Receipt OCR with Gemini and n8n: Validate JSON Before Logging

Use n8n to read receipts with Gemini, then validate JSON and decide if it's safe to record.

Jump to setup
Time saved
0h / week
Setup time
Not stated
Running cost
Not stated
Cost range
Under $25/mo

The problem it solves

“Receipt OCR with Gemini and n8n: Validate JSON Before Logging” is an intermediate Operations AI agent workflow from Any. It connects n8n, Gemini and Google Sheets in 4 steps. Setup takes about Not stated and running costs are about Not stated.

Gemini can return JSON for receipt OCR, but not all responses are valid or safe to log. You need to handle unreadable JSON, empty content, and distinguish retryable API errors from permanent failures before writing to Google Sheets.

How it flows
  1. List receipts
  2. Download image
  3. Build Gemini request
  4. Call Gemini
  5. Validate JSON and log

Step-by-step setup

  1. Set up receipt inbox and sheet

    Place receipt images in a Google Drive folder and create a Google Sheet with columns for store name, date, total, and status. Configure n8n to list files from the inbox folder and download each one.

  2. Build Gemini request with store list

    Use a Code node to fetch store names from the sheet and another Code node to construct the HTTP request body for Gemini, including the image and a prompt asking for JSON output.

  3. Call Gemini API

    Add an HTTP Request node to send the request to the Gemini API endpoint with your API key. Use the model gemini-3.6-flash as in the source.

  4. Validate JSON and decide logging

    Add a Code node to parse the response. Check if JSON is valid, if fields are non-empty, and classify API errors as retryable or permanent. Use an IF node to route valid records to Google Sheets and invalid ones to an error log or retry queue.

Example prompts

Generate n8n workflow for receipt OCR
Create an n8n workflow that lists images from a Google Drive folder [INBOX_FOLDER_ID], downloads each, and sends it to Gemini API using model gemini-3.6-flash with a prompt to extract store name, date, and total as JSON. Include a Code node to validate the JSON response: check if it parses, if required fields are present and non-empty, and classify errors as retryable (e.g., rate limit) or permanent (e.g., invalid image). Use an IF node to route valid records to Google Sheets [SHEET_ID] and invalid ones to a separate error sheet. Provide the workflow JSON.
Write validation Code node logic
Write JavaScript code for an n8n Code node that takes the Gemini API response and validates it. The code should: 1) attempt to parse the response as JSON; 2) check that store name, date, and total are present and not empty; 3) if parsing fails or fields are missing, return an object with status 'invalid' and a reason; 4) if the API returned an error, classify it as retryable (HTTP 429, 500, 503) or permanent (400, 401, 403, 404); 5) otherwise return status 'valid' with the extracted data. Output should be usable by an IF node to route to Google Sheets or error handling.

Frequently asked questions

What does the “Receipt OCR with Gemini and n8n: Validate JSON Before Logging” workflow do?

Use n8n to read receipts with Gemini, then validate JSON and decide if it's safe to record.

Which tools do I need?

You need n8n, Gemini and Google Sheets.

How long does it take to set up?

Plan for about Not stated. It is rated intermediate. The guide walks through 4 steps, starting with “Set up receipt inbox and sheet”.

How much does it cost to run?

Expect about Not stated in running costs (Under $25/mo range).

What problem does it solve?

Gemini can return JSON for receipt OCR, but not all responses are valid or safe to log. You need to handle unreadable JSON, empty content, and distinguish retryable API errors from permanent failures before writing to Google Sheets.

Operations · Beginner
  1. Call ends
  2. Transcript to Claude
  3. Notes + field updates

Meeting notes that update the CRM for you

After each sales call, Zapier sends the transcript to Claude, which writes the notes and updates next steps and deal fields in Salesforce.

Zapier · Claude · Salesforce
Content · Advanced
  1. Monthly schedule
  2. Find declining posts
  3. Research changes

Refresh blog posts that are losing search traffic

Each month, find posts whose search clicks dropped, research what changed with Perplexity, and get a Claude-written refresh brief for each one.

n8n · Perplexity · Claude · Google Sheets
Marketing · Intermediate
  1. Monday 07:00 cron
  2. Compute WoW deltas
  3. Claude writes report

Weekly paid-media report written for you every Monday

Every Monday, get a Slack summary of spend, CPA and ROAS by campaign, with week-over-week changes and anomalies flagged before standup.

n8n · Google Sheets · Claude · Slack
Add this badge to your site

Built this workflow? Show it is featured on AgentUseHub with a live upvote count that links back here. About badges

Featured on AgentUseHub