Archive and index legal PDFs from Gmail with Gemini, Sheets and Google Drive

Go to Workflow
0 views
Built by Oka Hironobu Oka Hironobu
Created on July 28, 2026

Description

Quick Overview
This workflow monitors Gmail for unread emails with PDF attachments, uses Google Gemini to extract Japan Electronic Books Preservation Act filing metadata, logs a searchable index in Google Sheets, and archives documents into Google Drive folders while notifying Slack when extraction or classification fails.

How it works
Polls Gmail hourly for unread emails that contain attachments and downloads the attached files.
Extracts text from the first PDF attachment.
Sends the extracted text to Google Gemini to pull out transaction date, counterparty, amount, and document type, and alerts Slack if the document text cannot be read.
Builds an Act-compliant PDF filename from the extracted fields and checks that date, counterparty, and amount are all present.
If required metadata is missing, posts a warning to a Slack channel to handle the document manually.
If metadata is complete, appends a row to a Google Sheets “Document Index”, marks the Gmail message as read to prevent reprocessing, and uploads the PDF to the matching Google Drive folder (invoice/receipt/contract) or flags it in Slack if unclassified.

Setup
Connect credentials for Gmail, Google Gemini (PaLM) API, Google Sheets, Google Drive, and Slack.
Create (or choose) Google Drive folders for invoices, receipts, and contracts, and select the correct folder IDs in the three Google Drive upload steps.
Select the target Google Sheets spreadsheet and the “Document Index” sheet (or create it) where the searchable metadata rows are appended.
Pick the Slack channel (for example, #accounting) used for extraction failures, missing metadata alerts, and unclassified document notifications.

Nodes Used (8)

Basic LLM Chain
@n8n/n8n-nodes-langchain.chainLlm
Code
n8n-nodes-base.code
Gmail
n8n-nodes-base.gmail
Google Drive
n8n-nodes-base.googleDrive
Google Gemini Chat Model
@n8n/n8n-nodes-langchain.lmChatGoogleGemini
Google Sheets
n8n-nodes-base.googleSheets
Slack
n8n-nodes-base.slack
Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured