Home / Function/ test_structured_tool_with_different_pydantic_versions() — langchain Function Reference

test_structured_tool_with_different_pydantic_versions() — langchain Function Reference

Architecture documentation for the test_structured_tool_with_different_pydantic_versions() function in test_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  425a2ab7_0854_d77c_2bd5_872d213e44a0["test_structured_tool_with_different_pydantic_versions()"]
  8e7836ae_e72c_f670_72a5_4ca6d46e3555["test_tools.py"]
  425a2ab7_0854_d77c_2bd5_872d213e44a0 -->|defined in| 8e7836ae_e72c_f670_72a5_4ca6d46e3555
  b621c544_d6db_7e8d_7240_9ce08870d71a["foo()"]
  425a2ab7_0854_d77c_2bd5_872d213e44a0 -->|calls| b621c544_d6db_7e8d_7240_9ce08870d71a
  style 425a2ab7_0854_d77c_2bd5_872d213e44a0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/test_tools.py lines 2047–2095

def test_structured_tool_with_different_pydantic_versions(pydantic_model: Any) -> None:
    """This should test that one can type the args schema as a Pydantic model."""

    def foo(a: int, b: str) -> str:
        """Hahaha."""
        return "foo"

    foo_tool = StructuredTool.from_function(
        func=foo,
        args_schema=pydantic_model,
    )

    assert foo_tool.invoke({"a": 5, "b": "hello"}) == "foo"

    args_schema = cast("type[BaseModel]", foo_tool.args_schema)
    if issubclass(args_schema, BaseModel):
        args_json_schema = args_schema.model_json_schema()
    elif issubclass(args_schema, BaseModelV1):
        args_json_schema = args_schema.schema()
    else:
        msg = "Unknown input schema type"
        raise TypeError(msg)
    assert args_json_schema == {
        "properties": {
            "a": {"title": "A", "type": "integer"},
            "b": {"title": "B", "type": "string"},
        },
        "required": ["a", "b"],
        "title": pydantic_model.__name__,
        "type": "object",
    }

    input_schema = foo_tool.get_input_schema()
    if issubclass(input_schema, BaseModel):
        input_json_schema = input_schema.model_json_schema()
    elif issubclass(input_schema, BaseModelV1):
        input_json_schema = input_schema.schema()
    else:
        msg = "Unknown input schema type"
        raise TypeError(msg)
    assert input_json_schema == {
        "properties": {
            "a": {"title": "A", "type": "integer"},
            "b": {"title": "B", "type": "string"},
        },
        "required": ["a", "b"],
        "title": pydantic_model.__name__,
        "type": "object",
    }

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_structured_tool_with_different_pydantic_versions() do?
test_structured_tool_with_different_pydantic_versions() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/test_tools.py.
Where is test_structured_tool_with_different_pydantic_versions() defined?
test_structured_tool_with_different_pydantic_versions() is defined in libs/core/tests/unit_tests/test_tools.py at line 2047.
What does test_structured_tool_with_different_pydantic_versions() call?
test_structured_tool_with_different_pydantic_versions() calls 1 function(s): foo.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free