Back
Open Source

Gemini can return HTTP 200 with no candidates. n8n used to crash.

n8n #43899 fixed Gemini nodes crashing when a blocked prompt returns 200, promptFeedback.blockReason and no candidates. The node now reports the block reason.

JB
Josué Barros
••2 min read

Gemini answers a blocked prompt with HTTP 200, promptFeedback.blockReason and no candidates. The vendor node read candidates directly, so Message a Model, Analyze, Transcribe, Generate and Edit crashed with TypeError: Cannot read properties of undefined.

This is one of the pull requests behind Six merged PRs in 72 hours. The series looks at the failure, the fix and the review evidence, one merge at a time.

The change: +327 / -60 across 11 files. PR 43899.

The bug

The HTTP status was successful, so the node’s generic error path did not catch it. The response was valid per the API shape; candidates is optional on GenerateContentResponse. The code assumed the happy path.

The fix adds a shared assertResponseHasCandidates after every generateContent call. It throws a UserError with blockReason and blockReasonMessage, or an OperationalError when the response is empty and has no reason. This matches the Chat Model fix in #43467.

Why it mattered

AI providers use successful HTTP responses for policy outcomes. A blocked prompt is a user-visible result, not an infrastructure failure. Crashing turns a clear “the model refused” into a stack trace that the workflow cannot branch on.

The fix

Validate the response shape at the boundary. If candidates is missing and a block reason exists, throw a UserError that includes the reason. If the response is empty without a reason, throw an OperationalError. The node then shows “Gemini blocked the prompt (reason: ...)” with the detail from blockReasonMessage.

The evidence

The new tests cover blocked responses and empty responses across the affected operations. They fail on master and pass with the change. The PR runs the Gemini node test suite with pnpm test nodes/vendors/GoogleGemini --maxWorkers=1.

What I would repeat

A 200 does not mean a useful payload. Validate optional fields at the provider boundary and map policy outcomes to typed, user-readable errors. The model refusing is a normal branch, not an exception the workflow should have to guess about.

Sources

If this was useful, connect with me on LinkedIn; I write about the bugs behind merged pull requests and the evidence that gets them accepted.

FAQ

Why did the n8n Gemini node crash?
A blocked prompt returned HTTP 200 with no candidates, and the node read candidates directly, causing a TypeError.
What does the node show now?
A UserError with the block reason and block reason message, such as “Gemini blocked the prompt”.
Does this cover all Gemini operations?
The shared assertResponseHasCandidates runs after every generateContent call used by Message a Model, Analyze, Transcribe, Generate and Edit.
#n8n#gemini#ai#errors#open-source

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.