From 53ebcb0bf48dcf77686b58616d76651ba8066b04 Mon Sep 17 00:00:00 2001 From: Eliel Sousa Date: Fri, 28 Aug 2026 01:26:39 -0300 Subject: [PATCH] fix(searxng): preserve upstream HTTP errors instead of returning empty results The search adapter built a SearchResponse from raw_response.json() without checking the status code. A 429 or 503 from the SearXNG instance has no "results" key, so response_json.get("results", []) produced an empty list and the caller received a successful response with zero results. That makes a retryable provider failure indistinguishable from a query that genuinely matched nothing, so fallback between configured search tools never fires. The HTTP handlers for this provider do not call raise_for_status either, so no other layer inspects the status. Raise through the provider's own error class so the existing retry and fallback machinery classifies it. The upstream body is deliberately not included in the message, because it can echo the original query. --- litellm/llms/searxng/search/transformation.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/litellm/llms/searxng/search/transformation.py b/litellm/llms/searxng/search/transformation.py index 4afb8b32e4b..5be8576973d 100644 --- a/litellm/llms/searxng/search/transformation.py +++ b/litellm/llms/searxng/search/transformation.py @@ -204,6 +204,19 @@ class SearXNGSearchConfig(BaseSearchConfig): Returns: SearchResponse with standardized format """ + if not 200 <= raw_response.status_code < 300: + # The HTTP handlers for this provider do not call raise_for_status, + # so an upstream 429/503 would otherwise be parsed as a successful + # response with zero results. The upstream body is deliberately not + # echoed, because it can contain the original query. + raise self.get_error_class( + error_message=( + f"SearXNG search provider returned HTTP {raw_response.status_code}" + ), + status_code=raw_response.status_code, + headers=dict(raw_response.headers), + ) + response_json: Final = raw_response.json() # Transform results to SearchResult objects