Skip to content

Commit d3b4bd9

Browse files
committed
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
1 parent 22fc332 commit d3b4bd9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/google/adk/tools/load_web_page.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ def load_web_page(url: str) -> str:
2828
Returns:
2929
str: The text content of the url.
3030
"""
31-
from bs4 import BeautifulSoup
31+
try:
32+
from bs4 import BeautifulSoup
33+
import lxml # noqa: F401 -- verify lxml is available for the parser
34+
except ImportError as e:
35+
raise ImportError(
36+
'load_web_page requires the "beautifulsoup4" and "lxml" packages. '
37+
'Install them with: pip install google-adk[extensions]'
38+
) from e
3239

3340
# Set allow_redirects=False to prevent SSRF attacks via redirection.
3441
response = requests.get(url, allow_redirects=False)

0 commit comments

Comments
 (0)