[PR #14454] fix: normalize empty content on assistant messages with tool_calls #45927

Open
opened 2026-04-25 01:31:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14454
Author: @Anandesh-Sharma
Created: 2/26/2026
Status: 🔄 Open

Base: mainHead: fix-empty-content-tool-calls


📝 Commits (1)

  • aefc1df fix: normalize empty content on assistant messages with tool_calls

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 openai/openai.go (+8 -1)

📄 Description

Summary

  • Normalize content: "" to be treated the same as content: null on assistant messages that have tool_calls
  • This prevents models from switching from structured tool calling to text-based markup mode

Details

When /v1/chat/completions receives assistant messages in conversation history with content: "" alongside tool_calls, the empty string was being passed through to the model template. This caused models like qwen3-coder to switch from structured tool_calls output to text-based <function=...> markup on subsequent turns.

The OpenAI API spec treats content: "" and content: null equivalently for assistant messages with tool_calls. This fix normalizes the empty string case in FromChatRequest to match the existing null handling in the default branch.

Test plan

  • Verified that content: "" with tool_calls now produces the same internal message as content: null with tool_calls
  • Non-empty content with tool_calls continues to work as before
  • Messages without tool_calls are unaffected

Fixes #14181

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14454 **Author:** [@Anandesh-Sharma](https://github.com/Anandesh-Sharma) **Created:** 2/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-empty-content-tool-calls` --- ### 📝 Commits (1) - [`aefc1df`](https://github.com/ollama/ollama/commit/aefc1dfb98d40f69b9ab51e7b4d16d05df25a120) fix: normalize empty content on assistant messages with tool_calls ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `openai/openai.go` (+8 -1) </details> ### 📄 Description ## Summary - Normalize `content: ""` to be treated the same as `content: null` on assistant messages that have `tool_calls` - This prevents models from switching from structured tool calling to text-based markup mode ## Details When `/v1/chat/completions` receives assistant messages in conversation history with `content: ""` alongside `tool_calls`, the empty string was being passed through to the model template. This caused models like `qwen3-coder` to switch from structured `tool_calls` output to text-based `<function=...>` markup on subsequent turns. The OpenAI API spec treats `content: ""` and `content: null` equivalently for assistant messages with tool_calls. This fix normalizes the empty string case in `FromChatRequest` to match the existing `null` handling in the `default` branch. ## Test plan - [x] Verified that `content: ""` with tool_calls now produces the same internal message as `content: null` with tool_calls - [x] Non-empty content with tool_calls continues to work as before - [x] Messages without tool_calls are unaffected Fixes #14181 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 01:31:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#45927