DEV Community

Robert Breen
Robert Breen

Posted on

n8n: Talk to your Google Sheets with an AI Agent (and why it sometimes gets the math wrong)

Spreadsheets are where a lot of office work lives: the client list, the sales log, the invoice tracker. n8n ships a popular chat template that lets you ask a Google Sheet questions in plain English, and it feels like magic the first time. It also has a habit that surprises people: it is great at looking things up and sometimes confidently wrong at math. Here is how the setup works, and how to keep the answers honest.

I teach this at Stepthrough, so the walkthrough at the end is my own free lesson. The rest of this post stands on its own.

What you are building

Three pieces, wired together on the n8n canvas:

  1. A Chat Trigger that gives you a chat box.
  2. An AI Agent node that reads your question and decides what to do.
  3. A Google Sheets tool the agent can call to fetch rows, plus a chat model (OpenAI, in this case) that does the thinking.

The flow looks like this:

Chat message -> AI Agent -> (chat model + Google Sheets tool) -> answer
Enter fullscreen mode Exit fullscreen mode

The template opens with empty credentials and no data, so the actual work is connecting your own OpenAI key, authorizing Google Sheets, and pointing the tool at a real spreadsheet.

Step 1: Prepare a sheet the agent can read

Agents do much better with a boring, clean table. Use one header row, one record per row, and no merged cells. A made-up example for a small consulting firm:

Client Industry Invoice Status Due
Harbor Dental Healthcare 4200 Paid 2026-09-30
Brightline Legal Legal 6800 Overdue 2026-09-15
Maple Accounting Finance 3100 Open 2026-10-20

Clear column names matter more than you think. The agent reads them to figure out what it can ask for.

Step 2: Connect the Google Sheets tool

Open the Google Sheets tool node, choose your credential, then pick the document and the sheet. Set the operation to read rows. A common mistake is leaving the tool on a placeholder document, which makes the agent say the sheet is empty when it simply is not looking at yours.

A tool description helps the agent decide when to use it. Something like:

{
  "name": "client_invoices",
  "description": "Returns every row of the client invoice sheet. Columns: Client, Industry, Invoice, Status, Due."
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Give the agent a short system prompt

Without guidance the agent improvises. A few plain sentences go a long way:

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.
Enter fullscreen mode Exit fullscreen mode

Step 4: Ask it things

Try lookups first: "Which clients are overdue?" or "When is Maple Accounting due?" These work well because the agent only has to find rows and quote them.

Why it sometimes gets the math wrong

Now ask: "What is the total of all open and overdue invoices?" Sometimes you get 9,900 (correct), and sometimes a number that is close but off.

The reason is that a language model predicts text. It is not a calculator. When it adds a column of numbers, it is producing what a plausible sum looks like. With three rows that usually works. With three hundred, rows get skipped, duplicated, or truncated, because the tool may only hand back part of the sheet and the model does not always notice.

Three habits that fix most of it:

  • 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. The spreadsheet is a calculator; let it be one.
  • Watch the row limit. If the sheet is long, filter before returning rows, for example only Status = Overdue, so the model is not asked to hold the whole table in its head.

A good rule of thumb: use the agent for finding and explaining, and use formulas for adding. If a number is going into a report or an email to a client, check it against the sheet once.

Where this is useful in an office

  • A bookkeeper asking "who has not paid in 30 days?" without building a filter.
  • An account manager checking a client's renewal date mid-call.
  • An operations lead getting a plain-English summary of a weekly log before a meeting.

None of that requires code beyond what you have seen above, and none of it should touch real client data while you are still learning. Practice on a made-up sheet first.

Try it step by step

If you would rather click through it than read about it, I built a free practice version. You work in a practice copy of the n8n editor, it checks each step, and nothing touches your real accounts. It takes about 8 minutes:

n8n: Talk to Your Google Sheets with ChatGPT (free lesson)

Have you hit the "confident wrong number" problem with an agent in your own workflows? I would like to hear how you solved it.

Top comments (0)