~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(search): parse list-of-content-blocks LLM replies in relevance filter (#7405)
Likhitha J4d78c7da6887
diff --git a/changelog.d/7396.bugfix.md b/changelog.d/7396.bugfix.mdnew file mode 100644index 0000000000..49e446517a--- /dev/null+++ b/changelog.d/7396.bugfix.md@@ -0,0 +1 @@+The relevance filter no longer drops every search result when a thinking-capable model's reply comes back as a list of content blocks (e.g. Anthropic extended-thinking) instead of a plain string.diff --git a/src/local_deep_research/web_search_engines/relevance_filter.py b/src/local_deep_research/web_search_engines/relevance_filter.pyindex df85866814..e4e5f8045d 100644--- a/src/local_deep_research/web_search_engines/relevance_filter.py+++ b/src/local_deep_research/web_search_engines/relevance_filter.py@@ -41,6 +41,7 @@ from langchain_ollama import ChatOllamafrom ..config.constants import DEFAULT_MAX_FILTERED_RESULTSfrom ..security.log_sanitizer import scrub_errorfrom ..security.secure_logging import logger+from ..utilities.json_utils import get_llm_response_text# Real wrapper chains (RateLimitedLLMWrapper -> ProcessingLLMWrapper -> base)# are at most 2-3 levels deep. A depth limit avoids spurious infinite chains@@ -414,14 +415,15 @@ def _invoke_text(llm, prompt: str, engine_name: str) -> List[int]:)raise- # LangChain chat models return a Message; LLMs return a string.- text = getattr(result, "content", result)- if not isinstance(text, str):- logger.warning(- f"[{engine_name}] Unexpected LLM response type: "- f"{type(text).__name__}"- )- return []+ # LangChain chat models return a Message; LLMs return a string. A+ # thinking-capable model (Anthropic extended-thinking, some Ollama+ # reasoning models) can return ``.content`` as a list of blocks+ # (``[{"type": "thinking", ...}, {"type": "text", "text": "0, 2"}]``)+ # rather than a plain string. get_llm_response_text() handles both+ # shapes — joining text blocks and dropping thinking/tool_use ones —+ # the same way the rest of the codebase extracts LLM output, instead+ # of only accepting a bare string and discarding the whole response.+ text = get_llm_response_text(result)logger.info(f"[{engine_name}] LLM call returned {len(text)} chars")diff --git a/tests/web_search_engines/test_relevance_filter.py b/tests/web_search_engines/test_relevance_filter.pyindex c7ac3375d2..6f2d4859f4 100644--- a/tests/web_search_engines/test_relevance_filter.py+++ b/tests/web_search_engines/test_relevance_filter.py@@ -10,6 +10,8 @@ that are hard to assert through the wrapper:- ``max_filtered_results=None`` (no cap)- text parsing tolerates wrapper text ("Indices: 0, 2, 5")- ``_unwrap_llm`` walks a wrapper chain (locks in Ollama optimization)+- ``.content`` as a list of blocks (thinking-capable models) is parsed+ instead of being treated as an unexpected type (issue #7396)"""import threading@@ -111,6 +113,46 @@ def test_message_object_response_uses_content_attribute():assert result == [previews[1], previews[3]]+def test_content_block_list_response_is_parsed():+ """A thinking-capable model's reply shape (.content is a list of+ blocks) must still be parsed instead of dropping all previews.++ Regression for issue #7396: a thinking model's ``.content`` can come+ back as ``[{"type": "thinking", ...}, {"type": "text", "text": "..."}]``+ rather than a plain string. The old code treated any non-str+ ``.content`` as "unexpected" and returned an empty judgment,+ silently rejecting every preview.+ """+ previews = _previews(4)+ fake_message = Mock(spec=["content"])+ fake_message.content = [+ {"type": "thinking", "thinking": "Let me consider each result..."},+ {"type": "text", "text": "0, 2"},+ ]+ mock_llm = Mock()+ mock_llm.invoke.return_value = fake_message++ result = filter_previews_for_relevance(mock_llm, previews, "q")++ assert result == [previews[0], previews[2]]+++def test_content_block_list_with_only_thinking_is_empty_judgment():+ """A content-block list with no text block parses to no indices —+ a valid "none relevant" judgment, not a crash or warning spam."""+ previews = _previews(3)+ fake_message = Mock(spec=["content"])+ fake_message.content = [+ {"type": "thinking", "thinking": "Still reasoning..."}+ ]+ mock_llm = Mock()+ mock_llm.invoke.return_value = fake_message++ result = filter_previews_for_relevance(mock_llm, previews, "q")++ assert result == []++# ---------- 5. LLM exception → capped fallback ----------