~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(llm): report skipped content blocks at debug level (#7851)
LearningCircuit1b86a37565fc
diff --git a/changelog.d/5509.bugfix.md b/changelog.d/5509.bugfix.mdnew file mode 100644index 0000000000..feed721116--- /dev/null+++ b/changelog.d/5509.bugfix.md@@ -0,0 +1 @@+Log a debug summary when LLM content blocks are skipped during text extraction.diff --git a/src/local_deep_research/utilities/json_utils.py b/src/local_deep_research/utilities/json_utils.pyindex 0f248593ac..d558348493 100644--- a/src/local_deep_research/utilities/json_utils.py+++ b/src/local_deep_research/utilities/json_utils.py@@ -61,9 +61,11 @@ def _coerce_content_blocks(blocks: list) -> str:Accepts blocks that are plain strings, dicts with a ``"text"`` key (when``type`` is ``"text"`` or unset), or objects exposing a ``.text`` strattribute (when their ``type`` attribute, if any, is ``"text"``).- Returns ``""`` for an empty/textless list.+ Returns ``""`` for an empty/textless list. Logs the number of skipped+ blocks at debug level without including their contents."""parts: list[str] = []+ skipped_count = 0for block in blocks:if isinstance(block, str):parts.append(block)@@ -72,14 +74,24 @@ def _coerce_content_blocks(blocks: list) -> str:block.get("text"), str):parts.append(block["text"])+ else:+ skipped_count += 1else:# A tool_result or thinking block object can expose .text too.# As for dicts, only an untyped or "text"-typed block counts.if getattr(block, "type", "text") != "text":+ skipped_count += 1continuetext_attr = getattr(block, "text", None)if isinstance(text_attr, str):parts.append(text_attr)+ else:+ skipped_count += 1+ if skipped_count:+ logger.debug(+ "Skipped {} non-text or malformed LLM content block(s)",+ skipped_count,+ )return "".join(parts)diff --git a/tests/utilities/test_content_block_diagnostics.py b/tests/utilities/test_content_block_diagnostics.pynew file mode 100644index 0000000000..958e83ecd4--- /dev/null+++ b/tests/utilities/test_content_block_diagnostics.py@@ -0,0 +1,68 @@+"""Observable diagnostics for skipped LLM content blocks."""++import re+from types import SimpleNamespace++import pytest++from local_deep_research.utilities import json_utils+++def diagnostics(loguru_caplog):+ records = []+ sink = json_utils.logger.add(+ lambda message: records.append(message.record),+ level="DEBUG",+ filter=lambda record: record["name"] == json_utils.__name__,+ )+ try:+ yield records+ finally:+ json_utils.logger.remove(sink)+++ "block",+ [+ {"type": "tool_use", "text": "ignored block text"},+ {"type": "text", "text": 42},+ {"unexpected": "ignored block text"},+ SimpleNamespace(type="thinking", text="ignored block text"),+ SimpleNamespace(text=None),+ None,+ ],+)+def test_skipped_blocks_emit_debug_diagnostics_without_changing_text(+ block, diagnostics+):+ response = SimpleNamespace(+ content=["first", block, {"type": "text", "text": " last"}]+ )++ assert json_utils.get_llm_response_text(response) == "first last"+ assert len(diagnostics) == 1+ assert diagnostics[0]["level"].name == "DEBUG"+ assert re.search(r"\b1\b", diagnostics[0]["message"])+ assert "skipped" in diagnostics[0]["message"].lower()+ assert "ignored block text" not in diagnostics[0]["message"]+++def test_one_summary_counts_multiple_skipped_blocks(diagnostics):+ response = SimpleNamespace(+ content=[{"type": "tool_use"}, SimpleNamespace(text=7), "kept"]+ )++ assert json_utils.get_llm_response_text(response) == "kept"+ assert len(diagnostics) == 1+ assert re.search(r"\b2\b", diagnostics[0]["message"])+++def test_text_only_and_empty_lists_do_not_emit_skip_diagnostics(diagnostics):+ response = SimpleNamespace(+ content=["a", {"text": "b"}, SimpleNamespace(text="c"), ""]+ )++ assert json_utils.get_llm_response_text(response) == "abc"+ assert json_utils.get_llm_response_text(SimpleNamespace(content=[])) == ""+ assert diagnostics == []