GoogleGenerativeAI Error [400 Bad Request]: contents.parts must not be empty

Same issue… it works with any other AI API. Any idea? { "nodes": [ { "parameters": { "promptType": "define", "text": "=Test prompt", "options": {} }, "type": "@n8n/n8n-nodes-langchain.agent", "typeVersion": 1.9, "position": [ 2060, -300 ], "id": "e9a3c7ef-f506-4102-b807-ead6a28b3ba0", "name": "Subtitles_corrector", "retryOnFail": false }, { "parameters": { "modelName": "models/gemini-2.0-pro-exp", "options": {} }, "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini", "typeVersion": 1, "position": [ 2020, -40 ], "id": "81a5ca5e-54dd-4559-a3af-460d2f33c88c", "name": "Google Gemini Chat Model", "credentials": { "googlePalmApi": { "id": "rC4dIbfdk9ok4aeT", "name": "Google Gemini(PaLM) Api account" } } }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n item.json.myNewField = 1;\n}\n\nreturn $input.all();" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1720, -320 ], "id": "63f824e4-6603-4a66-9e7c-93e167dccaf3", "name": "Code1" } ], "connections": { "Subtitles_corrector": { "main": [ [] ] }, "Google Gemini Chat Model": { "ai_languageModel": [ [ { "node": "Subtitles_corrector", "type": "ai_languageModel", "index": 0 } ] ] }, "Code1": { "main": [ [ { "node": "Subtitles_corrector", "type": "main", "index": 0 } ] ] } }, "pinData": {}, "meta": { "templateCredsSetupCompleted": true, "instanceId": "1f60cc61b3de7a18b76e0380fb108007748053d41b71b0aab2b4721f2a106b06" } }

It’s very simple — just delete all the AI Agent nodes and recreate them. It will work normally. Give me a Like if this solved your problem.

1 Like

can’t afford to do that in production env, for n number of users

Same Issue

Man, you’re absolutely right. I basically lost 4 hours on this issue when I came across your post. I thought it would be worth trying, I recreated my AI Agent in a fresh workflow, that is - everything recreated from scratch and bang! my Google Calendar event gets created exactly as it should.

O problema aqui foi resolvido! Em algumas interações, o agente respondia “vazio” sem conteúdo algum e isso era armazenado na memória de chat do postgressql, ai quando ela ia fazer uma nova interação e consultava a memória o erro aparecia, nesse caso já está errado o agente responder vazio, mas fazer o que né. Foi só limpatar a memória da mensagem vazia e voltou:


Depois disso, fiz um if para evitar essas coisas:

Espero que ajude alguém.

2 Likes

Hello Matheus, this is the solution we need!! Thank you!

Yes the reason why this is not working is the Chat Memory. As the entire dialogue is stored there and sometimes there is no answer. But this is definitely more of a bug than an actual issue.

If you’re using Postgres as memory in an AI agent, this error can occur because, for some reason, empty content data ends up being stored in memory. When the model later loads it, it misinterprets it as receiving empty data, which causes the issue. The solution I applied was to manipulate the most recent chat history in Supabase that was empty, and after that, everything worked normally.

Just remove the chat memory from the AI Agent or change the key and that will fix Your issue. Very simple.

Aqui foi a causa também Matheus, agradeço demais por compartilhar.

Eu uso o MongoDB para a memória, mas o ajuste foi o mesmo:

Em algumas execuções recebia o erro:

A causa é que em alguns momentos a IA pode gravar um log de memória com content vazio e se fizer isso, vai quebrar.

Antes:

Log vazio no mongo:

Fiz o update do content para 0:

Aí funcionou: