Skip to content

After this module you can stop filing documents by hand: every incoming PDF is identified, renamed to a consistent convention, and saved in the right folder, and anything unclear goes to a human.

What it does

POST /webhook/docs/intake with a PDF (multipart). The workflow:

  1. Extracts the text and runs a free rule classifier: keyword scores for invoice, receipt, contract, bank statement, purchase order and tax form, plus regex extraction of date, counterparty, reference number and amount. It knows which party is you (our_names in Settings), so a contract is filed under the other party.
  2. Asks AI for the type, confidence, fields and a one-line summary, and falls back to the rules if AI is unavailable (the response says why).
  3. Renames the file, e.g. 2026-09-15 - Invoice - Northwind Office Supply LLC - NW-55821.pdf, and picks the folder for its type. Unknown or low-confidence documents go to Needs Review as REVIEW - <original name>.pdf.
  4. Uploads it to Google Drive and reports the result; review cases and failed uploads branch to a notification.

?dry_run=true returns the decision without uploading; ?ai=false uses only the rules (no OpenAI key needed).

Flow

New Document → Settings → Has PDF? ─no→ 400
                              └yes→ Extract PDF Text → Rule Classifier → Use AI? ─yes→ AI Classify (continue on error) ─┐
                                                                                  └no────────────────────────────────┴→ Decide Route → Dry Run?
Dry Run? ─yes→ Respond Decision
         └no─→ Attach File → Upload to Drive (continue on error) → Upload Result → Respond + Needs a Human? → Notify Office

Verification status (n8n 2.43.6)

  • 19/19 checks without credentials on 5 generated sample PDFs (assets/samples/): correct type for each, exact fields (invoice total not subtotal, contract counterparty ≠ us, statement end date + closing balance), renamed files, needs-review routing, non-PDF 400, Drive failure reported, AI failure → rules fallback.
  • The PDF re-attached for upload was checked in the execution data: correct new filename, application/pdf, 817 B.
  • Not run with real OpenAI or Google Drive. WITH_CREDS=1 ./test/test.sh does that. The samples are clean digital PDFs; scanned documents need OCR (Exercise 3).

Files

File Tier Purpose
lesson.md Free Step-by-step build
workflow/starter.json Free Upload, PDF text, rule classifier
workflow/learner.json Learner Finished workflow
workflow/code/ Learner Readable copies of the Code nodes
assets/samples/ Learner 5 test documents with known answers
exercises.md Learner Practice tasks
solutions.md Learner Exercise solutions
notes.md Private Learning log
sell/ Private Offer, video script, blog post