Google Sheets Overwrites row

I’m struggling with an AI Agent workflow and hoping someone can offer some guidance.

My setup involves:

  1. Getting text from a document via OCR (which contains multiple transactions, like a bank statement).
  2. Passing this text to an AI Agent node (using Mistral).
  3. The AI Agent has access to the Google Sheets tool and its goal is to identify each debit transaction and add it as a unique row in my sheet using the tool.

However, the problem occurs when it sends this data to Google Sheets: it always overwrites the current data on the same row. It doesn’t append new rows below for the subsequent transactions identified in the following runs.

To try and fix this, I’ve attempted several things:

  • Using different prompts.
  • Reformatting the Google Sheet itself (setting columns as numbers, plain text, etc.).
  • Applying other advice I found on this matter on this forum.
  • Trying both manual instructions for the Google Sheets tool within the prompt (like telling it to “create a new row”) and what might be considered automatic “append row” functionalities.

Unfortunately, nothing has worked so far – the data consistently overwrites the same row.

Has anyone else experienced this? Any ideas on how to get the Google Sheets action (triggered by the AI Agent) to append new rows correctly instead of overwriting?

2 Likes

I think the AI agent by default goes back to updating A2 or first blank row it detects. I dont think the AI agent is able to store the current index of the google sheet. What if you let the Agent just output parsed data and then you append google sheets outside the agent using Google sheet append node?

Yep, I’ve actually tried that too. The tricky part seems to be that there are 10+ entries coming in within the same second, and I’m not sure how Google handles that behind the scenes.
I’ve already tested pulling the data out of the agent and sending it to Google Sheets one by one, but it’s still too fast — and when I add a delay, it just slows everything down evenly, without solving the core issue.

Got any other ideas I could try?

I am guessing you are parallel processing records to google sheets. I don’t think Google provides row level isolation like it is in a database. what if you use SplitInBatches with batch size =1 . that way you emit one transaction at a time and that single transaction flows to google sheets → append node row. after processing if you use wait node with a delay that might solve your issue

I do have the same issue and didn’t find a solution now. My workaround for now is to call the ai to report to me after every single step. Here is my prompt:

You are a workflow agent responsible for processing LinkedIn contact search results and writing them to Google Sheets one at a time.

TASK OBJECTIVE

Your mission is to ENSURE that each contact is APPENDED INDIVIDUALLY to the Google Sheet, and ONLY AFTER the write operation completes, you must CONFIRM success to the user and THEN move to the next contact. You MUST ENFORCE SEQUENTIAL EXECUTION with reporting between each write.

INPUT PARAMETERS

  • Keyword: {{ $json[“keyword”] }}
  • maxResults: {{ $json.maxResults }}
  • account: {{ $json.account }}

STEP-BY-STEP EXECUTION (CHAIN OF THOUGHTS)

  1. UNDERSTAND the task: You must first search for contacts via LinkedIn’s API and then write each result to Google Sheets individually.
  2. BASICS: You will receive a batch of contacts. You are to iterate over them one at a time.
  3. BREAK DOWN the task:
    • Step 1: Call the LinkedIn Search Contacts API with the keyword.
    • Step 2: For EACH contact returned:
      • WAIT for the Google Sheets Append operation to complete
      • ONCE CONFIRMED, send a message: "✅ Contact [Name or ID] successfully written to Google Sheets."
      • THEN continue to the next contact
  4. ANALYZE: If you do not wait for each Google Sheets node to finish, you risk multiple contacts being written in the same row or skipped due to concurrency issues.
  5. BUILD: Your loop MUST:
    • Execute the Google Sheets append synchronously
    • Await confirmation before moving forward
    • Log or report the success before continuing
  6. EDGE CASES:
    • IF a contact fails to write, CATCH the error, LOG it, and CONTINUE to the next
    • DO NOT halt the entire process on a single error
  7. FINAL BEHAVIOR: The agent must process entries in strict sequence, reporting success per entry

ENFORCED RULES

  • NEVER batch or parallelize writes to Google Sheets
  • ALWAYS WAIT for each append to finish before reporting or proceeding
  • ALWAYS report success explicitly after each individual entry

EXAMPLE FLOW

  1. Search returns 5 contacts.
  2. First contact is written → Google Sheets confirms → Agent reports success → Proceeds to second contact.
  3. Repeat until all contacts are processed.

For me, it worked to tell the AI Agent to wait 1 Second after every entry. But the solution is flaky and it is calling the chatGPT API after every entry.


I had a similar problem and managed to solve it without relying too much on the AI agent/models. Unfortunately, you have to remove the Sheets tool from the agent, because it simply couldn’t handle it that way. You need to instruct the agent to return the result in JSON format, with "column_name": "value" as in a typical JSON object. Unfortunately, I don’t know what to write in the prompt to prevent it from adding json at the beginning and at the end of the output—if anyone has figured this out, please let me know. I managed to work around it by adding a “function block” and a simple JS function that strips those unnecessary characters. This is necessary so that the “Split Out” block can split the data into separate table rows, which I then passed to the Sheets block, mapping the values from the JSON.

I have a similar problem. Webhook events are coming into a google sheet on a dedicated service account. If events arrive within 5 seconds of one another (which they do all the time) then Google Sheets will overwrite existing data even when Google sheets node is configured to Append only mode. They literally disappear, even though I can see them in the execution logs. We’re experiencing a lot of bugs across a lot of node types - n8n is caked in bugs. It’s not prod ready.

Maybe the problem from to the LLM Model
Did you tried with GPT 4.1 ? It’s a good model for code/task (4.1 mini if it’s too expensive)

Here is my testing on this topic.

Just solve another client’s issue yesterday.

If there is a service call Google Sheet append multiple times almost simultaneously. The problem will occur. Only one row being append.

For AI Agent I think we need to tell it not append it multiple times.
Let it collect all the result and then append it once with multiple rows.

@Anakin_Skywalker, how did you solve this ? I am facing the same issue and cannot use iterator because I want to use the google sheet node as a tool for the AI agent

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.