Skip to content

~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.

Fix Guardian snippets-only search behavior (#7085)

LearningCircuitf6119b9f32a3
diff --git a/changelog.d/7043.bugfix.md b/changelog.d/7043.bugfix.md
new file mode 100644
index 0000000000..c2883267fe
--- /dev/null
+++ b/changelog.d/7043.bugfix.md
@@ -0,0 +1 @@
+Guardian search now respects snippets-only mode: it requests article bodies only for full-content searches and does not return cached bodies in preview results.
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py
index b70e47c787..41255b1d89 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py
@@ -31,6 +31,7 @@ class GuardianSearchEngine(BaseSearchEngine):
max_filtered_results: Optional[int] = None,
optimize_queries: bool = True,
adaptive_search: bool = True,
+ search_snippets_only: bool = True,
settings_snapshot: Optional[Dict[str, Any]] = None,
**kwargs,
):
@@ -48,12 +49,14 @@ class GuardianSearchEngine(BaseSearchEngine):
max_filtered_results: Maximum number of results to keep after filtering
optimize_queries: Whether to optimize queries using LLM
adaptive_search: Whether to use adaptive search (adjusting date ranges)
+ search_snippets_only: Whether to request and return previews only
"""
# Initialize the BaseSearchEngine with LLM, max_filtered_results, and max_results
super().__init__(
llm=llm,
max_filtered_results=max_filtered_results,
max_results=max_results,
+ search_snippets_only=search_snippets_only,
settings_snapshot=settings_snapshot,
)
@@ -325,8 +328,8 @@ ONE WORD ONLY:"""
def _get_all_data(self, query: str) -> List[Dict[str, Any]]:
"""
- Get all article data from The Guardian API in a single call.
- Always requests all fields for simplicity.
+ Get article data from The Guardian API in a single call.
+ Request article bodies only when full content is enabled.
Args:
query: The search query
@@ -347,7 +350,6 @@ ONE WORD ONLY:"""
)
query = query[:100]
- # Always request all fields for simplicity
# Ensure max_results is an integer to avoid comparison errors
page_size = min(
int(self.max_results) if self.max_results is not None else 10,
@@ -367,7 +369,11 @@ ONE WORD ONLY:"""
"to-date": self.to_date,
"order-by": self.order_by,
"page-size": page_size, # API maximum is 50
- "show-fields": "headline,trailText,byline,body,publication",
+ "show-fields": (
+ "headline,trailText,byline,publication"
+ if self.search_snippets_only
+ else "headline,trailText,byline,body,publication"
+ ),
"show-tags": "keyword",
}
@@ -399,7 +405,7 @@ ONE WORD ONLY:"""
articles = data.get("response", {}).get("results", [])
logger.info(f"Guardian API returned {len(articles)} articles")
- # Format results to include all data
+ # Format results for the selected content mode
formatted_articles = []
for i, article in enumerate(articles):
if i >= self.max_results:
@@ -407,7 +413,6 @@ ONE WORD ONLY:"""
fields = article.get("fields", {})
- # Format the article with all fields
result = {
"id": article.get("id", ""),
"title": fields.get(
@@ -418,10 +423,12 @@ ONE WORD ONLY:"""
"publication_date": article.get("webPublicationDate", ""),
"section": article.get("sectionName", ""),
"author": fields.get("byline", ""),
- "content": fields.get("body", ""),
- "full_content": fields.get("body", ""),
}
+ if not self.search_snippets_only:
+ result["content"] = fields.get("body", "")
+ result["full_content"] = fields.get("body", "")
+
# Extract tags/keywords
tags = article.get("tags", [])
result["keywords"] = [
@@ -606,8 +613,13 @@ ONE WORD ONLY:"""
else:
filtered_items = previews
- # Get full content for relevant items
- results = self._get_full_content(filtered_items)
+ # Relevance filtering operates on previews in both modes. Only
+ # restore cached bodies when full content was requested.
+ results = (
+ filtered_items
+ if self.search_snippets_only
+ else self._get_full_content(filtered_items)
+ )
# Add source information to make it clear these are from The Guardian
for result in results:
diff --git a/tests/security/test_api_key_leakage.py b/tests/security/test_api_key_leakage.py
index 99651fb0b8..14d0f63559 100644
--- a/tests/security/test_api_key_leakage.py
+++ b/tests/security/test_api_key_leakage.py
@@ -802,6 +802,7 @@ class TestSearchEngineParamsKeyLeakage:
engine.to_date = "2024-12-31"
engine.order_by = "relevance"
engine.section = None
+ engine.search_snippets_only = True
engine.engine_type = "test_engine"
engine.rate_tracker = _stub_rate_tracker()
engine._raise_if_rate_limit = lambda *a, **k: None
diff --git a/tests/web_search_engines/engines/test_guardian_coverage.py b/tests/web_search_engines/engines/test_guardian_coverage.py
index af02c908c8..1622c92172 100644
--- a/tests/web_search_engines/engines/test_guardian_coverage.py
+++ b/tests/web_search_engines/engines/test_guardian_coverage.py
@@ -471,7 +471,7 @@ class TestGetAllDataLogic:
"local_deep_research.web_search_engines.engines.search_engine_guardian.safe_get",
return_value=resp,
):
- engine = _make_engine()
+ engine = _make_engine(search_snippets_only=False)
results = engine._get_all_data("test")
r = results[0]
assert set(r.keys()) == {
@@ -859,7 +859,7 @@ class TestRunMethod:
def test_source_field_added(self):
"""Results get 'source': 'The Guardian' added."""
- engine = _make_engine()
+ engine = _make_engine(search_snippets_only=False)
previews = [
{
"id": "a1",
@@ -883,7 +883,7 @@ class TestRunMethod:
def test_existing_source_not_overwritten(self):
"""If result already has 'source', it's not overwritten."""
- engine = _make_engine()
+ engine = _make_engine(search_snippets_only=False)
previews = [
{
"id": "a1",
@@ -907,7 +907,11 @@ class TestRunMethod:
def test_dates_restored_after_run(self):
"""Original date params restored after a successful run."""
- engine = _make_engine(from_date="2024-01-01", to_date="2024-12-31")
+ engine = _make_engine(
+ from_date="2024-01-01",
+ to_date="2024-12-31",
+ search_snippets_only=False,
+ )
previews = [
{
"id": "a1",
@@ -946,7 +950,7 @@ class TestRunMethod:
def test_cache_cleaned_up_after_run(self):
"""_full_articles and _search_metadata are cleaned up."""
- engine = _make_engine()
+ engine = _make_engine(search_snippets_only=False)
previews = [
{
"id": "a1",
diff --git a/tests/web_search_engines/engines/test_guardian_snippets_contract.py b/tests/web_search_engines/engines/test_guardian_snippets_contract.py
new file mode 100644
index 0000000000..e599aea27f
--- /dev/null
+++ b/tests/web_search_engines/engines/test_guardian_snippets_contract.py
@@ -0,0 +1,134 @@
+"""Guardian snippet/full-content behavior through the real engine and factory."""
+
+from unittest.mock import Mock, patch
+
+import pytest
+
+from local_deep_research.web_search_engines.engines.search_engine_guardian import (
+ GuardianSearchEngine,
+)
+from local_deep_research.web_search_engines.search_engine_factory import (
+ create_search_engine,
+)
+
+
+def _api_response(*articles):
+ response = Mock()
+ response.json.return_value = {"response": {"results": list(articles)}}
+ return response
+
+
+def _article(article_id, body):
+ return {
+ "id": article_id,
+ "webTitle": f"Title {article_id}",
+ "webUrl": f"https://www.theguardian.com/{article_id}",
+ "webPublicationDate": "2026-10-01T12:00:00Z",
+ "sectionName": "News",
+ "fields": {
+ "headline": f"Title {article_id}",
+ "trailText": f"Preview {article_id}",
+ "byline": "Reporter",
+ # Return a body even when not requested to prove it cannot leak.
+ "body": body,
+ },
+ "tags": [],
+ }
+
+
+ ("snapshot_value", "override", "snippets_only"),
+ [
+ (True, None, True),
+ (False, None, False),
+ (False, True, True),
+ (True, False, False),
+ ],
+)
+def test_factory_setting_controls_guardian_request_and_result(
+ snapshot_value, override, snippets_only
+):
+ snapshot = {
+ "search.tool": {"value": "guardian"},
+ "search.snippets_only": {"value": snapshot_value},
+ "search.engine.web.guardian.api_key": {"value": "test-key"},
+ }
+ config = {
+ "guardian": {
+ "module_path": ".engines.search_engine_guardian",
+ "class_name": "GuardianSearchEngine",
+ "requires_api_key": True,
+ "default_params": {},
+ }
+ }
+ kwargs = {"search_snippets_only": override} if override is not None else {}
+
+ with patch(
+ "local_deep_research.web_search_engines.search_engine_factory.search_config",
+ return_value=config,
+ ):
+ engine = create_search_engine(
+ "guardian",
+ settings_snapshot=snapshot,
+ programmatic_mode=True,
+ adaptive_search=False,
+ **kwargs,
+ )
+
+ assert isinstance(engine, GuardianSearchEngine)
+ assert engine.search_snippets_only is snippets_only
+ engine.rate_tracker.apply_rate_limit = Mock(return_value=0)
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_guardian.safe_get",
+ return_value=_api_response(_article("one", "Complete article")),
+ ) as get:
+ results = engine.run("climate policy")
+
+ assert len(results) == 1
+ assert results[0]["snippet"] == "Preview one"
+ assert results[0]["source"] == "The Guardian"
+ assert ("body" in get.call_args.kwargs["params"]["show-fields"]) is (
+ not snippets_only
+ )
+ if snippets_only:
+ assert "content" not in results[0]
+ assert "full_content" not in results[0]
+ else:
+ assert results[0]["content"] == "Complete article"
+ assert results[0]["full_content"] == "Complete article"
+ assert not hasattr(engine, "_full_articles")
+
+
[email protected]("snippets_only", [True, False])
+def test_relevance_filter_keeps_selected_article_in_both_modes(snippets_only):
+ engine = GuardianSearchEngine(
+ api_key="test-key",
+ llm=Mock(),
+ max_filtered_results=1,
+ adaptive_search=False,
+ optimize_queries=False,
+ search_snippets_only=snippets_only,
+ )
+ engine.rate_tracker.apply_rate_limit = Mock(return_value=0)
+
+ with (
+ patch(
+ "local_deep_research.web_search_engines.engines.search_engine_guardian.safe_get",
+ return_value=_api_response(
+ _article("one", "Body one"), _article("two", "Body two")
+ ),
+ ),
+ patch.object(
+ engine,
+ "_filter_for_relevance",
+ side_effect=lambda previews, query: previews[1:],
+ ) as filter_results,
+ ):
+ results = engine.run("climate policy")
+
+ filter_results.assert_called_once()
+ assert [item["id"] for item in results] == ["two"]
+ assert ("full_content" in results[0]) is (not snippets_only)
+ if not snippets_only:
+ assert results[0]["full_content"] == "Body two"
diff --git a/tests/web_search_engines/engines/test_search_engine_guardian.py b/tests/web_search_engines/engines/test_search_engine_guardian.py
index d2e5988c6e..e16a0cae34 100644
--- a/tests/web_search_engines/engines/test_search_engine_guardian.py
+++ b/tests/web_search_engines/engines/test_search_engine_guardian.py
@@ -270,7 +270,9 @@ class TestGetAllData:
"local_deep_research.web_search_engines.engines.search_engine_guardian.safe_get",
return_value=mock_response,
):
- engine = GuardianSearchEngine(api_key="test-key")
+ engine = GuardianSearchEngine(
+ api_key="test-key", search_snippets_only=False
+ )
articles = engine._get_all_data("test query")
assert len(articles) == 1
@@ -442,7 +444,9 @@ class TestRun:
GuardianSearchEngine,
)
- engine = GuardianSearchEngine(api_key="test-key")
+ engine = GuardianSearchEngine(
+ api_key="test-key", search_snippets_only=False
+ )
mock_previews = [
{
diff --git a/tests/web_search_engines/test_search_engine_base_query_logging.py b/tests/web_search_engines/test_search_engine_base_query_logging.py
index fed6e4d466..7a758590d5 100644
--- a/tests/web_search_engines/test_search_engine_base_query_logging.py
+++ b/tests/web_search_engines/test_search_engine_base_query_logging.py
@@ -228,6 +228,7 @@ def test_guardian_success_path_omits_the_query_from_search_metadata():
BaseSearchEngine.__init__(engine, programmatic_mode=True)
engine.llm = None
engine.max_filtered_results = None
+ engine.search_snippets_only = False
engine.from_date = "2026-01-01"
engine.to_date = "2026-01-02"
engine.section = None