Mapping Receipt Data to Google Sheets with AI

Resumen

Setting up an AI agent in n8n that reads receipt images and logs the data into Google Sheets requires connecting three pieces: a chat model, a tool, and a well crafted prompt. This walkthrough is for builders who want to automate expense tracking using OpenAI and Telegram as the entry point.

How do you connect a chat model to an n8n AI agent?

Inside n8n, you click the plus icon and search for AI agent. By default, your agent shows three branches: chat model, memory, and tool. Each one plays a specific role in how your automation thinks and acts.

  • Chat model: lets you pick the LLM you want to use.
  • Memory: enables context retention across interactions.
  • Tool: connects external services like Google Sheets.

For the chat model, you click the plus on that branch and choose OpenAI. Once your credentials are connected, you select GPT 4o mini as the model and return to the canvas [01:00].

What is an AI agent in n8n? It's a node that orchestrates an LLM with tools and memory so it can reason, decide, and execute actions like writing to a spreadsheet or replying on Telegram.

How do you map Google Sheets columns to AI extracted data?

The Google Sheets file in this setup is named Agente registra gastos and contains six columns: fecha, glosa descripción, monto, proveedor o comercio, NIT, and método de pago. Your job is to match each column with the text the agent extracts from the image.

Back in n8n, on the tool branch you click plus and search Google Sheets. With credentials already configured, you set:

  • Tool description: set automatically.
  • Resource: shared sheet within document.
  • Operation: append row.

You pick append row because every image the agent reads should generate a new line in your sheet. Then you select the document Agente registra gastos and its single sheet [02:30].

Why use the from AI notation in n8n?

In mapping column mode you choose map each column manually. For each field you switch to expression and write the double curly brace notation with $fromAI(). n8n autocompletes the method, and inside the parentheses you type the keyword the AI should look for.

  • Fecha receives $fromAI('fecha').
  • Glosa descripción uses $fromAI('descripcion').
  • Monto uses $fromAI('monto').
  • Proveedor uses $fromAI('comercio').
  • NIT uses $fromAI('NIT').
  • Método de pago uses $fromAI('metodo de pago').

This tells the agent which slice of the extracted text belongs in each column [03:30].

How do you write the prompt for an n8n AI agent?

Double click the AI agent node and pick connected chat trigger node, then leave the source as define below. That option opens a user message field where you paste the prompt.

The prompt frames the agent as a financial assistant that makes humans more productive. It lists every field to extract, walks through the reasoning step by step for desglose, descripción, NIT, and pago, includes examples of correct registries, and clarifies what the agent should not do. The output must be returned in JSON format [05:00].

For the date, the prompt uses $now so n8n captures the exact moment the workflow runs as the current date. You paste the full text into prompt or user message, confirm the field is in expression mode, and verify the $now variable is active.

What does $fromAI do in n8n? It pulls a specific piece of information from the LLM's interpretation of the input and places it where you call it, like a column in Google Sheets.

How do you send the agent response back to Telegram?

After the agent writes to Sheets, you want a confirmation back to the user. You click plus, search Telegram, and pick send a text message. With credentials linked, you keep resource and operations on message.

In chat ID you switch to expression and write the double brace notation referencing the trigger node. If your first Telegram node is named Trigger Telegram, the expression becomes $('Trigger Telegram').item.json.message.messageId. That ID guarantees the reply lands in the same chat session [07:30].

In text, you also use expression and write {{ $json.output }}, which is the final response the AI agent produces. With that, the loop closes: image in, structured data into Sheets, confirmation back on Telegram.

Which skills are you practicing here?

  • Prompt engineering with explicit reasoning steps and JSON output.
  • Field mapping between unstructured text and structured spreadsheet columns.
  • Expression syntax in n8n using $fromAI, $now, and node references.
  • Tool orchestration combining OpenAI, Google Sheets, and Telegram inside a single agent.

With every node configured, the automation is ready to be tested end to end. Drop in the comments which expense fields you would add to your own version of this agent.