[PR #9510] fix(google-genai): add null safety for candidateContent.parts #8959

Closed
opened 2026-02-19 17:44:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langchainjs/pull/9510

State: closed
Merged: No


Description:

Fixed a bug in @langchain/google-genai where using middleware with agents (createDeepAgent or createAgent) would randomly crash with:
TypeError: undefined is not an object (evaluating 'candidateContent.parts')

Root Cause:
in common.ts , functions mapGenerateContentResultToChatResult and convertResponseContentToChatGenerationChunk accessed candidateContent.parts without checking if candidateContent was defined.

Changes Made:
Added null safety for candidateContent.parts:
const functionCalls = (candidateContent?.parts || []).reduce((acc, p) => {

Also added a test to check if mapGenerateContentResultToChatResult handles candidate with undefined content
Only added test for one function since both had the same issue, doesn't make sense to test for same thing twice.

Fixes langchain-ai/deepagentsjs#70

**Original Pull Request:** https://github.com/langchain-ai/langchainjs/pull/9510 **State:** closed **Merged:** No --- ## Description: Fixed a bug in @langchain/google-genai where using middleware with agents (createDeepAgent or createAgent) would randomly crash with: `TypeError: undefined is not an object (evaluating 'candidateContent.parts')` **Root Cause:** in common.ts , functions mapGenerateContentResultToChatResult and convertResponseContentToChatGenerationChunk accessed candidateContent.parts without checking if candidateContent was defined. **Changes Made:** Added null safety for candidateContent.parts: `const functionCalls = (candidateContent?.parts || []).reduce((acc, p) => {` Also added a test to check if mapGenerateContentResultToChatResult handles candidate with undefined content Only added test for one function since both had the same issue, doesn't make sense to test for same thing twice. Fixes langchain-ai/deepagentsjs#70
yindo added the pull-request label 2026-02-19 17:44:59 -05:00
yindo closed this issue 2026-02-19 17:44:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchainjs#8959