fix(write): handle array content from GLM and Qwen models - #1508
fix(write): handle array content from GLM and Qwen models#1508georgeglarson wants to merge 3 commits into
Conversation
Some models (GLM 4.6, Qwen 3 Coder 480B) send the write tool's content parameter as an array of strings instead of a single string, causing validation errors: "Invalid input: expected string, received array" This commit adds a custom UnmarshalJSON method to WriteParams that: - Accepts string content (existing behavior, fully backward compatible) - Accepts array of strings (joins with newlines) - Provides clear error messages for invalid types The fix is transparent to models that send strings and enables compatibility with models that send arrays. Fixes compatibility with: - GLM 4.6 - Qwen 3 Coder 480B - Any other models that send array content Tested with Venice.ai models via VeniceCode.
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
This PR adds backward-compatible JSON unmarshaling support to handle both string and array-of-strings for the content parameter in the write tool, enabling compatibility with GLM 4.6 and Qwen 3 Coder 480B models that send content as arrays instead of strings.
Key changes:
- Custom
UnmarshalJSONmethod forWriteParamsthat accepts both string and array formats - Array elements are joined with newlines to form the final content string
- Added
encoding/jsonimport to support custom unmarshaling
💡 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>
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. |
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
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
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. recheck |
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. |
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. recheck |
|
Closing — CLAAssistant has been failing despite multiple sign attempts over the past ~178 days, with no maintainer engagement to unstick it. Happy to re-open if the upstream CLA flow becomes responsive. |
Problem
Some models (GLM 4.6, Qwen 3 Coder 480B) send the write tool's
contentparameter as an array of strings instead of a single string, causing validation errors:Solution
This PR adds a custom
UnmarshalJSONmethod toWriteParamsthat:The fix is transparent to models that send strings and enables compatibility with models that send arrays.
Affected Models
Testing
Tested with Venice.ai models via VeniceCode (Venice.ai-optimized fork of Crush).
Code Changes
Adds 35 lines to
internal/agent/tools/write.go:UnmarshalJSONmethod forWriteParamsRelated