n8n - ✅(Solved) Fix googleGemini node (typeVersion 1.1) crashes with "Cannot use 'in' operator to search for 'functionCall' in undefined" when builtInTools.googleSearch is enabled and Gemini returns a multi-turn tool response [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
n8n-io/n8n#28215Fetched 2026-04-09 08:16:02
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×1cross-referenced ×1labeled ×1mentioned ×1

Error Message

When using the @n8n/n8n-nodes-langchain.googleGemini node (typeVersion 1.1) with builtInTools.googleSearch enabled, the node intermittently crashes with NodeOperationError: Cannot use 'in' operator to search for 'functionCall' in undefined. The error originates inside router.ts at line 60, meaning it occurs before the node produces any output — making it impossible to handle downstream. The crash happens because Gemini sometimes returns a multi-part response containing a functionCall block followed by a functionResponse block before the final text, and the node's response parser does not guard against undefined parts in that sequence. 5. Run the node multiple times — the error occurs intermittently, more frequently when the trend topic is highly active and Gemini performs multiple search rounds

Root Cause

When using the @n8n/n8n-nodes-langchain.googleGemini node (typeVersion 1.1) with builtInTools.googleSearch enabled, the node intermittently crashes with NodeOperationError: Cannot use 'in' operator to search for 'functionCall' in undefined. The error originates inside router.ts at line 60, meaning it occurs before the node produces any output — making it impossible to handle downstream. The crash happens because Gemini sometimes returns a multi-part response containing a functionCall block followed by a functionResponse block before the final text, and the node's response parser does not guard against undefined parts in that sequence.

Fix Action

Fixed

PR fix notes

PR #28219: fix(googleGemini): Guard tool call parsing when response parts contain undefined

Description (problem / solution / changelog)

Summary

The Google Gemini node (text resource, Message operation) could throw Cannot use 'in' operator to search for 'functionCall' in undefined when Gemini returned content.parts with missing entries during multi-turn tool use (for example with built-in Google Search). This updates getToolCalls to use content?.parts ?? [] and to only treat plain objects with a real functionCall payload as tool calls.

A unit test covers a multi-iteration response with an undefined part and Google Search enabled.

How to test

cd packages/@n8n/nodes-langchain && pnpm test GoogleGemini.node.test.ts

Related Linear tickets, Github issues, and Community forum posts

Fixes https://github.com/n8n-io/n8n/issues/28215

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created (not required for this bugfix).
  • Tests included.
  • PR labeled for backport if needed.

Changed files

  • packages/@n8n/nodes-langchain/nodes/vendors/GoogleGemini/GoogleGemini.node.test.ts (modified, +88/-0)
  • packages/@n8n/nodes-langchain/nodes/vendors/GoogleGemini/actions/text/message.operation.ts (modified, +13/-1)
RAW_BUFFERClick to expand / collapse

Bug Description

When using the @n8n/n8n-nodes-langchain.googleGemini node (typeVersion 1.1) with builtInTools.googleSearch enabled, the node intermittently crashes with NodeOperationError: Cannot use 'in' operator to search for 'functionCall' in undefined. The error originates inside router.ts at line 60, meaning it occurs before the node produces any output — making it impossible to handle downstream. The crash happens because Gemini sometimes returns a multi-part response containing a functionCall block followed by a functionResponse block before the final text, and the node's response parser does not guard against undefined parts in that sequence.

To Reproduce

  1. Create a workflow with a @n8n/n8n-nodes-langchain.googleGemini node
  2. Set model to models/gemini-2.5-flash
  3. Enable builtInTools.googleSearch = true
  4. Set a prompt that references a real-world/trending topic to force Gemini to use Google Search (e.g. "Generate a tweet about this trending topic: PSG vs Liverpool")
  5. Run the node multiple times — the error occurs intermittently, more frequently when the trend topic is highly active and Gemini performs multiple search rounds

Expected behavior

The node should handle multi-turn tool use responses from Gemini gracefully, extract the final text part, and return it as output — without crashing. At minimum, the parser in router.ts should null-check each part before applying the 'in' operator.

Debug Info

{ "errorMessage": "Cannot use 'in' operator to search for 'functionCall' in undefined", "errorDetails": {}, "n8nDetails": { "nodeType": "@n8n/n8n-nodes-langchain.googleGemini", "nodeVersion": 1.1, "resource": "text", "operation": "message", "itemIndex": 0, "stackTrace": [ "NodeOperationError: Cannot use 'in' operator to search for 'functionCall' in undefined", "at ExecuteContext.router (.../GoogleGemini/actions/router.ts:60:10)" ] }, "model": "models/gemini-2.5-flash", "builtInTools": { "googleSearch": true }, "triggerCondition": "Prompt references a live/trending topic causing Gemini to perform multiple search rounds before returning final text" }

Operating System

Docker

n8n Version

2.14.2

Node.js Version

24.14.1

Database

PostgreSQL

Execution mode

main (default)

Hosting

self hosted

extent analysis

TL;DR

The @n8n/n8n-nodes-langchain.googleGemini node may be fixed by modifying the response parser in router.ts to null-check each part of the multi-part response from Gemini before applying the 'in' operator.

Guidance

  • Verify that the error occurs due to the node's response parser not handling undefined parts in the multi-part response from Gemini by checking the stackTrace in the error details.
  • Inspect the router.ts file at line 60 to confirm that the 'in' operator is being used without null-checking the functionCall property.
  • Consider adding a null-check before applying the 'in' operator, such as if (part!== undefined && 'functionCall' in part).
  • Test the node with a prompt that references a real-world/trending topic to force Gemini to use Google Search and verify that the error no longer occurs.

Example

// router.ts (modified)
if (part!== undefined && 'functionCall' in part) {
  // existing code
}

Notes

The fix may require modifying the @n8n/n8n-nodes-langchain.googleGemini node's code, which could be updated in a future version. The workaround may need to be reapplied if the node is updated.

Recommendation

Apply the workaround by modifying the router.ts file to add null-checking for the functionCall property, as this will allow the node to handle multi-turn tool use responses from Gemini without crashing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The node should handle multi-turn tool use responses from Gemini gracefully, extract the final text part, and return it as output — without crashing. At minimum, the parser in router.ts should null-check each part before applying the 'in' operator.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING