Skip to content

fix(write): handle array content from GLM and Qwen models - #1508

Closed
georgeglarson wants to merge 3 commits into
charmbracelet:mainfrom
georgeglarson:fix-write-tool-array-content
Closed

fix(write): handle array content from GLM and Qwen models#1508
georgeglarson wants to merge 3 commits into
charmbracelet:mainfrom
georgeglarson:fix-write-tool-array-content

Conversation

@georgeglarson

Copy link
Copy Markdown

Problem

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:

The write tool was called with invalid arguments:
"Invalid input: expected string, received array"

Solution

This PR 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.

Affected Models

  • GLM 4.6
  • Qwen 3 Coder 480B
  • Any other models that send array content

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:

  • Custom UnmarshalJSON method for WriteParams
  • Handles both string and array formats
  • Zero breaking changes

Related

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.
Copilot AI review requested due to automatic review settings November 24, 2025 20:03
@georgeglarson
georgeglarson requested a review from a team as a code owner November 24, 2025 20:03
@georgeglarson
georgeglarson requested review from aymanbagabas and kujtimiihoxha and removed request for a team November 24, 2025 20:03
@charmcli

charmcli commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UnmarshalJSON method for WriteParams that accepts both string and array formats
  • Array elements are joined with newlines to form the final content string
  • Added encoding/json import to support custom unmarshaling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/agent/tools/write.go Outdated
Comment thread internal/agent/tools/write.go Outdated
georgeglarson and others added 2 commits November 24, 2025 15:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@georgeglarson

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

georgeglarson added a commit to georgeglarson/venicecode that referenced this pull request Nov 24, 2025
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
georgeglarson added a commit to georgeglarson/venicecode that referenced this pull request Nov 24, 2025
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
@georgeglarson

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

recheck

@georgeglarson

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@georgeglarson

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA. recheck

@georgeglarson

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants