Skip to content

[Bug]: Knowledge extractor fails with DeepSeek — JSON parsing error #495

Description

@jes614753-sketch

Problem

KnowledgeExtractorAgent passes response_format={"type": "json_object"} to the LLM. DeepSeek API does not support this parameter and returns JSON wrapped in markdown code fences (```json ... ```), causing json.loads() to fail.

Steps to Reproduce

  1. Configure LLM to use DeepSeek (LLM_BINDING=deepseek, LLM_MODEL=deepseek-chat)
  2. Upload a document and trigger knowledge point extraction
  3. Extraction fails with JSON decode error

Expected

The extractor should handle markdown-wrapped JSON responses gracefully.

Suggested Fix

In deeptutor/agents/knowledge_extractor/extractor_agent.py, strip markdown fences before parsing:

cleaned = response.strip()
if cleaned.startswith("```"):
    first_newline = cleaned.find("\n")
    if first_newline != -1:
        cleaned = cleaned[first_newline + 1:]
    if cleaned.rstrip().endswith("```"):
        cleaned = cleaned.rstrip()[:-3].rstrip()
result = json.loads(cleaned)

Also consider removing response_format={"type": "json_object"} for providers that don't support it, or making it configurable.

Environment

  • LLM: DeepSeek (deepseek-chat)
  • Python 3.14, Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions