This workflow corresponds to n8n.io template #13909 — we link there as the canonical source.
This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "Cw8ws3kzeP7ZC1Aq",
"name": "Intelligent expense management with AI tax optimization",
"tags": [],
"nodes": [
{
"id": "864b4df3-47aa-4bd8-bc82-0b8aecfcff84",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-960,
48
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 9
}
]
}
},
"typeVersion": 1.3
},
{
"id": "a0abc676-1a98-423d-b179-b3be2f1b4349",
"name": "Workflow Configuration",
"type": "n8n-nodes-base.set",
"position": [
-736,
48
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "id-1",
"name": "receiptsApiUrl",
"type": "string",
"value": "<__PLACEHOLDER_VALUE__Expense receipts API endpoint URL__>"
},
{
"id": "id-2",
"name": "revenueApiUrl",
"type": "string",
"value": "<__PLACEHOLDER_VALUE__Revenue data API endpoint URL__>"
},
{
"id": "id-3",
"name": "taxAgentEmail",
"type": "string",
"value": "<__PLACEHOLDER_VALUE__Tax agent email address__>"
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
},
{
"id": "73a31f19-a659-439c-8b6e-5ca27e5c56ee",
"name": "Fetch Expense Receipts",
"type": "n8n-nodes-base.httpRequest",
"position": [
-512,
-48
],
"parameters": {
"url": "={{ $('Workflow Configuration').first().json.receiptsApiUrl }}",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"typeVersion": 4.3
},
{
"id": "fa3a847c-a111-4357-a9dc-a2e842e0ea31",
"name": "Fetch Revenue Data",
"type": "n8n-nodes-base.httpRequest",
"position": [
-288,
144
],
"parameters": {
"url": "={{ $('Workflow Configuration').first().json.revenueApiUrl }}",
"options": {}
},
"typeVersion": 4.3
},
{
"id": "2301d4d7-36d6-4083-8f69-76603e11502a",
"name": "Extract Receipt Data",
"type": "n8n-nodes-base.extractFromFile",
"position": [
-288,
-48
],
"parameters": {
"options": {},
"operation": "pdf"
},
"typeVersion": 1.1
},
{
"id": "91936ec6-e147-4554-9907-7899f8a5188d",
"name": "Receipt Matching Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
160,
48
],
"parameters": {
"text": "=Receipt data: {{ $json.text }}\n\nRevenue periods: {{ $json }}",
"options": {
"systemMessage": "You are a tax processing assistant that matches expense receipts with revenue periods.\n\nYour task is to:\n1. Analyze the receipt data and extract the date and amount\n2. Match each receipt to the appropriate revenue period based on the date\n3. Return structured data with matched receipts and their corresponding revenue periods\n\nReturn your results in the structured format defined by the output parser."
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3.1
},
{
"id": "0b5880c9-c38a-4c9c-9c6e-347a27926a9d",
"name": "OpenAI Model - Receipt Matching",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
176,
272
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {},
"builtInTools": {}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.3
},
{
"id": "0eea9256-ff36-4ae1-8911-50b6d108f824",
"name": "Structured Output - Receipt Matching",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
304,
272
],
"parameters": {
"jsonSchemaExample": "{\n\t\"receiptId\": \"RCP-12345\",\n\t\"receiptDate\": \"2024-01-15\",\n\t\"receiptAmount\": 150.75,\n\t\"revenuePeriod\": \"Q1 2024\",\n\t\"matchConfidence\": \"high\"\n}"
},
"typeVersion": 1.3
},
{
"id": "8f5c9240-88fe-480c-b99b-5f512ec21233",
"name": "Deduction Category Extraction Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
512,
48
],
"parameters": {
"text": "=Matched receipt data: {{ $json }}",
"options": {
"systemMessage": "You are a tax deduction specialist that extracts deductible categories from expense receipts.\n\nYour task is to:\n1. Analyze the receipt data and identify the expense category\n2. Determine if the expense is tax deductible\n3. Classify the deduction category (e.g., office supplies, travel, meals, equipment, utilities)\n4. Calculate the allowable deduction percentage based on tax rules\n5. Return structured data with deduction categories and amounts\n\nReturn your results in the structured format defined by the output parser."
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3.1
},
{
"id": "4065dadd-7702-4060-a5e7-4b4a91cf5020",
"name": "OpenAI Model - Deduction Extraction",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
528,
272
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {},
"builtInTools": {}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.3
},
{
"id": "fae7892a-acd1-4421-88c1-cd146759e30d",
"name": "Structured Output - Deduction Extraction",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
656,
272
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"receiptId\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Receipt identifier\"\n\t\t},\n\t\t\"expenseCategory\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Category of the expense (e.g., office supplies, travel, meals)\"\n\t\t},\n\t\t\"isDeductible\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"description\": \"Whether the expense is tax deductible\"\n\t\t},\n\t\t\"deductionCategory\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Tax deduction category\"\n\t\t},\n\t\t\"deductionPercentage\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Percentage of expense that is deductible (0-100)\"\n\t\t},\n\t\t\"deductibleAmount\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Calculated deductible amount\"\n\t\t}\n\t}\n}"
},
"typeVersion": 1.3
},
{
"id": "004909a3-7f57-4a06-a924-889429f0f8a8",
"name": "Calculate Tax Deductions",
"type": "n8n-nodes-base.code",
"position": [
960,
80
],
"parameters": {
"jsCode": "// Calculate total deductions by summing deductibleAmount from all items\n// and grouping by revenue period\n\nconst items = $input.all();\nconst deductionsByPeriod = {};\n\n// Process each item and group by revenue period\nfor (const item of items) {\n const period = item.json.revenuePeriod || 'Unknown Period';\n const deductibleAmount = parseFloat(item.json.deductibleAmount) || 0;\n \n if (!deductionsByPeriod[period]) {\n deductionsByPeriod[period] = {\n period: period,\n totalDeductions: 0,\n itemCount: 0,\n items: []\n };\n }\n \n deductionsByPeriod[period].totalDeductions += deductibleAmount;\n deductionsByPeriod[period].itemCount += 1;\n deductionsByPeriod[period].items.push(item.json);\n}\n\n// Convert to array and calculate grand total\nconst results = Object.values(deductionsByPeriod);\nconst grandTotal = results.reduce((sum, period) => sum + period.totalDeductions, 0);\n\n// Return summary with period breakdowns\nreturn [\n {\n json: {\n grandTotalDeductions: grandTotal,\n periodBreakdowns: results,\n totalPeriods: results.length,\n totalItems: items.length,\n calculatedAt: new Date().toISOString()\n }\n }\n];"
},
"typeVersion": 2
},
{
"id": "7e0b6b8b-22f9-4eec-a671-1e86ac84b240",
"name": "Report Generation Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1312,
48
],
"parameters": {
"text": "=Tax calculation data: {{ $json }}",
"options": {
"systemMessage": "You are a tax report generator that creates comprehensive revenue-minus-deductions reports.\n\nYour task is to:\n1. Analyze the revenue and deduction data\n2. Calculate net taxable income (revenue minus deductions) for each period\n3. Generate a detailed report with:\n - Revenue breakdown by period\n - Deductions breakdown by category\n - Net taxable income calculations\n - Summary statistics\n4. Format the report in a clear, professional structure\n\nReturn your results in the structured format defined by the output parser."
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3.1
},
{
"id": "9232d324-c195-4a67-91e6-e8c443a9a77b",
"name": "OpenAI Model - Report Generation",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1360,
272
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {},
"builtInTools": {}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.3
},
{
"id": "60484377-2ae3-47e6-acaa-0a4c135ca31d",
"name": "Structured Output - Report Generation",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1552,
272
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"reportTitle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Title of the tax report\"\n\t\t},\n\t\t\"reportPeriod\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Period covered by the report\"\n\t\t},\n\t\t\"totalRevenue\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Total revenue for the period\"\n\t\t},\n\t\t\"totalDeductions\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Total deductions for the period\"\n\t\t},\n\t\t\"netTaxableIncome\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Net taxable income (revenue minus deductions)\"\n\t\t},\n\t\t\"deductionsByCategory\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"JSON string of deductions grouped by category\"\n\t\t},\n\t\t\"reportSummary\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Executive summary of the tax report\"\n\t\t}\n\t}\n}"
},
"typeVersion": 1.3
},
{
"id": "360e2c80-e7a6-48fe-a4dd-81127395da66",
"name": "Prepare Final Packet",
"type": "n8n-nodes-base.set",
"position": [
1600,
48
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "id-1",
"name": "emailSubject",
"type": "string",
"value": "=Tax Filing Packet - {{ $json.reportPeriod }}"
},
{
"id": "id-2",
"name": "emailBody",
"type": "string",
"value": "=Please find attached the tax filing packet for {{ $json.reportPeriod }}.\n\nReport Summary:\n{{ $json.reportSummary }}\n\nTotal Revenue: ${{ $json.totalRevenue }}\nTotal Deductions: ${{ $json.totalDeductions }}\nNet Taxable Income: ${{ $json.netTaxableIncome }}\n\nPlease review and proceed with filing."
},
{
"id": "id-3",
"name": "taxAgentEmail",
"type": "string",
"value": "={{ $('Workflow Configuration').first().json.taxAgentEmail }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "1d572fd1-07ca-4027-a704-822141d705fb",
"name": "Send to Tax Agent",
"type": "n8n-nodes-base.gmail",
"position": [
1824,
48
],
"parameters": {
"sendTo": "={{ $json.taxAgentEmail }}",
"message": "={{ $json.emailBody }}",
"options": {},
"subject": "={{ $json.emailSubject }}"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.2
},
{
"id": "4acf57e1-69c2-4b35-9e42-ff58e735ab4f",
"name": "Merge Receipt and Revenue Data",
"type": "n8n-nodes-base.merge",
"position": [
-64,
48
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3.2
},
{
"id": "05568eda-40b9-41fc-963a-8a06e70e07b9",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
320,
-512
],
"parameters": {
"color": 4,
"width": 640,
"height": 320,
"content": "## Prerequisites\nFinancial system API access with read permissions, OpenAI API access. \n## Use Cases\nMonthly expense reconciliation, quarterly tax preparation, annual tax filing automation\n## Customization\nAdd approval workflows for high-value expenses, integrate additional financial systems\n## Benefits\nReduces tax preparation time by 70%, maximizes legitimate deductions through intelligent categorization"
},
"typeVersion": 1
},
{
"id": "28a59a1b-49eb-48d9-aefe-1e073ea268cb",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
-464
],
"parameters": {
"width": 416,
"height": 272,
"content": "## Setup Steps\n1. Configure financial system API credentials in \"Fetch Expense Receipts\" \n2. Set up OpenAI API key in all AI agent nodes for intelligent processing\n3. Define schedule frequency in \"Schedule Trigger\" based on accounting period requirements\n4. Customize deduction categories and rules in \"Deduction Categorization Agent\"\n5. Configure tax calculation parameters in \"Calculate Tax Deductions\" node per regulations"
},
"typeVersion": 1
},
{
"id": "aa1417ff-67c7-4254-95a3-6ef9e8b86d55",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-960,
-480
],
"parameters": {
"width": 752,
"height": 288,
"content": "## How It Works\nThis workflow streamlines financial operations for accounting teams, finance departments, and tax professionals managing business expenses. It addresses the challenge of reconciling expenses with revenue data, accurately categorizing deductions, and ensuring tax compliance across complex transactions. The system triggers on schedule to fetch expense receipts and revenue data from financial systems simultaneously. An AI-powered receipt matching agent uses OpenAI models to intelligently pair receipts with corresponding revenue entries, handling variations in formatting, dates, and vendor names. A deduction categorization agent analyzes matched transactions using structured output parsing to classify expenses into appropriate tax categories based on IRS guidelines and business rules. The workflow calculates optimized tax deductions considering category limits and compliance requirements. A report generation agent compiles comprehensive tax packets with supporting documentation, which are finalized and automatically delivered to tax agents via email for review and filing."
},
"typeVersion": 1
},
{
"id": "b4036f04-9c89-490a-9c20-0b08ba34a65d",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
480,
-160
],
"parameters": {
"color": 7,
"width": 368,
"height": 832,
"content": "## Deduction categorization agent classifies expenses into tax-compliant categories\n**Why**: Ensures accurate tax treatment while maximizing legitimate deduction opportunities within regulatory limits"
},
"typeVersion": 1
},
{
"id": "b3e4afb1-563f-4fa1-9444-a43381756010",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
80,
-160
],
"parameters": {
"color": 7,
"width": 368,
"height": 848,
"content": "## Receipt matching agent pairs expenses with revenue using AI pattern recognition\n**Why**: Handles inconsistent formats and missing data that rule-based matching systems cannot resolve effectively"
},
"typeVersion": 1
},
{
"id": "61ec375c-9abb-4982-9bb9-6f2e7c04e13e",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1008,
-160
],
"parameters": {
"color": 7,
"width": 1056,
"height": 576,
"content": "## Parallel data collection fetches expense receipts and revenue records\n**Why**: Simultaneous retrieval reduces processing time and ensures data consistency across both sources"
},
"typeVersion": 1
},
{
"id": "50ce9d00-30cb-4f33-8bf5-0b7c0a94f975",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1200,
-160
],
"parameters": {
"color": 7,
"width": 832,
"height": 832,
"content": "\n## Report generation agent compiles comprehensive documentation packets\n**Why**: Creates audit-ready records with proper supporting evidence, reducing tax preparation time significantly"
},
"typeVersion": 1
},
{
"id": "b125b150-0b20-4c3f-93b9-ef3065f73ae6",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
864,
-160
],
"parameters": {
"color": 7,
"width": 304,
"height": 1088,
"content": "## Tax calculator determines optimized deductions considering category constraints\n**Why**: Maximizes tax benefits while maintaining compliance with deduction caps and regulatory requirements"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"availableInMCP": false,
"executionOrder": "v1"
},
"versionId": "2f8fbbe0-3958-42e7-bf1b-0f8f7385f996",
"connections": {
"Schedule Trigger": {
"main": [
[
{
"node": "Workflow Configuration",
"type": "main",
"index": 0
}
]
]
},
"Fetch Revenue Data": {
"main": [
[
{
"node": "Merge Receipt and Revenue Data",
"type": "main",
"index": 1
}
]
]
},
"Extract Receipt Data": {
"main": [
[
{
"node": "Merge Receipt and Revenue Data",
"type": "main",
"index": 0
}
]
]
},
"Prepare Final Packet": {
"main": [
[
{
"node": "Send to Tax Agent",
"type": "main",
"index": 0
}
]
]
},
"Fetch Expense Receipts": {
"main": [
[
{
"node": "Extract Receipt Data",
"type": "main",
"index": 0
}
]
]
},
"Receipt Matching Agent": {
"main": [
[
{
"node": "Deduction Category Extraction Agent",
"type": "main",
"index": 0
}
]
]
},
"Workflow Configuration": {
"main": [
[
{
"node": "Fetch Expense Receipts",
"type": "main",
"index": 0
},
{
"node": "Fetch Revenue Data",
"type": "main",
"index": 0
}
]
]
},
"Report Generation Agent": {
"main": [
[
{
"node": "Prepare Final Packet",
"type": "main",
"index": 0
}
]
]
},
"Calculate Tax Deductions": {
"main": [
[
{
"node": "Report Generation Agent",
"type": "main",
"index": 0
}
]
]
},
"Merge Receipt and Revenue Data": {
"main": [
[
{
"node": "Receipt Matching Agent",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Model - Receipt Matching": {
"ai_languageModel": [
[
{
"node": "Receipt Matching Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenAI Model - Report Generation": {
"ai_languageModel": [
[
{
"node": "Report Generation Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Deduction Category Extraction Agent": {
"main": [
[
{
"node": "Calculate Tax Deductions",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Model - Deduction Extraction": {
"ai_languageModel": [
[
{
"node": "Deduction Category Extraction Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output - Receipt Matching": {
"ai_outputParser": [
[
{
"node": "Receipt Matching Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Structured Output - Report Generation": {
"ai_outputParser": [
[
{
"node": "Report Generation Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Structured Output - Deduction Extraction": {
"ai_outputParser": [
[
{
"node": "Deduction Category Extraction Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2openAiApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This workflow streamlines financial operations for accounting teams, finance departments, and tax professionals managing business expenses. It addresses the challenge of reconciling expenses with revenue data, accurately categorizing deductions, and ensuring tax compliance…
Source: https://n8n.io/workflows/13909/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This n8n automation workflow automates the creation, scripting, production, and posting of YouTube videos. It leverages AI (OpenAI), image generation (PIAPI), video rendering (Shotstack), and platform
Created by: Peyton Leveillee Last updated: October 2025
SEO Blog Article Generation Workflow. Uses outputParserStructured, httpRequest, agent, lmChatOpenAi. Scheduled trigger; 56 nodes.
This workflow was born out of a very real problem.
This workflow automates comprehensive real estate investment analysis by orchestrating specialized AI agents to evaluate property data, market trends, and financial metrics. Designed for real estate i