This workflow corresponds to n8n.io template #16049 — we link there as the canonical source.
This workflow follows the Agent → Gmail Tool 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": "hEJB8UyMfAyB7Ywu",
"name": "Prompt Chaining",
"tags": [],
"nodes": [
{
"id": "f2559a4a-665e-49b5-82c4-4854eca29f4b",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-128,
16
],
"parameters": {
"width": 480,
"height": 608,
"content": "## Prompt Chaining\n\n### How it works\n\nThis workflow chains multiple AI prompts around an email-driven document processing flow. It starts from a Gmail trigger, analyzes and extracts structured information from the document, validates the result, posts it to an external webhook, and then uses another AI Agent to prepare and send a Gmail follow-up.\n\n### Setup steps\n\n- Connect Gmail credentials for the Gmail Trigger and Gmail sending tool, and configure the trigger criteria for the incoming documents to process.\n- Configure Google Gemini credentials for the Gemini analysis node and both AI Agent model subnodes, including any fallback model settings.\n- Review the Structured Output Parser schema so it matches the fields expected by the validation code and webhook payload.\n- Update the HTTP Request node with the correct webhook or API endpoint, method, headers, and authentication if needed.\n- Review the Validate Document Data code node to ensure its validation rules match the document types and required fields.\n\n### Customization\n\nYou can adjust the extraction prompt and parser schema for different document formats, change the validation logic for stricter business rules, replace the webhook URL with a production API, and customize the second AI Agent\u2019s Gmail message tone or content."
},
"typeVersion": 1
},
{
"id": "e058e0ba-1bbe-4717-837f-15fffb4e0811",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
432,
64
],
"parameters": {
"color": 7,
"width": 880,
"height": 528,
"content": "## Ingest and extract document\n\nStarts when a Gmail event occurs, analyzes the incoming document with Gemini, and uses an AI Agent with primary/fallback Gemini models plus a structured output parser to extract normalized document data. This forms the left-side AI extraction cluster."
},
"typeVersion": 1
},
{
"id": "57dabaa9-d034-4280-b1ec-629d9f90f192",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1344,
16
],
"parameters": {
"color": 7,
"width": 464,
"height": 368,
"content": "## Validate and submit data\n\nRuns custom validation on the extracted document fields and then sends the validated payload to an external webhook endpoint via HTTP POST. These nodes sit in the middle of the canvas as the handoff between extraction and follow-up processing."
},
"typeVersion": 1
},
{
"id": "b249c3a7-2d60-4d40-945f-3661eb8b19e1",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1872,
16
],
"parameters": {
"color": 7,
"width": 432,
"height": 576,
"content": "## Generate Gmail follow-up\n\nUses a second AI Agent with primary/fallback Gemini chat models and a Gmail tool to generate and send a follow-up Gmail message after the external submission step. This is the right-side response/action cluster."
},
"typeVersion": 1
},
{
"id": "c9d6609b-6954-4840-a353-f2f89d011f72",
"name": "When Email Received",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
480,
224
],
"parameters": {
"simple": false,
"filters": {
"sender": "user@example.com"
},
"options": {
"downloadAttachments": true
},
"pollTimes": {
"item": [
{}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.4
},
{
"id": "463da97f-cd83-4558-b75b-ad600ecc37b2",
"name": "Analyze Document with Gemini",
"type": "@n8n/n8n-nodes-langchain.googleGemini",
"position": [
704,
224
],
"parameters": {
"text": "Analyze the document and structure the content to markdown:\n\n## SID\nCompany Name\n## SID City/State/Zip\nSID company City State and zip code\n## SID Address\nSID Company address\n## SID Name\nSID Company Name\n\n\n## CID\nCompany Name\n## CID City/State/Zip\nCID Customer City State and zip code\n## CID Address\nCID Customer address\n## CID Name\nCID Customer Name\n\n\n## Bill of Lading Number\nThe BOL number\n\n## Carrier Name\nName of the freight carrier company\n## Trailer number\nnumber of the trailer\n## Seal number\nID of the Seal\n\n## Customer Order Information Table\n| CUSTOMER ORDER NUMBER | # PKGS | WEIGHT | PALLET/SLIP (CIRCLE ONE) | ADDITIONAL SHIPPER INFO |\n|----------------------------|--------------------|---------------|--------------------------|----------------------------|\n| order id starting with ORD | number of packages | weight in lbs | Y/N | description of the article |\n\n## Carrier Information Table\n| HANDLING UNIT QTY | HANDLING UNIT TYPE | PACKAGE QTY | PACKAGE TYPE | WEIGHT WEIGHT | H.M.\u25a0(X) | COMMODITY DESCRIPTION COMMODITY DESCRIPTION | LTL ONLY NMFC # | LTL ONLY CLASS |\n|---------------------------|---------------------------|------------------|--------------|--------------------|----------|---------------------------------------------|-----------------|----------------|\n| Quantity of handling unit | Type of the handling unit | Package qunatity | Package type | Weight of the unit | H.M | Description of the Unit | NMFC number | LTL class |\n\n\n## Except as noted Date\nDate of the Carrier exeptance in the signature area",
"modelId": {
"__rl": true,
"mode": "list",
"value": "models/gemini-3.1-flash-lite",
"cachedResultName": "models/gemini-3.1-flash-lite"
},
"options": {},
"resource": "document",
"inputType": "binary",
"binaryPropertyName": "attachment_0"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "b1353396-fa19-4868-9ed2-6dee7dd03968",
"name": "AI Document Analyzer Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
960,
224
],
"parameters": {
"text": "={{ $json.content.parts[0].text }}",
"options": {
"systemMessage": "Structure the user message and return valid JSON using the given JSON schema. Make sure to only output the JSON and nothing else. "
},
"promptType": "define",
"needsFallback": true,
"hasOutputParser": true
},
"typeVersion": 3.1
},
{
"id": "782d134f-39be-4b9a-b0f8-75d5cd7d3ed4",
"name": "Post to Webhook API",
"type": "n8n-nodes-base.httpRequest",
"position": [
1664,
224
],
"parameters": {
"url": "https://webhook.site/ea6eb8ec-05d4-4804-9779-fd2d0704e141",
"method": "POST",
"options": {},
"jsonBody": "={{ $json.output }}",
"sendBody": true,
"specifyBody": "json"
},
"typeVersion": 4.4
},
{
"id": "d16ab511-134a-4d46-a5b4-1ae9829fd72c",
"name": "AI Validation Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1984,
224
],
"parameters": {
"text": "={{ $('Validate Data with Code').item.json.output }}",
"options": {
"systemMessage": "You are an agent that answers emails. You will receive data from a workflow, that checked if an bill of lading has all necessary information in it. You only get messages where all is fine. Be sure to write a nice message of acceptance and list the items. Be sure to structure the message with a nice HTML layout. You will use your GMAIL tool for sending the message, which accpets HTML. "
},
"promptType": "define",
"needsFallback": true
},
"typeVersion": 3.1
},
{
"id": "4bbc76c1-6223-4808-9653-d9c77d759179",
"name": "Send Gmail Message",
"type": "n8n-nodes-base.gmailTool",
"position": [
2176,
448
],
"parameters": {
"sendTo": "={{ $('When Email Received').item.json.from.value[0].address }}",
"message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
"options": {},
"subject": "=RE: {{ $('When Email Received').item.json.headers.subject }}"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.2
},
{
"id": "01f8c846-2e17-4fc4-b3bf-60253b16af89",
"name": "Gemini Main Analysis 1",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
928,
448
],
"parameters": {
"options": {},
"modelName": "models/gemini-3.1-flash-lite"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.1
},
{
"id": "3218d320-141a-44f9-9d36-fd6d317f23c3",
"name": "Gemini Fallback Analysis 1",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
1056,
448
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.5-flash"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.1
},
{
"id": "bc2b6ced-18ff-45f6-b1ca-24b8a6102c6d",
"name": "Gemini Main Analysis 2",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
1920,
448
],
"parameters": {
"options": {},
"modelName": "models/gemini-3.5-flash"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.1
},
{
"id": "466db66a-9f51-4857-babd-8e95b5b8a00d",
"name": "Gemini Fallback Analysis 2",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
2048,
448
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.5-flash"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.1
},
{
"id": "6dd651ec-a8c9-43be-bb3b-eea04b9db574",
"name": "Parse Structured Output",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1184,
448
],
"parameters": {
"jsonSchemaExample": "{\n \"shipper\": {\n \"sid\": \"ACME Corporation\",\n \"name\": \"ACME Corporation\",\n \"address\": \"1234 Industrial Blvd\",\n \"city_state_zip\": \"Springfield, IL 62701\"\n },\n \"consignee\": {\n \"cid\": \"CUST-9988\",\n \"name\": \"John Doe\",\n \"address\": \"42 Elm Street\",\n \"city_state_zip\": \"Shelbyville, IL 62565\"\n },\n \"shipment\": {\n \"bill_of_lading_number\": \"BOL-2026-00847\",\n \"carrier_name\": \"Swift Freight LLC\",\n \"trailer_number\": \"TRL-4821\",\n \"seal_numbers\": [\"SL-002\", \"SL-003\"],\n \"except_as_noted_date\": \"2026-06-01\"\n },\n \"customer_orders\": [\n {\n \"customer_order_number\": \"ORD-8821-A\",\n \"packages\": 4,\n \"weight_lbs\": 320,\n \"additional_shipper_info\": \"Laptop computers \u2013 batch A\"\n },\n {\n \"customer_order_number\": \"ORD-8821-B\",\n \"packages\": 2,\n \"weight_lbs\": 180,\n \"additional_shipper_info\": \"Monitors 27in \u2013 2 units\"\n },\n {\n \"customer_order_number\": \"ORD-8822\",\n \"packages\": 6,\n \"weight_lbs\": 210,\n \"additional_shipper_info\": \"Office chairs \u2013 disassembled\"\n },\n {\n \"customer_order_number\": \"ORD-8823\",\n \"packages\": 1,\n \"weight_lbs\": 45,\n \"additional_shipper_info\": \"Networking switch \u2013 48-port\"\n }\n ],\n \"carrier_line_items\": [\n {\n \"handling_unit\": { \"qty\": 4, \"type\": \"PLT\" },\n \"package\": { \"qty\": 4, \"type\": \"BOX\" },\n \"weight_lbs\": 320,\n \"hazardous_materials\": false,\n \"commodity_description\": \"Laptop Computers Model X-500\",\n \"nmfc_number\": \"61400\",\n \"class\": 85\n },\n {\n \"handling_unit\": { \"qty\": 2, \"type\": \"PLT\" },\n \"package\": { \"qty\": 2, \"type\": \"BOX\" },\n \"weight_lbs\": 180,\n \"hazardous_materials\": false,\n \"commodity_description\": \"27in LCD Monitors\",\n \"nmfc_number\": \"44070\",\n \"class\": 70\n },\n {\n \"handling_unit\": { \"qty\": 6, \"type\": \"PLT\" },\n \"package\": { \"qty\": 6, \"type\": \"CTN\" },\n \"weight_lbs\": 210,\n \"hazardous_materials\": false,\n \"commodity_description\": \"Office Chairs \u2013 KD packed\",\n \"nmfc_number\": \"56100\",\n \"class\": 85\n },\n {\n \"handling_unit\": { \"qty\": 1, \"type\": \"PLT\" },\n \"package\": { \"qty\": 1, \"type\": \"BOX\" },\n \"weight_lbs\": 45,\n \"hazardous_materials\": true,\n \"commodity_description\": \"48-Port Network Switch\",\n \"nmfc_number\": \"63010\",\n \"class\": 70\n }\n ]\n}"
},
"typeVersion": 1.3
},
{
"id": "ceee5101-e519-4728-902a-d4d488275da7",
"name": "Validate Data with Code",
"type": "n8n-nodes-base.code",
"position": [
1392,
224
],
"parameters": {
"language": "pythonNative",
"pythonCode": "# Loop over input items and add a new field called 'my_new_field' to the JSON of each one\nfor item in _items:\n customer_orders = item[\"json\"].get(\"customer_orders\", [])\n carrier_line_items = item[\"json\"].get(\"carrier_line_items\", [])\n\n mismatches = []\n\n for order in customer_orders:\n order_number = order.get(\"customer_order_number\")\n order_pkgs = order.get(\"packages\")\n order_weight = order.get(\"weight_lbs\")\n\n # Find matching carrier line item by commodity description or index\n matched_carrier = next(\n (c for c in carrier_line_items if c.get(\"package\", {}).get(\"qty\") == order_pkgs),\n None\n )\n\n if matched_carrier is None:\n mismatches.append({\n \"order_number\": order_number,\n \"reason\": \"No matching carrier line item found\",\n \"order_packages\": order_pkgs,\n \"order_weight_lbs\": order_weight\n })\n else:\n carrier_pkgs = matched_carrier.get(\"package\", {}).get(\"qty\")\n carrier_weight = matched_carrier.get(\"weight_lbs\")\n\n pkg_match = order_pkgs == carrier_pkgs\n weight_match = order_weight == carrier_weight\n\n if not pkg_match or not weight_match:\n mismatches.append({\n \"order_number\": order_number,\n \"reason\": \"Package count or weight mismatch\",\n \"order_packages\": order_pkgs,\n \"carrier_packages\": carrier_pkgs,\n \"packages_match\": pkg_match,\n \"order_weight_lbs\": order_weight,\n \"carrier_weight_lbs\": carrier_weight,\n \"weight_match\": weight_match\n })\n\n all_match = len(mismatches) == 0\n\n item[\"json\"][\"validation\"] = {\n \"all_match\": all_match,\n \"mismatches\": mismatches if not all_match else []\n }\n\nreturn _items"
},
"typeVersion": 2
},
{
"id": "8006f54d-f329-4c83-9ca2-48f0950ed61e",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-128,
640
],
"parameters": {
"color": "#BAD9FE",
"width": 480,
"height": 112,
"content": "## Get help with the setup and more workflwos\n\n vylos-ai.com/"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"binaryMode": "separate",
"executionOrder": "v1"
},
"versionId": "d17c4935-1116-4142-8907-9d965a95a9f2",
"connections": {
"Send Gmail Message": {
"ai_tool": [
[
{
"node": "AI Validation Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Post to Webhook API": {
"main": [
[
{
"node": "AI Validation Agent",
"type": "main",
"index": 0
}
]
]
},
"When Email Received": {
"main": [
[
{
"node": "Analyze Document with Gemini",
"type": "main",
"index": 0
}
]
]
},
"Gemini Main Analysis 1": {
"ai_languageModel": [
[
{
"node": "AI Document Analyzer Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Gemini Main Analysis 2": {
"ai_languageModel": [
[
{
"node": "AI Validation Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Parse Structured Output": {
"ai_outputParser": [
[
{
"node": "AI Document Analyzer Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Validate Data with Code": {
"main": [
[
{
"node": "Post to Webhook API",
"type": "main",
"index": 0
}
]
]
},
"AI Document Analyzer Agent": {
"main": [
[
{
"node": "Validate Data with Code",
"type": "main",
"index": 0
}
]
]
},
"Gemini Fallback Analysis 1": {
"ai_languageModel": [
[
{
"node": "AI Document Analyzer Agent",
"type": "ai_languageModel",
"index": 1
}
]
]
},
"Gemini Fallback Analysis 2": {
"ai_languageModel": [
[
{
"node": "AI Validation Agent",
"type": "ai_languageModel",
"index": 1
}
]
]
},
"Analyze Document with Gemini": {
"main": [
[
{
"node": "AI Document Analyzer Agent",
"type": "main",
"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.
gmailOAuth2googlePalmApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This workflow triggers on a Gmail message from a specific sender, extracts bill of lading data from an email attachment using Google Gemini, validates the extracted values with Python, posts the structured JSON to a webhook URL, and replies to the sender with an HTML acceptance…
Source: https://n8n.io/workflows/16049/ — 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 workflow monitors Gmail for unread emails from a specific sender, classifies attached documents with Google Gemini, then extracts and validates structured data for bills of lading, invoices, and
This Shopify AI automation is an advanced n8n-powered workflow that transforms Shopify product collections into SEO-optimized blog articles with images, while maintaining full visibility and control t
This workflow is designed for e-commerce, marketing teams, or creators who want to automate the production of high-quality, AI-generated product visuals and ad creatives.
CV → Match → Screen → Decide, all automated
This n8n workflow automates sales processes using AI agents integrated with Airtable as a CRM and Gmail for email handling. It consists of two main workflows: one for handling Airtable status changes