Home / Function/ test_bind_tool_pydantic() — langchain Function Reference

test_bind_tool_pydantic() — langchain Function Reference

Architecture documentation for the test_bind_tool_pydantic() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c7e169c4_840e_f43d_6777_4e34e559f8f7["test_bind_tool_pydantic()"]
  f4b40f56_1158_0e72_1cac_d0121e4eabd8["ChatModelUnitTests"]
  c7e169c4_840e_f43d_6777_4e34e559f8f7 -->|defined in| f4b40f56_1158_0e72_1cac_d0121e4eabd8
  style c7e169c4_840e_f43d_6777_4e34e559f8f7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/unit_tests/chat_models.py lines 991–1034

    def test_bind_tool_pydantic(
        self,
        model: BaseChatModel,
        my_adder_tool: BaseTool,
    ) -> None:
        """Test bind tools with Pydantic models.

        Test that chat model correctly handles Pydantic models that are passed
        into `bind_tools`. Test is skipped if the `has_tool_calling` property
        on the test class is False.

        ??? question "Troubleshooting"

            If this test fails, ensure that the model's `bind_tools` method
            properly handles Pydantic V2 models.

            `langchain_core` implements a [utility function](https://reference.langchain.com/python/langchain_core/utils/?h=convert_to_op#langchain_core.utils.function_calling.convert_to_openai_tool).
            that will accommodate most formats.

            See [example implementation](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/base.py).
            of `with_structured_output`.
        """
        if not self.has_tool_calling:
            return

        def my_adder(a: int, b: int) -> int:
            """Return the sum of two integers."""
            return a + b

        tools = [my_adder_tool, my_adder]

        for pydantic_model in TEST_PYDANTIC_MODELS:
            model_schema = (
                pydantic_model.model_json_schema()
                if hasattr(pydantic_model, "model_json_schema")
                else pydantic_model.schema()
            )
            tools.extend([pydantic_model, model_schema])

        # Doing a mypy ignore here since some of the tools are from pydantic
        # BaseModel 2 which isn't typed properly yet. This will need to be fixed
        # so type checking does not become annoying to users.
        tool_model = model.bind_tools(tools, tool_choice="any")  # type: ignore[arg-type]
        assert isinstance(tool_model, RunnableBinding)

Domain

Subdomains

Frequently Asked Questions

What does test_bind_tool_pydantic() do?
test_bind_tool_pydantic() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py.
Where is test_bind_tool_pydantic() defined?
test_bind_tool_pydantic() is defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py at line 991.

Analyze Your Own Codebase

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

Try Supermodel Free