[PR #14915] model/parsers: treating failed parsing of tool calls as content for qwen models instead of aborting #25454

Open
opened 2026-04-19 18:13:42 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14915
Author: @davidson8171
Created: 3/17/2026
Status: 🔄 Open

Base: mainHead: model/parsers-qwen-tool-fallback


📝 Commits (1)

  • bcae341 model/parsers: treating failed parsing as content for qwen models instead of aborting

📊 Changes

4 files changed (+18 additions, -8 deletions)

View changed files

📝 model/parsers/qwen3.go (+5 -2)
📝 model/parsers/qwen35.go (+3 -2)
📝 model/parsers/qwen3coder.go (+5 -2)
📝 model/parsers/qwen3vl.go (+5 -2)

📄 Description

Summary

Fixes cases where Qwen models (in particular qwen3-coder and the qwen3 / qwen3vl / qwen3.5 variants) stream malformed or incomplete tool call output (e.g. broken XML-like tags).
Previously, this caused errors like "qwen tool call parsing failed" and aborted the entire request, so the user received no response at all.
With this change, unparseable tool calls are treated as regular text content so the request can complete and the user still sees the model output.

Related: Issue #14834


Root Cause

  • The Qwen parsers (qwen3.go, qwen3vl.go, qwen3coder.go, qwen35.go) attempted to strictly parse tool calls.
  • When the model produced invalid or truncated tool call payloads (for example, incomplete XML inside a <tool_call> block), the parsing step failed (xml.Unmarshal or the tool parser) and Add returned an error.
  • That error was propagated up to the caller and terminated the request, resulting in a "qwen tool call parsing failed" error with no usable response for the end user.

Fix

  • Qwen3 / Qwen3VL / Qwen3Coder

    • When parsing a tool call fails, the raw tool call block is emitted back as regular text content:
      • The original content between <tool_call> and </tool_call> is written back, wrapped with the same tags.
    • The parse error is logged as a warning but is no longer returned from Add, so the request is not aborted.
  • Qwen3.5

    • When the underlying tool parser (toolParser.Add) fails while processing content, that segment is treated as plain content instead of failing the whole request.
    • Any tool calls extracted from that segment are discarded, but the user still receives the textual answer.
    • The error is still logged as a warning for debugging, without being propagated to the caller.

Valid tool calls continue to be parsed and emitted as before; only malformed tool calls are downgraded to plain content, which is safer and more robust for users.


Test Plan

  • Unit tests for parsers

    # Run only Qwen-related tests in the parser package
    go test ./model/parsers -run Qwen
    
    # Run the full parser package tests
    go test ./model/parsers
    
    

🔄 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/14915 **Author:** [@davidson8171](https://github.com/davidson8171) **Created:** 3/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `model/parsers-qwen-tool-fallback` --- ### 📝 Commits (1) - [`bcae341`](https://github.com/ollama/ollama/commit/bcae341de2e45bc2d14c260944fa75e1bdb3f0ac) model/parsers: treating failed parsing as content for qwen models instead of aborting ### 📊 Changes **4 files changed** (+18 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `model/parsers/qwen3.go` (+5 -2) 📝 `model/parsers/qwen35.go` (+3 -2) 📝 `model/parsers/qwen3coder.go` (+5 -2) 📝 `model/parsers/qwen3vl.go` (+5 -2) </details> ### 📄 Description ## Summary Fixes cases where Qwen models (in particular `qwen3-coder` and the `qwen3` / `qwen3vl` / `qwen3.5` variants) stream malformed or incomplete tool call output (e.g. broken XML-like tags). Previously, this caused errors like `"qwen tool call parsing failed"` and aborted the entire request, so the user received no response at all. With this change, unparseable tool calls are treated as regular text content so the request can complete and the user still sees the model output. Related: [Issue #14834](https://github.com/ollama/ollama/issues/14834) --- ## Root Cause - The Qwen parsers (`qwen3.go`, `qwen3vl.go`, `qwen3coder.go`, `qwen35.go`) attempted to strictly parse tool calls. - When the model produced invalid or truncated tool call payloads (for example, incomplete XML inside a `<tool_call>` block), the parsing step failed (`xml.Unmarshal` or the tool parser) and `Add` returned an error. - That error was propagated up to the caller and terminated the request, resulting in a `"qwen tool call parsing failed"` error with no usable response for the end user. --- ## Fix - **Qwen3 / Qwen3VL / Qwen3Coder** - When parsing a tool call fails, the raw tool call block is emitted back as regular text content: - The original content between `<tool_call>` and `</tool_call>` is written back, wrapped with the same tags. - The parse error is logged as a warning but is no longer returned from `Add`, so the request is not aborted. - **Qwen3.5** - When the underlying tool parser (`toolParser.Add`) fails while processing content, that segment is treated as plain content instead of failing the whole request. - Any tool calls extracted from that segment are discarded, but the user still receives the textual answer. - The error is still logged as a warning for debugging, without being propagated to the caller. Valid tool calls continue to be parsed and emitted as before; only malformed tool calls are downgraded to plain content, which is safer and more robust for users. --- ## Test Plan - **Unit tests for parsers** ```bash # Run only Qwen-related tests in the parser package go test ./model/parsers -run Qwen # Run the full parser package tests go test ./model/parsers --- <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-19 18:13:42 -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#25454