Skip to content

fix(chat_templates): extract reasoning_content before reassigning content in qwen3_5 template#3725

Merged
NanoCode012 merged 1 commit into
axolotl-ai-cloud:mainfrom
Anai-Guo:fix/qwen3_5-jinja-reasoning-order
Jun 15, 2026
Merged

fix(chat_templates): extract reasoning_content before reassigning content in qwen3_5 template#3725
NanoCode012 merged 1 commit into
axolotl-ai-cloud:mainfrom
Anai-Guo:fix/qwen3_5-jinja-reasoning-order

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3724.

The bundled qwen3_5.jinja template parses inline <think>...</think> reasoning incorrectly for assistant messages. In the else branch that handles inline reasoning, the two {%- set %} statements were in the wrong order relative to the official Qwen3.5 template: content was mutated before reasoning_content was extracted from it.

Both assignments read content, so they are order-dependent:

{%- set content = content.split('</think>')[-1].lstrip('\n') %}
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}

After the first line, content no longer contains </think> (or <think>), so the second line's content.split('</think>')[0].split('<think>')[-1] just returns the already-truncated answer. The result: the reasoning trace is silently dropped and the answer is duplicated into the <think> block of the rendered prompt.

Fix

Swap the two statements so reasoning_content is extracted from the original content before content is reassigned, matching the official Qwen3.5 template:

{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
{%- set content = content.split('</think>')[-1].lstrip('\n') %}

Test plan

  • Render an assistant turn whose content contains an inline <think>...</think> block (and no separate message.reasoning_content field) and confirm the reasoning text lands in the <think> block and the answer follows after </think>.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed parsing and display of reasoning content in model responses to ensure accurate extraction.

…tent in qwen3_5 template

The inline-<think> assistant branch reassigned content (stripping it to
the post-</think> answer) before reasoning_content was extracted from it.
Since reasoning_content reads from the already-truncated content, the
reasoning trace was dropped and the answer leaked into the <think> block.
Swap the two set statements to match the official Qwen3.5 template order.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b8a1088-7722-45e9-a615-a80b37adc4b9

📥 Commits

Reviewing files that changed from the base of the PR and between 22bcb9a and cee969b.

📒 Files selected for processing (1)
  • src/axolotl/utils/chat_templates/templates/qwen3_5.jinja

📝 Walkthrough

Walkthrough

The PR fixes a bug in the Qwen3.5 chat template where inline <think>...</think> reasoning blocks were being silently dropped. Two variable assignments in the assistant message rendering logic are reordered so reasoning_content is extracted before content is mutated.

Changes

Qwen3.5 Template Reasoning Parsing Fix

Layer / File(s) Summary
Reorder reasoning extraction before content mutation
src/axolotl/utils/chat_templates/templates/qwen3_5.jinja
Lines 96–97 are reordered: reasoning_content is now computed from the original content before content is reassigned to the portion after </think>, fixing the inline reasoning block extraction logic that was previously dropping reasoning when message.reasoning_content is not provided as a separate field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • winglian
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: reordering two Jinja set statements to extract reasoning_content before reassigning content in the qwen3_5 template.
Linked Issues check ✅ Passed The PR correctly implements the primary fix from issue #3724: swapping the two set statements so reasoning_content is extracted before content is reassigned, resolving the bug where inline reasoning was lost.
Out of Scope Changes check ✅ Passed The PR makes only the minimal targeted fix to qwen3_5.jinja (1 line added, 1 line removed) that directly addresses the statement reordering issue in issue #3724, with no extraneous changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ved1beta ved1beta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good catch

@NanoCode012

Copy link
Copy Markdown
Collaborator

Ooh, this was the same comment I had on your PR @ved1beta . I think you can choose whichever to merge first

@NanoCode012 NanoCode012 merged commit b02ee14 into axolotl-ai-cloud:main Jun 15, 2026
1 check passed
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.

Qwen3.5 chat template drops reasoning for inline <think> assistant turns (two set statements swapped)

3 participants