Skip to content

[Bug]:parse_json_response does not strip <think> reasoning tags, causing empty BookEngine proposal fields #673

Closed

Description

@generalthunder15

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

Image

deeptutor/utils/json_parser.py::parse_json_response() parses JSON from LLM responses,
but it does not strip ... reasoning chains before parsing.

When using models like Qwen / DeepSeek that emit chain-of-thought inside tags
before the JSON, the parser may return {}. In BookEngine's IdeationAgent, this
causes the generated proposal's description, scope, and rationale to be empty.

Example raw response:

  1. Analyze user intent...
  2. Determine target audience...
{"title":"...","description":"...","scope":"...","rationale":"..."}

parse_json_response() fails to extract the JSON, returns {}, and
IdeationAgent._coerce_proposal() fills all fields with empty strings.

This affects all callers of parse_json_response(), not just BookEngine.

Steps to reproduce

  1. Configure a model that outputs tags (e.g., qwen3.7-max).
  2. Go to Book → Create new book.
  3. Enter a user intent and click Generate proposal.
  4. The proposal card appears, but Description, Scope, and Rationale are empty.

Expected Behavior

parse_json_response() should ignore ... content and successfully parse the JSON object. The proposal should contain non-empty description, scope, and rationale.

Related Module

Idea Generation

Configuration Used

Model provider: OpenAI-compatible endpoint serving Qwen3.7-max-2026-06-08 Issue is independent of specific knowledge bases or chat selections.

Logs and screenshots

Image

Additional Information

  • DeepTutor Version: v1.5.3
  • Operating System: Windows 11
  • Python Version: 3.11
  • Node.js Version: v24.14.0
  • Browser (if applicable): Chrome 127
  • Related Issues: none
  • Verification: After adding think-tag stripping to parse_json_response() in a local branch, the same model and input produce a correct proposal with all fields populated, and the issue no longer reproduces.

Activity

  1. added
    bug
    on Jul 24, 2026
  2. Cyriellewu commented on Jul 24, 2026

    @Cyriellewu
    Contributor

    Hi! I'd like to work on this. I've traced it to parse_json_response() in deeptutor/utils/json_parser.py — when a <think> reasoning block contains a brace, the raw_decode scan picks up the object from inside the reasoning instead of the real payload. I have a fix + tests ready targeting dev and will open a PR shortly.

  3. added a commit that references this issue on Jul 24, 2026
    b020686
  4. pancacake commented on Jul 24, 2026

    @pancacake
    Collaborator

    Fixed on dev by #675. parse_json_response now strips <think> reasoning after a failed direct parse and before the raw_decode scan, so a brace inside the reasoning can no longer be returned in place of the real payload — and a valid JSON payload whose string values legitimately contain a literal <think> is preserved untouched (regression test added). Will ship in the next release. Thanks @Cyriellewu for the trace and the fix.

  5. added a commit that references this issue on Jul 25, 2026
    1843cd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions