~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): guard central think-strip against non-string content (follow-up to #4343) (#4611)
LearningCircuit54ef628cbfd4
diff --git a/changelog.d/+harden-central-think-strip.bugfix.md b/changelog.d/+harden-central-think-strip.bugfix.mdnew file mode 100644index 0000000000..7f3d344451--- /dev/null+++ b/changelog.d/+harden-central-think-strip.bugfix.md@@ -0,0 +1 @@+Harden the central `ProcessingLLMWrapper` think-tag stripping against non-string responses. `remove_think_tags` is text-only, so it now runs only when `response.content` is a `str`; non-string content (e.g. provider content-block lists such as Anthropic's, or `None`) is passed through unchanged instead of raising `TypeError`. This removes the wrapper-level crash that the per-site `str(...)` guards used to absorb before they were dropped. Note: a few direct `.content` consumers still assume string content, so robust list-content handling at those call sites is tracked separately.diff --git a/changelog.d/+remove-redundant-think-stripping.bugfix.md b/changelog.d/+remove-redundant-think-stripping.bugfix.mdindex 938c421524..d4c3564552 100644--- a/changelog.d/+remove-redundant-think-stripping.bugfix.md+++ b/changelog.d/+remove-redundant-think-stripping.bugfix.md@@ -1 +1 @@-Remove redundant per-site `<think>`-tag stripping now that `get_llm` LLMs are normalized centrally in `ProcessingLLMWrapper`. Direct `self.model.invoke(...).content` is already think-stripped, so ~25 scattered `remove_think_tags(...)` calls across the search strategies, constraint/evidence/knowledge components, and synthesis path were dropped (relying on the single central strip point), keeping explicit handling only where it is load-bearing (agent/`bind_tools` paths, injected LLMs). Empty-answer fallbacks now log a warning so a silent degrade is visible.+Remove redundant per-site `<think>`-tag stripping now that `get_llm` LLMs are normalized centrally in `ProcessingLLMWrapper`. Direct `self.model.invoke(...).content` is already think-stripped, so 11 scattered stripping calls (6 `remove_think_tags(...)` and 5 `get_llm_response_text(...)`) across the constraint/evidence/knowledge components, the synthesis path, and the document-analysis API were dropped (relying on the single central strip point), keeping explicit handling only where it is load-bearing (agent/`bind_tools` paths, injected LLMs). Empty-answer fallbacks now log a warning so a silent degrade is visible.diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.pyindex 953fd73692..1ea4a9e902 100644--- a/src/local_deep_research/config/llm_config.py+++ b/src/local_deep_research/config/llm_config.py@@ -411,9 +411,17 @@ def wrap_llm_without_think_tags(A bare-string return (some providers/wrappers) is wrapped into an``AIMessage`` so callers can always rely on ``.content``. Anythingelse is passed through unchanged.++ Only *string* ``.content`` is stripped: ``remove_think_tags`` is+ text-only, and the ``<think>...</think>`` artifact is only ever+ emitted as plain text by some local models. Non-string content+ (e.g. provider content-block lists like Anthropic's, or ``None``)+ is passed through untouched — running the regex on it would raise+ ``TypeError`` or corrupt the structured content."""if hasattr(response, "content"):- response.content = remove_think_tags(response.content)+ if isinstance(response.content, str):+ response.content = remove_think_tags(response.content)elif isinstance(response, str):response = AIMessage(content=remove_think_tags(response))return responsediff --git a/tests/config/test_llm_config.py b/tests/config/test_llm_config.pyindex 9449a490a8..744bd5c220 100644--- a/tests/config/test_llm_config.py+++ b/tests/config/test_llm_config.py@@ -117,6 +117,38 @@ class TestWrapLlmWithoutThinkTags:wrapper.invoke("test")mock_remove.assert_called_with("<think>internal</think>visible")+ def test_wrapper_preserves_nonstring_content(self):+ """Non-string content (e.g. provider content-block lists) must pass+ through unchanged instead of raising TypeError in remove_think_tags."""+ mock_llm = MagicMock()+ mock_response = MagicMock()+ blocks = [{"type": "text", "text": "visible"}]+ mock_response.content = blocks+ mock_llm.invoke.return_value = mock_response++ with patch(+ "local_deep_research.config.llm_config.get_setting_from_snapshot",+ return_value=False,+ ):+ wrapper = wrap_llm_without_think_tags(mock_llm)+ result = wrapper.invoke("test")+ assert result.content == blocks++ def test_wrapper_preserves_none_content(self):+ """None content must pass through unchanged rather than raising."""+ mock_llm = MagicMock()+ mock_response = MagicMock()+ mock_response.content = None+ mock_llm.invoke.return_value = mock_response++ with patch(+ "local_deep_research.config.llm_config.get_setting_from_snapshot",+ return_value=False,+ ):+ wrapper = wrap_llm_without_think_tags(mock_llm)+ result = wrapper.invoke("test")+ assert result.content is None+def test_wrapper_delegates_attributes(self):"""Should delegate attribute access to base LLM."""mock_llm = MagicMock()