{"record":{"id":"cc84817ca4753967","repo":"huggingface/smolagents","slug":"no-results-found-for-query-query-with-filteri","errorCode":null,"errorMessage":"No results found for query: '{query}' with filtering on year={filter_year}. Use a less restrictive query or do not filter on year.","messagePattern":"No results found for query: '(.+?)' with filtering on year=(.+?)\\. Use a less restrictive query or do not filter on year\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"src/smolagents/default_tools.py","lineNumber":219,"sourceCode":"        else:\n            params = {\n                \"q\": query,\n                \"api_key\": self.api_key,\n            }\n            base_url = \"https://google.serper.dev/search\"\n        if filter_year is not None:\n            params[\"tbs\"] = f\"cdr:1,cd_min:01/01/{filter_year},cd_max:12/31/{filter_year}\"\n\n        response = requests.get(base_url, params=params)\n\n        if response.status_code == 200:\n            results = response.json()\n        else:\n            raise ValueError(response.json())\n\n        if self.organic_key not in results.keys():\n            if filter_year is not None:\n                raise Exception(\n                    f\"No results found for query: '{query}' with filtering on year={filter_year}. Use a less restrictive query or do not filter on year.\"\n                )\n            else:\n                raise Exception(f\"No results found for query: '{query}'. Use a less restrictive query.\")\n        if len(results[self.organic_key]) == 0:\n            year_filter_message = f\" with filter year={filter_year}\" if filter_year is not None else \"\"\n            return f\"No results found for '{query}'{year_filter_message}. Try with a more general query, or remove the year filter.\"\n\n        web_snippets = []\n        if self.organic_key in results:\n            for idx, page in enumerate(results[self.organic_key]):\n                date_published = \"\"\n                if \"date\" in page:\n                    date_published = \"\\nDate published: \" + page[\"date\"]\n\n                source = \"\"\n                if \"source\" in page:\n                    source = \"\\nSource: \" + page[\"source\"]","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L201-L237","documentation":"Raised by the search tool's forward when the API response JSON lacks the organic-results key (e.g. 'organic' for Serper, 'organic_results' for SerpAPI) AND a filter_year was applied. It indicates the query (possibly with the year filter appended) returned no organic results.","triggerScenarios":"Calling run(query, filter_year=2015) where the provider response has no organic key — i.e. zero organic hits for the year-filtered query (e.g. 'site:nonexistent.com latest news' with filter_year).","commonSituations":"Agents filtering by year on niche queries, year filters that exclude all results for young topics, or API responses containing only ads/knowledge panels with no organic block.","solutions":["Retry without filter_year.","Broaden the query (fewer quoted terms, remove site: filters).","Catch the exception and let the agent decide to drop the year filter."],"exampleFix":"# before\ntool.run('quantum computing breakthroughs', filter_year=1995)\n# after\ntool.run('quantum computing breakthroughs', filter_year=2024)","handlingStrategy":"retry","validationCode":"null","typeGuard":null,"tryCatchPattern":"try:\n    res = tool.run(q, filter_year=y)\nexcept Exception:\n    res = tool.run(q)  # drop year filter and retry","preventionTips":["Default to no filter_year and only add it when results are too broad.","Instruct agents that empty year-filtered results mean: retry without the filter."],"tags":["search-tool","empty-results","year-filter","smolagents"],"backgroundTag":"search-no-results","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}