A8gent
All articles

Technical

contents.parts must not be empty: 5 Causes of the Gemini 400 Error in n8n

Google's API rejected the request because one message in it had no content. In n8n that empty message is usually the prompt, the system message, a binary attachment that was not an image, or a line in chat memory. Two of the causes were n8n bugs that are fixed in current versions.

A8gentAutomation practiceNovember 17, 20269 min read

Short answer: "contents.parts must not be empty" means n8n sent Gemini a message with no content, and Google rejected the whole request. The most common cause is the agent's prompt resolving to an empty string, for example an expression pointing at a field that is blank or missing. Open the chat model sub-node's input in the execution log, find the empty Human, System or AI line, and fix the expression or data that produced it.

Contents
  1. The Short Answer
  2. The 5 Causes at a Glance
  3. Cause 1: The Prompt Resolved to an Empty String
  4. Cause 2: The System Message Is Empty
  5. Cause 3: A File That Is Not an Image (Fixed in n8n 1.91.0)
  6. Cause 4: A Failing Tool (Fixed in n8n 1.105.0)
  7. Cause 5: An Empty Message in Chat Memory
  8. Similar Gemini 400s That Are Not This Error
  9. Still Broken? Check These in Order
  10. How to Stop It Coming Back
  11. Sources
  12. FAQ

The Short Answer

In n8n the error usually appears on the Google Gemini Chat Model sub-node and reads like this:

Bad request - please check your parameters
[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse: [400 Bad Request] * GenerateContentRequest.contents[4].parts: contents.parts must not be empty.

A variant names the system message instead:

GenerateContentRequest.system_instruction.parts: contents.parts must not be empty.

Google's Gemini API takes a list of messages, and each message is a list of parts: text, an image, a function call. A message with zero parts is invalid. The LangChain library n8n uses to talk to Gemini only adds a text part when the text is not empty, so any empty message n8n builds arrives at Google with no parts, and Google returns a 400.

First check: open the failed execution and select the Gemini chat model sub-node. Its input shows the messages it sent, as lines starting System:, Human: and AI:. Look for one with nothing after the colon, or with [].

The 5 Causes at a Glance

SymptomCauseFixHow to confirm
contents[0] or [1], every run with this inputThe prompt resolved to an empty stringFix the expression, filter empty itemsThe current Human: line in the model input is blank
Error names system_instruction.partsThe system message is emptyGive it text, or remove itThe System: line is blank
Last message is Human: [], a file is attachedNon-image binary passed to the agent (before 1.91.0)Update n8n, or strip binary firstInput item has a PDF or other binary
Higher index, right after a tool callA failing tool, often MCP (before 1.105.0)Update n8nA tool sub-node errored in the same run
Higher index, one user only, every messageAn empty message stored in chat memoryClear that session's historyA blank AI: or Human: line in the loaded history

As a rough guide to the index: in the reports we read, contents[1] pointed at a message right after the first prompt, and contents[4] at a turn after several tool calls. A low number means the input you just sent. A high number means history or tools.

Cause 1: The Prompt Resolved to an Empty String

The AI Agent's Prompt is either taken from a chatInput field on the previous node, or defined by you, usually with an expression. If the prompt is undefined, n8n stops before calling the model with a different error, No prompt specified. If it is an empty string, n8n's check lets it through, and the user message reaches Gemini with no parts.

Typical sources: a chat message with no text (an image or voice note), or an empty form field.

How to confirm it: in the model sub-node's input, the last Human: line is empty. Then open the node before the agent and check the field your expression reads.

The fix: correct the expression, and stop empty items reaching the agent. Put an If node in front of it with a string condition:

Value:     {{ $json.chatInput }}
Operation: is not empty

Send the false branch to a reply such as "Please send your question as text". Our post on Can't get data for expression covers expressions that point at the wrong place.

Cause 2: The System Message Is Empty

When the error names system_instruction.parts, the empty message is the system prompt. In the main forum thread, the first report was exactly this variant.

It happens when System Message in the agent's options is an expression that resolves to nothing, for example text pulled from a Google Doc or a database row that came back blank, or when the field was cleared but left in place.

How to confirm it: the System: line in the model input is empty, or missing its text.

The fix: give the system message fixed text, and append any dynamic part to it, so it is never blank:

You are the support assistant for our store.
{{ $json.extraInstructions ?? '' }}

Cause 3: A File That Is Not an Image (Fixed in n8n 1.91.0)

The AI Agent has an option, Automatically Passthrough Binary Images, that sends images on the input item to the model. Before n8n 1.91.0, if the item carried binary data that was not an image, such as a PDF, the agent still added a message for it, with no content. It shows up at the end of the model input as:

Human: []

Gemini rejected it; other providers tolerated it, which is why switching provider seemed to fix it. The cause was traced in GitHub issue #14023, and pull request #14871, "Prevent adding empty binary message", fixed it in n8n 1.91.0.

This explains two "fixes" in the forum thread. Users reported that putting a pass-through Code node before the agent, or removing a Merge node, made the error go away. Neither is a fix in itself. It is very likely that those changes stopped the binary data reaching the agent.

How to confirm it: the last message is Human: [] and the agent's input item has a binary property.

The fix: update n8n. On an older instance, turn off Automatically Passthrough Binary Images if you do not need images, or drop the binary data in a Code node before the agent:

return $input.all().map(item => ({ json: item.json }));

Cause 4: A Failing Tool (Fixed in n8n 1.105.0)

On n8n 1.97.1, GitHub issue #16605 showed that when an MCP Client tool returned an error, the next call to Gemini failed with contents[4].parts: contents.parts must not be empty. The tool's error was dropped instead of being passed back to the model as a result. Pull request #17558, "Do not throw on tool errors, instead return error message", fixed it in n8n 1.105.0.

How to confirm it: the index is above 1, and a tool sub-node shows an error in the same execution.

The fix: update to 1.105.0 or later, then fix the tool itself. Our notes on tool calling and MCP cover how tool results flow back to the model.

Cause 5: An Empty Message in Chat Memory

With a memory sub-node attached, the agent sends the stored history for the session along with the new prompt. If the history holds a message with no text and no tool call, for example from an earlier turn that produced nothing, it becomes a message with no parts on every later turn. That is how the error ends up affecting one user and not another.

This follows from the conversion rule above, not from a documented n8n bug, so confirm it first.

How to confirm it: the index is above 1, no tool failed, and the history in the model input contains an AI: or Human: line with nothing after it. A new session ID with the same message works.

The fix: clear that session's history. For Postgres Chat Memory, delete the session's rows from the memory table. For Simple Memory, switch the user to a new session key. Then fix whatever let an empty turn through, usually Cause 1 on an earlier message. Session keys are covered in our post on No session ID found.

Similar Gemini 400s That Are Not This Error

Gemini validates tool definitions strictly too. These come from tool schemas, not empty messages:

MessageCause
parameters.properties: should be non-empty for OBJECT typeA tool that takes no parameters. An n8n engineer in issue #12109 suggested giving the tool a parameter as a workaround.
type: must be specified when not using one_of, any_of or all_of fieldsA tool parameter with no type in its schema, reported with HTTP Request and MCP tools.

Advice to ignore: one reply in the forum thread says tool names must not contain underscores. Another user tried it and it did not help, and we found no source that supports it.

Still Broken? Check These in Order

  • Read the messages in the chat model sub-node's input. The empty one is there.
  • Check your n8n version in the About n8n panel. Below 1.91.0, Cause 3 applies. Below 1.105.0, Cause 4 applies.
  • Run the same input through a Basic LLM Chain with the same Gemini model. If it works, the agent added the empty message: binary, memory or a tool.
  • Disconnect the memory sub-node and run once. If it passes, it is Cause 5.
  • Disconnect tools one at a time. If removing one fixes it, read that tool's output and schema.
  • Pin the input data on the node before the agent and check every field the prompt uses.

How to Stop It Coming Back

Never let an empty input reach a model. An If node with "is not empty" in front of every agent costs nothing and catches the most common cause.

Keep the system message static at its core. Append dynamic text to fixed text so it cannot resolve to blank.

Stay on a current n8n version. Two of these five causes are bugs that are fixed in every 2.x release.

Add an error workflow that starts with the Error Trigger node, so a failed run tells you which input caused it. See error handling.

If you are weighing Gemini against other providers for agent work, our Google Gemini model page covers pricing and trade-offs. How the AI Agent node builds the messages it sends, and what it adds from memory and tools, is the subject of our free lesson on the AI Agent node. If your agent also returns JSON, see Model output doesn't fit required format.

The n8n AI Agents course builds working agents end to end: tools, memory, structured output, RAG, error handling with human fallback, and deployment, with importable workflow JSON for every lesson.

Sources

Checked against GitHub issues, n8n release notes, n8n's documentation, LangChain source and the community forum on 17 November 2026.

FAQ

What does "contents.parts must not be empty" mean in n8n?
Google's Gemini API rejected the request because one of the messages n8n sent had no content. Every message must contain at least one part, such as text or an image. The empty message is usually the prompt, the system message, an attachment or a line from chat memory.
Why does it work with OpenAI but not with Gemini?
Gemini validates empty messages strictly and other providers are more tolerant. The empty message is still there with OpenAI. Switching provider hides the problem, so find the empty message instead.
What does the number in contents[N] mean?
It is the position of the empty message in the request, counted from 0. A low number points at the input you just sent. A higher number points at earlier history from memory or a turn after a tool call.
What does system_instruction.parts must not be empty mean?
The system message was empty. Check the System Message option on the AI Agent. If it is an expression, make sure it cannot resolve to an empty string, for example by starting it with fixed text.
Why does adding a Code node before the agent fix it?
Very likely because it stops binary data reaching the agent. Before n8n 1.91.0, a non-image file on the input item made the agent add an empty message. Updating n8n fixes the cause directly.
Which n8n version fixed the Gemini empty message bugs?
The empty binary message was fixed in n8n 1.91.0 and the failing MCP tool case in n8n 1.105.0. Every n8n 2.x release includes both. If you still see the error on a current version, the empty message is coming from your data.

If this resonated

Module 02 is the long version of this post.

Eval set, refusal pattern, kill switch. Build it in a weekend.

All postsLast verified 2026-11-17

Done for you

Want this built for your business?

Tell us the workflow. We scope, build, and ship the agent with guardrails and the numbers to prove it worked. The scoping call is free.

Free scoping call. You own the code.

Request a scoping call