Skip to content

fix(providers): handle nil input in GLM series tool_use blocks#1662

Closed
hyperwd wants to merge 1 commit intosipeed:mainfrom
hyperwd:fix/glm-nil-input
Closed

fix(providers): handle nil input in GLM series tool_use blocks#1662
hyperwd wants to merge 1 commit intosipeed:mainfrom
hyperwd:fix/glm-nil-input

Conversation

@hyperwd
Copy link
Contributor

@hyperwd hyperwd commented Mar 17, 2026

问题

Zhipu AI 的 GLM 系列模型在返回 tool_use 块时,可能会将 input 字段设置为 null,这会导致后续 API 请求失败并报错:
ClaudeContentBlockToolResult object has no attribute id

修复

  • 添加对 tool call Arguments 字段的防御性 nil 检查
  • 将 nil input 替换为空对象 {},以符合 Anthropic 规范
  • 防止 API 错误,同时保持与其他 provider 的向后兼容性

这是对 PR #1284 的后续修复。

- add defensive nil check for tool call Arguments field
- replace nil input with empty object to comply with Anthropic spec
- prevent API errors when GLM models return null input in tool_use blocks

Zhipu AI's GLM series models may return tool_use blocks with null input field,
which causes their API to reject subsequent requests with error:
"ClaudeContentBlockToolResult object has no attribute id"

This fix ensures compatibility by converting nil inputs to empty objects {},
matching the Anthropic Messages API specification while maintaining backward
compatibility with other providers.
@hyperwd
Copy link
Contributor Author

hyperwd commented Mar 17, 2026

Closing to recreate with English description

@hyperwd hyperwd closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant