From b5a6402e7299e1c74dbab38a184ef49c64e48a29 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:06:37 +0100 Subject: [PATCH] Handle missing search results safely Guard against a None result or missing 'results' key by iterating over (result or {}).get('results', []) instead of result['results']. This prevents exceptions when the search backend returns no data and yields an empty output list while preserving existing behavior of limiting to SEARCH_ENGINE_RESULTS. --- python/tools/search_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tools/search_engine.py b/python/tools/search_engine.py index 9891e46b9..9df4967c7 100644 --- a/python/tools/search_engine.py +++ b/python/tools/search_engine.py @@ -32,7 +32,7 @@ class SearchEngine(Tool): return f"{source} search failed: {str(result)}" outputs = [] - for item in result["results"]: + for item in (result or {}).get("results", []): outputs.append(f"{item['title']}\n{item['url']}\n{item['content']}") return "\n\n".join(outputs[:SEARCH_ENGINE_RESULTS]).strip()