AutomationFlowsAI & RAG › Answer PDF Questions with Cited Answers Using Google Gemini, Gmail and Sheets

Answer PDF Questions with Cited Answers Using Google Gemini, Gmail and Sheets

ByOka Hironobu @okp29 on n8n.io

This workflow collects a question and PDF via an n8n form, uses Google Gemini to answer using only the document with citations, suggests follow-up questions, emails the results via Gmail, and logs the Q&A to Google Sheets. Receives a form submission that includes the user’s…

Event trigger★★★★☆ complexityAI-powered12 nodesForm TriggerGoogle GeminiChain LlmGoogle Gemini ChatGmailGoogle Sheets
AI & RAG Trigger: Event Nodes: 12 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #17954 — we link there as the canonical source.

This workflow follows the Chainllm → Form Trigger 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 →

Download .json
{
  "id": "TMqu0zvNAirJtBOj",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true
  },
  "name": "Ask questions about any PDF and get a cited answer with Gemini",
  "tags": [],
  "nodes": [
    {
      "id": "933acf57-13bc-444f-8175-e773bdc80d4a",
      "name": "Document Q&A Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        48,
        48
      ],
      "parameters": {
        "options": {
          "buttonLabel": "Ask",
          "respondWithOptions": {
            "values": {
              "formSubmittedText": "Thanks! Your answer is being prepared and will arrive by email shortly."
            }
          }
        },
        "formTitle": "Ask your document",
        "formFields": {
          "values": [
            {
              "fieldType": "email",
              "fieldLabel": "Your email",
              "requiredField": true
            },
            {
              "fieldLabel": "Question",
              "placeholder": "e.g. What is the notice period in this lease?",
              "requiredField": true
            },
            {
              "fieldType": "file",
              "fieldLabel": "Document",
              "multipleFiles": false,
              "requiredField": true,
              "acceptFileTypes": ".pdf"
            }
          ]
        },
        "formDescription": "Upload a PDF and ask a question - the AI reads the whole document to answer."
      },
      "typeVersion": 2.6
    },
    {
      "id": "da854f9a-118a-44b4-bc5d-7e182ba778e9",
      "name": "Read Document with Gemini",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "onError": "continueErrorOutput",
      "position": [
        272,
        48
      ],
      "parameters": {
        "text": "=Answer this question using only the attached document. Quote the exact clause or sentence you used, and if the document does not contain the answer, say so clearly. Question: {{ $json.Question }}",
        "modelId": {
          "__rl": true,
          "mode": "id",
          "value": "models/gemini-2.5-flash"
        },
        "options": {
          "maxOutputTokens": 1024
        },
        "resource": "document",
        "inputType": "binary",
        "binaryPropertyName": "Document"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bb36b781-d13a-492f-b5bc-14d9e8bf7043",
      "name": "Shape Answer",
      "type": "n8n-nodes-base.code",
      "position": [
        464,
        32
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const f = $('Document Q&A Form').item.json;\nlet ans = '';\nconst r = $json;\nif (typeof r.content === 'string') ans = r.content;\nelse if (r.text) ans = r.text;\nelse if (r.response) ans = r.response;\nelse ans = JSON.stringify(r).slice(0, 1500);\nreturn { email: f['Your email'], question: f.Question, answer: ans };"
      },
      "typeVersion": 2
    },
    {
      "id": "74a0e50a-7e8f-42f5-a303-926749512b6e",
      "name": "Suggest Follow-up Questions",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        784,
        32
      ],
      "parameters": {
        "text": "=Based on this question and answer about a document, suggest 3 useful follow-up questions the person might want to ask next. One per line, no numbering.\n\nQuestion: {{ $json.question }}\nAnswer: {{ $json.answer }}",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "abbc7a6d-2580-4334-8787-8178784ae5e5",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        784,
        192
      ],
      "parameters": {
        "options": {
          "temperature": 0.4
        },
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "0b2a0708-2f0c-433b-96e3-15a5f4028aa2",
      "name": "Email the Answer",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1344,
        32
      ],
      "parameters": {
        "sendTo": "={{ $(\"Shape Answer\").item.json.email }}",
        "message": "={{ \"Q: \" + $(\"Shape Answer\").item.json.question + \"\\n\\nA: \" + $(\"Shape Answer\").item.json.answer + \"\\n\\nYou might also ask:\\n\" + $json.text }}",
        "options": {},
        "subject": "={{ \"Answer: \" + $(\"Shape Answer\").item.json.question }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e3cf62eb-1950-4796-9ce5-bc6d0edb7c8f",
      "name": "Log Q&A",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        784,
        336
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Document QA"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Select your spreadsheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "6d3b3790-c78d-4045-8ac2-c33815dfdcb7",
      "name": "Email Read Failure",
      "type": "n8n-nodes-base.gmail",
      "position": [
        464,
        192
      ],
      "parameters": {
        "sendTo": "={{ $(\"Document Q&A Form\").item.json[\"Your email\"] }}",
        "message": "Sorry - we could not read your PDF. Please try again with a text-based PDF (not a scanned image) under 20MB.",
        "options": {},
        "subject": "We could not read your document",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9802ec19-8af3-43a4-991b-bbbd03012144",
      "name": "Overview Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -160
      ],
      "parameters": {
        "width": 536,
        "height": 636,
        "content": "## Ask questions about any PDF and get a cited answer with Gemini\n\n### How it works\nUpload a PDF and ask a question in plain language. Unlike templates that extract raw text first, this one sends the PDF straight to Google Gemini's native document understanding, so it reads layout, tables and long context and answers your exact question - quoting the clause or sentence it used, and saying so honestly when the document does not contain the answer. A Basic LLM Chain then suggests three smart follow-up questions you might want to ask next. The answer and follow-ups are emailed to you and the Q&A is logged to Google Sheets. Scanned or unreadable PDFs trigger a helpful email instead of a broken run.\n\n### Setup\n1. Connect Google Gemini (PaLM) API, Gmail and Google Sheets.\n2. Point the Log Q&A node at your spreadsheet (tab: Document QA).\n3. Open the form URL and upload a text-based PDF.\n\n### Customization tips\nAllow multiple documents at once, or return the answer instantly with a Respond to Webhook instead of email."
      },
      "typeVersion": 1
    },
    {
      "id": "189160db-6898-47eb-a1d4-19d1a42c2001",
      "name": "S1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 596,
        "height": 652,
        "content": "## 1. Upload & read (Gemini document)\nThe PDF goes straight to Gemini native document understanding, which answers the question with a citation. Unreadable PDFs email the user."
      },
      "typeVersion": 1
    },
    {
      "id": "57c2d495-5931-43e7-b406-276ffc4c345a",
      "name": "S2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 564,
        "height": 652,
        "content": "## 2. Follow-ups (Basic LLM Chain)\nGemini suggests three useful follow-up questions to ask next."
      },
      "typeVersion": 1
    },
    {
      "id": "b1295cc0-1749-4708-aa08-ffd5eef51522",
      "name": "S3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 656,
        "content": "## 3. Email & log\nEmail the cited answer plus follow-ups and log the Q&A to Sheets."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "5fda1ac8-0d18-4a82-a03d-4b9c5af2a069",
  "nodeGroups": [],
  "connections": {
    "Shape Answer": {
      "main": [
        [
          {
            "node": "Suggest Follow-up Questions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Q&A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Q&A Form": {
      "main": [
        [
          {
            "node": "Read Document with Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Suggest Follow-up Questions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Read Document with Gemini": {
      "main": [
        [
          {
            "node": "Shape Answer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email Read Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Suggest Follow-up Questions": {
      "main": [
        [
          {
            "node": "Email the Answer",
            "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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow collects a question and PDF via an n8n form, uses Google Gemini to answer using only the document with citations, suggests follow-up questions, emails the results via Gmail, and logs the Q&A to Google Sheets. Receives a form submission that includes the user’s…

Source: https://n8n.io/workflows/17954/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow collects a voice memo via an n8n form, transcribes it with Google Gemini, extracts a structured task list, emails the summary and tasks via Gmail, and appends each task as a new row in G

Form Trigger, Google Gemini, Chain Llm +4
AI & RAG

This workflow collects candidate applications via an n8n form, extracts resume text with Mistral AI, matches the candidate to an open role stored in Google Sheets and Google Docs, scores the fit using

Form, Form Trigger, Google Sheets +7
AI & RAG

Automate your lead intake, scoring, and outreach pipeline. This workflow collects leads from forms, enriches and scores them using Relevance AI, routes them by quality, and triggers the right follow-u

Form Trigger, HTTP Request, Chain Llm +6
AI & RAG

&gt; Transform your content ideas into viral Facebook posts with AI-powered automation in just 30 minutes!

Facebook Graph Api, Google Sheets, Chain Llm +4
AI & RAG

This workflow collects a PDF and study preferences via an n8n form, extracts its text, uses Google Gemini to generate flashcards, a quiz, key topics, and a study plan, then saves the cards and quiz to

Form Trigger, Chain Llm, Google Gemini Chat +3