From d3b4bd9c63046d664df2335716dcf6a81b09fa80 Mon Sep 17 00:00:00 2001 From: brucearctor <5032356+brucearctor@users.noreply.github.com> Date: Mon, 16 Mar 2026 17:12:15 -0700 Subject: [PATCH] fix: improve error message when beautifulsoup4/lxml not installed for load_web_page The load_web_page tool requires beautifulsoup4 and lxml, which are available via the [extensions] optional dependency group. Previously, calling the tool without these packages installed produced a raw ModuleNotFoundError, giving no guidance on how to resolve it. This wraps the deferred imports in try/except to provide a clear, actionable error message directing users to install the missing packages with: pip install google-adk[extensions] Fixes #4852 --- src/google/adk/tools/load_web_page.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/google/adk/tools/load_web_page.py b/src/google/adk/tools/load_web_page.py index e7419c9fbf..270af5cfb1 100644 --- a/src/google/adk/tools/load_web_page.py +++ b/src/google/adk/tools/load_web_page.py @@ -28,7 +28,14 @@ def load_web_page(url: str) -> str: Returns: str: The text content of the url. """ - from bs4 import BeautifulSoup + try: + from bs4 import BeautifulSoup + import lxml # noqa: F401 -- verify lxml is available for the parser + except ImportError as e: + raise ImportError( + 'load_web_page requires the "beautifulsoup4" and "lxml" packages. ' + 'Install them with: pip install google-adk[extensions]' + ) from e # Set allow_redirects=False to prevent SSRF attacks via redirection. response = requests.get(url, allow_redirects=False)