n8n: Talk to your Google Sheets with an AI Agent (and why it sometimes gets the math wrong)
Description and use
This guide explains how to set up an n8n chat agent to interact with Google Sheets, ensuring accurate answers and avoiding calculation errors.
Problem
The AI Agent in n8n can confidently provide incorrect sums when asked to calculate totals from Google Sheets.
Outcome
The workflow enables accurate, transparent interaction with Google Sheets via an AI Agent, reducing math errors by leveraging spreadsheet formulas and clear prompts.
Workflow
- Prepare a clean Google Sheet with a single header row and one record per row.
- Connect the Google Sheets tool node in n8n, select credentials, choose the document and sheet, and set operation to read rows.
- Provide a tool description such as {"name":"client_invoices","description":"Returns every row of the client invoice sheet. Columns: Client, Industry, Invoice, Status, Due."}.
- Add a short system prompt: "You answer questions about the client invoice sheet. Always read the sheet before answering. If the answer needs a calculation, show the rows you used. If you are not sure, say so instead of guessing."
- Ask lookup questions first (e.g., "Which clients are overdue?").
- When asking for totals, request the rows used or use a spreadsheet formula (e.g., a Summary column or pivot tab) to perform the calculation outside the model.
- Filter rows before returning them if the sheet is long to avoid exceeding the model’s context limit.
- Verify the agent’s answer against the sheet’s calculated value before using it in reports or emails.
Evidence
The agent reads your question and decides what to do.
Agents do much better with a boring, clean table. Use one header row, one record per row, and no merged cells.
The reason is that a language model predicts text. It is not a calculator.
Make it show its work. Asking for the rows it used lets you spot a missing record in seconds.
Do the math outside the model. Add a Summary column or a pivot tab in the sheet itself and have the agent read that figure.
- Record date: 2026-10-11T13:40:56.883Z