Skip to content

Bug Tool calls fail when assistant content is null #51661

Description

@picpicpic

Description

I am encountering an issue in OpenCode v2 (version 2.0.18) where tool calls trigger a validation error from the provider.
This behavior is not present in OpenCode v1 with the same provider.

Plugins

none

OpenCode version

2.0.18

Steps to reproduce

  1. Use a custom provider
  2. Trigger any tool call
    For example, I use the following prompt to reproduce: use the shell tool to call 'echo dummystring'
  3. The request sent to the provider contains "content": null for the assistant message that initiates the tool call

Actual behavior:
The provider returns a ValidationError because it expects a string or an array for the content field, but receives null.

Failing request { "model": "gemma-4-31b-it", "messages": [ { "role": "assistant", "content": null, "tool_calls": [...] } ] }
Error response { "errors": [{ "errorMessage": "Request doesn't match the schema", "message": "Invalid input: expected string, received null" }] }

Expected behavior:
The content field should be an empty string "" instead of null when a tool call is made without accompanying text.

Workaround / Proof of concept:
I created a small plugin that intercepts the request and replaces "content": null with "content": "".
With this change, the tool calls work perfectly.

Fixed request which is working { "model": "gemma-4-31b-it", "messages": [ { "role": "assistant", "content": "", "tool_calls": [...] } ] }

Screenshot and/or share link

No response

Operating System

macOS

Terminal

Kitty, VSCode terminal, MacOS Terminal

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions