Skip to content

Conversation

diego-coder
Copy link

@diego-coder diego-coder commented Jul 30, 2025

Addresses: #30498

Summary

This PR improves the usability and error handling of the RequestsTool family by providing explicit, user-friendly errors when required arguments are missing, and by enhancing documentation for both contributors and users.


Motivation

Previously, initializing any RequestsTool (such as RequestsGetTool) without the required requests_wrapper argument resulted in a generic and potentially confusing Pydantic ValidationError.


What's Changed

  • Code Fix:
    A Pydantic @model_validator has been added to the BaseRequestsTool. It now proactively checks for the required requests_wrapper argument and raises a clear, user-friendly ValueError if it's missing. This fix is inherited by all request tools (GET, POST, etc.).

  • Documentation Fix:
    The docstring for RequestsGetTool has been improved to include a .. warning::, a clear usage example, and a Google-style Args: section detailing the required parameters.

  • Testing:
    Added a unit test (test_requests_tool_missing_wrapper_raises_error) to ensure that the new error handling triggers as intended if requests_wrapper is not provided.

  • Formatting and Linting:
    All affected files have been formatted and linted to match project standards (ruff format and ruff check --fix).


Example Usage

from langchain_community.tools import RequestsGetTool
from langchain_community.utilities import TextRequestsWrapper

# Correct usage: must provide a requests_wrapper
wrapper = TextRequestsWrapper()
tool = RequestsGetTool(
    requests_wrapper=wrapper,
    allow_dangerous_requests=True
)

If the required requests_wrapper is omitted, the following error is now raised:

ValueError: `requests_wrapper` is a required argument for this tool. Please pass in an instance of a RequestsWrapper, e.g. `TextRequestsWrapper()`.

Checklist

  • Added or updated docstrings for all affected classes/functions
  • Added unit test for new error handling
  • Code is formatted and linted to project standards (ruff format / ruff check --fix)
  • All tests pass locally (pytest)

Closes

Closes #214

@diego-coder diego-coder force-pushed the fix/requests-tool-validation-error branch from 2f5df3b to 10d4910 Compare July 30, 2025 02:07
@diego-coder diego-coder force-pushed the fix/requests-tool-validation-error branch from 10d4910 to 8ee81e1 Compare July 30, 2025 04:14
@diego-coder diego-coder force-pushed the fix/requests-tool-validation-error branch from 8ee81e1 to d43bdbd Compare September 10, 2025 03:35
@diego-coder diego-coder force-pushed the fix/requests-tool-validation-error branch from d43bdbd to ce91ebf Compare September 11, 2025 01:03
… and docs

Addresses a common point of confusion where initializing a RequestsTool
without the required `requests_wrapper` argument raises an unhelpful
Pydantic `ValidationError`.

This commit introduces two changes to improve the user experience:
1. A Pydantic `@model_validator` is added to the `BaseRequestsTool` to
   proactively check for `requests_wrapper` and raise a clear ValueError.
2. The `RequestsGetTool` docstring is updated with a usage example and
   explicit documentation for the required arguments.

Closes: #30498
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValidationError while using RequestsGetTool(allow_dangerous_requests=True)
1 participant