Zod schema validation error when Gemini streams tool calls (missing index field)

Description:

When using Google Gemini models (gemini-flash-lite-latest, Gemini 2.0 / 2.5) with tool calls enabled (e.g., Web Search via brave_search), streaming responses continuously fail with a Zod invalid_union / invalid_type error.

Cause:

Google's Gemini OpenAI-compatibility API endpoint drops the index property inside delta.tool_calls[0] when streaming a response. Because BoltAI's streaming parser expects strict OpenAI completion formatting where tool_calls[0].index must be an integer, the schema validation fails and crashes the stream before the function/tool can execute.

Raw Error Log:

JSON

Type validation failed: Value: {"choices":[{"delta":{"role":"assistant","tool_calls":[{"extra_content":{"google":{"thought_signature":"... "}},"function":{"arguments":"{\"query\":\"...\"}","name":"brave_search"},"id":"a4Fsai5e","type":"function"}]},"index":0}],"created":1785262181,"id":"...","model":"models/gemini-flash-lite-latest","object":"chat.completion.chunk","usage":{"completion_tokens":29,"prompt_tokens":651,"total_tokens":680}} Error message: [{"code":"invalid_union","errors":[[{"expected":"number","code":"invalid_type","path":["choices",0,"delta","tool_calls",0,"index"],"message":"Invalid input"}],[{"expected":"object","code":"invalid_type","path":["error"],"message":"Invalid input"}]],"path":[],"message":"Invalid input"}] 

Suggested Fix:

In BoltAI's streaming delta parser schema, make index an optional property inside tool_calls, or fallback to defaulting tool_calls[i].index to 0 when parsing chunks from Google Gemini endpoints.

Please authenticate to join the conversation.

Upvoters
Status

In Review

Board
πŸ›

Bug Reports

Date

About 8 hours ago

Author

injectedlinen

Subscribe to post

Get notified by email when there are changes.