Skip to content

feat: add timeout and URL scheme validation to load_web_page #4886

@cchinchilla-dev

Description

@cchinchilla-dev

Is your feature request related to a specific problem?

The load_web_page() function in src/google/adk/tools/load_web_page.py calls requests.get() without a timeout parameter. If the target server is unresponsive, the agent hangs indefinitely with no way to recover. Additionally, the function accepts any URL scheme (file://, ftp://, etc.) and does not handle Timeout or ConnectionError exceptions, causing uncontrolled errors to propagate.

Describe the Solution You'd Like

  1. Add timeout=10 to requests.get() to prevent indefinite hangs
  2. Validate that the URL scheme is http or https before making the request
  3. Handle requests.exceptions.Timeout and requests.exceptions.ConnectionError, returning descriptive error messages

Impact on your work

When building agents that use load_web_page as a tool, an unresponsive URL blocks the entire agent execution. This makes production deployments unreliable.

Willingness to contribute

Yes. I will submit a PR with the implementation and unit tests shortly.


Describe Alternatives You've Considered

Wrapping the tool call in a try/except at the agent level, but this pushes error handling to every consumer instead of solving it at the source.

Proposed API / Implementation

N/A - No API changes, only internal hardening. The function signature remains load_web_page(url: str) -> str.

Additional Context

The function already has SSRF protection via allow_redirects=False. These changes complement that existing hardening. The PR includes 11 unit tests covering all new behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tools[Component] This issue is related to tools

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions