Skip to content

fix(workflow): prevent JSON parsing failures from LLM <think> blocks#2609

Open
Sanjeever wants to merge 1 commit intocoze-dev:mainfrom
Sanjeever:main
Open

fix(workflow): prevent JSON parsing failures from LLM <think> blocks#2609
Sanjeever wants to merge 1 commit intocoze-dev:mainfrom
Sanjeever:main

Conversation

@Sanjeever
Copy link

fix(workflow): remove think tags before JSON parsing

When parsing LLM responses, some replies include <think>...</think> tags (internal reasoning), which may break JSON parsing. This PR strips all <think>...</think> blocks via regex before attempting to parse, making JSON extraction stable.

What type of PR is this?

  • fix

Check the PR title.

  • This PR title match the format: (optional scope):
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Add documentation if the current PR requires user awareness at the usage level.

(Optional) Translate the PR title into Chinese.

fix(workflow): 在解析 JSON 前移除 think 标签

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

  • Problem: Some LLM outputs wrap internal reasoning in <think>...</think>, causing JSON parsing to fail.
  • Solution: Remove all <think>...</think> segments before JSON parsing using a regex pre-processing step.
  • Impact: Improves robustness of JSON extraction; no functional change for valid JSON responses.

zh(optional):

  • 问题:部分 LLM 输出包含 <think>...</think>,会导致 JSON 解析失败。
  • 方案:在解析 JSON 前用正则移除所有 <think>...</think> 段落。
  • 影响:提升 JSON 提取稳定性;对原本就合法的 JSON 输出无影响。

(Optional) Which issue(s) this PR fixes:

N/A

When parsing LLM responses, some replies include <think> tags used for internal reasoning, which can cause JSON parsing failures. To prevent this, use regular expressions to remove all <think>...</think> tags before parsing, ensuring smooth JSON extraction.
@CLAassistant
Copy link

CLAassistant commented Feb 5, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants