DOC Classify for Idfy
Classifies document in 10 categories
Shared 1/8/2026
3 views
Visual Workflow
JSON Code
{
"id": "ko-8LseKYOq4HdjSOpUfN",
"meta": {
"instanceId": "372a2bb50c5d2d2a17e28216d65a172584be48298e102dc198c6ef59e66aed52",
"templateCredsSetupCompleted": true
},
"name": "DOC Classify with Gemini",
"tags": [],
"nodes": [
{
"id": "6984a855-ec6a-45d5-9ccf-2acd03ecafce",
"name": "Google Gemini Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
976,
48
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"id": "gIHcE1v10iiozeLv",
"name": "Google Gemini(PaLM) Api account"
}
},
"typeVersion": 1
},
{
"id": "73959c9a-27b5-4ee4-a1f1-61ff334bdeb4",
"name": "Simple Memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
1136,
64
],
"parameters": {
"sessionKey": "={{ $execution.id }}",
"sessionIdType": "customKey",
"contextWindowLength": 1
},
"typeVersion": 1.3
},
{
"id": "859be2e0-f56d-4641-9286-29a97595eaed",
"name": "Parsing Json",
"type": "n8n-nodes-base.code",
"position": [
1376,
-176
],
"parameters": {
"jsCode": "const raw = items[0].json.output;\n\n// remove markdown fences\nconst cleaned = raw\n .replace(/```json/g, '')\n .replace(/```/g, '')\n .trim();\n\nconst parsed = JSON.parse(cleaned);\n\n// build flat row for Google Sheets\nconst row = {\n classification: parsed.final_classification.classified_as,\n confidence: parsed.final_classification.confidence,\n ...parsed.scores\n};\n\nreturn [{ json: row }];\n"
},
"typeVersion": 2
},
{
"id": "dfd1fd07-52b1-4c61-b590-06ee6fe19aaf",
"name": "Extract from File",
"type": "n8n-nodes-base.extractFromFile",
"position": [
320,
-288
],
"parameters": {
"options": {
"maxPages": 1
},
"operation": "pdf",
"binaryPropertyName": "Upload"
},
"typeVersion": 1.1
},
{
"id": "7f9a1b78-8a1e-417f-810c-d64a43df6fda",
"name": "Form",
"type": "n8n-nodes-base.form",
"notes": "Hey, Seems like the Google Model was overloaded right now.\n\nLet me re-try and classify",
"onError": "continueRegularOutput",
"maxTries": 2,
"position": [
1600,
16
],
"webhookId": "17074cd9-114c-4aea-ad54-17ee96c31d9c",
"parameters": {
"options": {
"customCss": "",
"formTitle": "Results"
},
"operation": "completion",
"completionTitle": "=Hey there, thank you for using DocClassify, you've uploaded {{ $json.classification }}. \n\nI'm {{ $json.confidence }} % sure!",
"completionMessage": "=Thank you, to re-upload, please click on the form link again."
},
"executeOnce": false,
"retryOnFail": true,
"typeVersion": 2.4,
"alwaysOutputData": false,
"waitBetweenTries": 2000
},
{
"id": "061fe437-1485-4b30-8752-c46a7af7daaa",
"name": "OCR Image Extraction",
"type": "@n8n/n8n-nodes-langchain.googleGemini",
"position": [
320,
48
],
"parameters": {
"text": "### ROLE\n\nYou are a Document OCR and Integrity Guardrail Engine. Your goal is to extract text ONLY if the document is a valid, original physical document.\n\n\n\n### STEP 1: GUARDRAIL EVALUATION (Hard Rejects)\n\nAnalyze the image for the following. If any are detected, return {\"content\": null, \"reason\": \"REASON_HERE\"} and STOP.\n\n\n\n1. NON-DOCUMENT: Image contains faces (selfies), scenery, random objects, or chat/app screenshots.\n\n2. BLANK/NEAR-BLANK: Scanned empty pages or backsides of cards with no identifying text.\n\n3. LOW QUALITY: Image is too blurry, overexposed, or dark to extract at least 15 characters of legible text.\n\n4. SCREENSHOT DETECTION: Detect phone UI elements (Status bar, battery icon, notch, navigation dock, or app borders).\n\n5. MULTI-DOC FOCUS: If multiple documents exist, only extract text from the largest/most centered one.\n\n\n\n### STEP 2: EXTRACTION (Only if Step 1 Passes)\n\nPerform high-fidelity OCR on the primary document. Capture all names, numbers, dates, and unique identifiers (like MRZ lines or UID formats) and reply",
"modelId": {
"__rl": true,
"mode": "list",
"value": "models/gemini-2.5-flash",
"cachedResultName": "models/gemini-2.5-flash"
},
"options": {},
"resource": "document",
"simplify": false,
"inputType": "binary",
"binaryPropertyName": "Upload"
},
"credentials": {
"googlePalmApi": {
"id": "gIHcE1v10iiozeLv",
"name": "Google Gemini(PaLM) Api account"
}
},
"typeVersion": 1.1
},
{
"id": "65638bfc-d12a-4c53-a743-32ea0c257fde",
"name": "Classifier",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
992,
-176
],
"parameters": {
"text": "=You are a high-precision document OCR and classification engine. \nEvaluate the provided document (Image or Text) against 11 document types.\n\n### MANDATORY DATA POINTS (Required for Confidence > 50):\n1. PAN Card: Permanent Account Number (10 alphanumeric), Name, Father's Name, DOB, Income Tax Dept signature/logo.\n2. Aadhaar Card: 12-digit UID (XXXX XXXX XXXX), \"Government of India\", \"VID\", Address, DOB.\n3. Passport: \"REPUBLIC OF INDIA\", Passport No (starts with letter), Type 'P', MRZ Code (the <<< lines at bottom), Nationality.\n4. Voter ID: \"ELECTION COMMISSION OF INDIA\", EPIC Number, Father's/Husband's name.\n5. Bank Statement: Bank Name, Account Number, Transaction list, Opening/Closing balance.\n6. Bank Passbook: Bank Name, IFSC code, Branch details, Account holder name.\n7. Invoice: Word \"Invoice\" or \"Bill\", Tax ID (GSTIN), Line items with totals, Date, Vendor Name.\n8. ITR: \"Acknowledgement Number\", \"Assessment Year\", \"Income Tax Department\", Form Type (e.g., ITR-V).\n9. Electricity Bill: Consumer Number, Billing Cycle, Units Consumed, Utility Provider Name (e.g., BESCOM, Tata Power).\n10. Resume: Education, Experience, Skills, Accomplishments, Skills .\n11. Miscellaneous: None of the above.\n\n### EVALUATION LOGIC:\n- Compute a confidence score (0–100) for EACH of the 11 types.\n- If the document contains the MRZ code (e.g., P<IND...), it is almost certainly a Passport.\n- If the highest score is ≥ 80, classify as that type. Otherwise, classify as \"Miscellaneous (Other)\".\n- Strictly follow the JSON output format provided below.\n\n### INPUT TEXT TO EVALUATE:\n{{ $json.candidates[0].content.parts[0].text }}\n\n### OUTPUT FORMAT (JSON ONLY):\n{\n \"final_classification\": {\n \"classified_as\": \"<one of: PAN Card | Aadhaar Card | Passport | Voter ID | Bank Statement | Bank Passbook | Invoice | Income Tax Return (ITR) | Electricity Bill | Resume | Miscellaneous (Other)>\",\n \"confidence\": <number 0-100>\n },\n \"scores\": {\n \"PAN Card\": <number>,\n \"Aadhaar Card\": <number>,\n \"Passport\": <number>,\n \"Voter ID\": <number>,\n \"Bank Statement\": <number>,\n \"Bank Passbook\": <number>,\n \"Invoice\": <number>,\n \"Income Tax Return (ITR)\": <number>,\n \"Electricity Bill\": <number>,\n \"Resume\": <number>,\n \"Miscellaneous (Other)\": <number>\n }\n}",
"options": {},
"promptType": "define"
},
"typeVersion": 3.1
},
{
"id": "71627c13-cc32-446b-a69b-c1adc85fdf46",
"name": "File Type",
"type": "n8n-nodes-base.if",
"position": [
-48,
-144
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "9893889e-bb55-42b4-9879-6ec3512cc47e",
"operator": {
"type": "string",
"operation": "contains"
},
"leftValue": "={{ $json.Upload.mimetype }}",
"rightValue": "pdf"
}
]
}
},
"typeVersion": 2.3
},
{
"id": "f1964df8-ff7d-4d25-bb28-019be00138e8",
"name": "Once the Form is Submitted",
"type": "n8n-nodes-base.formTrigger",
"position": [
-256,
-144
],
"webhookId": "48554ef8-06fd-449a-afa0-3ec4a4d09fdd",
"parameters": {
"options": {
"path": "idfy_docclasify_arjun_rastogi",
"customCss": ":root {\n /* Brand Fonts */\n --font-family: 'Inter', 'Open Sans', sans-serif;\n \n /* IDfy Brand Colors */\n --color-primary-red: #cd2027; /* IDfy Cardinal Red */\n --color-primary-blue: #1c43b9; /* IDfy Primary Blue */\n --color-dark-grey: #373737; /* IDfy Mine Shaft */\n --color-light-grey: #f5f5f5; /* IDfy Background Grey */\n \n /* Mapping to n8n Variables */\n --color-background: var(--color-light-grey);\n --color-card-bg: #ffffff;\n --color-header: var(--color-dark-grey);\n --color-label: var(--color-dark-grey);\n --color-submit-btn-bg: var(--color-primary-red);\n --color-submit-btn-text: #ffffff;\n --color-focus-border: var(--color-primary-blue);\n --color-required: var(--color-primary-red);\n --color-html-link: var(--color-primary-blue);\n\n /* Dimensions & Spacing */\n --container-width: 480px;\n --border-radius-card: 12px;\n --border-radius-input: 8px;\n --padding-card: 32px;\n}\n\n/* Custom Header Injection */\n.form-header h1 {\n font-size: 0; /* Hide default title */\n}\n\n.form-header h1::before {\n content: \"DocClassify by Arjun Rastogi\";\n font-size: 24px;\n font-weight: 700;\n color: var(--color-dark-grey);\n display: block;\n margin-bottom: 8px;\n}\n\n/* Styling the Submit Button for a more 'IDfy' premium feel */\nbutton[type=\"submit\"] {\n text-transform: uppercase;\n letter-spacing: 1px;\n font-weight: 600;\n transition: background 0.3s ease;\n}\n\n button[type=\"submit\"]:hover {\n background-color: #a31a1f !important; /* Slightly darker red on hover */\n}\n\n/* Card Styling */\n.form-card {\n border-top: 4px solid var(--color-primary-red);\n box-shadow: 0 10px 25px rgba(0,0,0,0.05);\n}",
"buttonLabel": "Classify",
"appendAttribution": false
},
"formTitle": "Doc Classify",
"formFields": {
"values": [
{
"fieldName": "Upload",
"fieldType": "file",
"fieldLabel": "Max Size 5 Mb",
"multipleFiles": false,
"acceptFileTypes": ".jpg, .pdf, .jpeg, .png"
}
]
},
"responseMode": "lastNode",
"formDescription": "This tool helps you segregate document in 10 categories \nPAN Card, Aadhaar Card, Passport, Voter ID, Bank Statement, Bank Passbook, Invoice, Income Tax Return, Electricity Bill, Resume, Miscellaneous (Other)\n\nUpload Format Supported: .JPG, .JPEG, .png or .pdf, In case of multiple pages in PDF, only Page 1 will be considered\n\nFor best results, upload 1 pager pdf or 1 sided Document Image"
},
"typeVersion": 2.4
},
{
"id": "9594a9c1-d6b3-4cb8-92f5-bbc2a2dbf827",
"name": "Activity Tracker",
"type": "n8n-nodes-base.googleSheets",
"position": [
1584,
-176
],
"parameters": {
"columns": {
"value": {},
"schema": [
{
"id": "classification",
"type": "string",
"display": true,
"required": false,
"displayName": "classification",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "PAN card",
"type": "string",
"display": true,
"required": false,
"displayName": "PAN card",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Aadhaar Card",
"type": "string",
"display": true,
"required": false,
"displayName": "Aadhaar Card",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Passport",
"type": "string",
"display": true,
"required": false,
"displayName": "Passport",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Voter ID",
"type": "string",
"display": true,
"required": false,
"displayName": "Voter ID",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Bank Statement",
"type": "string",
"display": true,
"required": false,
"displayName": "Bank Statement",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Bank Passbook",
"type": "string",
"display": true,
"required": false,
"displayName": "Bank Passbook",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Bank Passbook",
"type": "string",
"display": true,
"required": false,
"displayName": "Bank Passbook",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Invoice",
"type": "string",
"display": true,
"required": false,
"displayName": "Invoice",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Income Tax Return (ITR)",
"type": "string",
"display": true,
"required": false,
"displayName": "Income Tax Return (ITR)",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": " Electricity Bill",
"type": "string",
"display": true,
"required": false,
"displayName": " Electricity Bill",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Resume",
"type": "string",
"display": true,
"required": false,
"displayName": "Resume",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Miscellaneous (Other)",
"type": "string",
"display": true,
"required": false,
"displayName": "Miscellaneous (Other)",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "confidence",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "confidence",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "PAN Card",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "PAN Card",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Electricity Bill",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Electricity Bill",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "autoMapInputData",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1060508877,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VD6JtXYJx0z4WqUWFPt_aFGLhJMtufVcYfAnUa-UtzA/edit#gid=1060508877",
"cachedResultName": "Doc Classification"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1VD6JtXYJx0z4WqUWFPt_aFGLhJMtufVcYfAnUa-UtzA",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VD6JtXYJx0z4WqUWFPt_aFGLhJMtufVcYfAnUa-UtzA/edit?usp=drivesdk",
"cachedResultName": "Document Classification"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "Ro24u1u79eub8KGh",
"name": "Google Sheets account"
}
},
"typeVersion": 4.7
}
],
"active": true,
"pinData": {},
"settings": {
"availableInMCP": false,
"executionOrder": "v1"
},
"versionId": "c6fe3a4e-427e-4bda-b189-0e33dd19c153",
"connections": {
"File Type": {
"main": [
[
{
"node": "Extract from File",
"type": "main",
"index": 0
}
],
[
{
"node": "OCR Image Extraction",
"type": "main",
"index": 0
}
]
]
},
"Classifier": {
"main": [
[
{
"node": "Parsing Json",
"type": "main",
"index": 0
}
]
]
},
"Parsing Json": {
"main": [
[
{
"node": "Activity Tracker",
"type": "main",
"index": 0
},
{
"node": "Form",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "Classifier",
"type": "ai_memory",
"index": 0
}
]
]
},
"Extract from File": {
"main": [
[
{
"node": "Classifier",
"type": "main",
"index": 0
}
]
]
},
"OCR Image Extraction": {
"main": [
[
{
"node": "Classifier",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "Classifier",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Once the Form is Submitted": {
"main": [
[
{
"node": "File Type",
"type": "main",
"index": 0
}
]
]
}
}
}