fix(write): support array content from Venice.ai models#4715
fix(write): support array content from Venice.ai models#4715georgeglarson wants to merge 4 commits intoanomalyco:devfrom
Conversation
Some AI models (e.g., GLM 4.6, Qwen 3 Coder 480B) send tool call content as arrays instead of strings. This causes the write tool to fail with: 'Invalid input: expected string, received array' This fix uses Zod's preprocess function to handle both formats: - String content: passed through unchanged - Array content: joined with newlines - Other types: converted to string This maintains backward compatibility while enabling support for Venice.ai and similar models that use array-based content formatting. Related: charmbracelet/crush#1508
There was a problem hiding this comment.
Pull request overview
This pull request adds support for AI models (e.g., GLM 4.6, Qwen 3 Coder 480B from Venice.ai) that send tool call content as arrays instead of strings. The fix uses Zod's preprocess function to normalize array-based content by joining elements with newlines, while maintaining backward compatibility with string-based content.
Key changes:
- Added preprocessing logic to handle both string and array content formats
- Used
z.preprocess()to transform array inputs into newline-separated strings before validation - Maintained backward compatibility with existing string-based content
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
hey @georgeglarson, are you sure the models aren't calling the tool improperly ? does this only happen with the write tool or also other tools? in the mean time, you can expose the experimental batch tool: hope this helps |
|
Hey @spoons-and-mirrors! Great question. TL;DR: The models are following the OpenAI spec correctly - they're allowed to send arrays. This happens specifically with the Why arrays? Does it affect other tools?
The fix |
|
This setting does not make the error go away
Z AI and others do work, its not a model issue per say, its the way the write/ediit tool is being used i believe |
|
Not sure I understand what you mean, but as I showed in my screenshot, I can have glm do what this PR is supposedly trying to fix. |
|
So, the issue isnt the model itself its how the inference provider has it setup. |
|
Let me rephrase that, the issue isnt how the provider has it setup, as its per OpenAI spec. |
f8ee907 to
6a9856d
Compare
|
@spoons-and-mirrors any chance this will get merged. Lots of venice.ai user are waiting for this fix 🙏🙏🙏 |
|
@znake I've pinged the team, not much more i can do. Are you sure this solves venice.ai user issues tho? how about other tools? did you try the batch tool ? which could help maybe? |
|
@spoons-and-mirrors Ive tried enabling the experimental batching tool feature and it did not have any effect. |
|
Can't wait for this PR to get merged! |
|
@rekram1-node Can this go live? |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |


Some AI models (e.g., GLM 4.6, Qwen 3 Coder 480B) send tool call content as arrays instead of strings. This causes the write tool to fail with: 'Invalid input: expected string, received array'
This fix uses Zod's preprocess function to handle both formats:
This maintains backward compatibility while enabling support for Venice.ai and similar models that use array-based content formatting.
Related: charmbracelet/crush#1508