Home / Class/ TestOutputToolBinding Class — langchain Architecture

TestOutputToolBinding Class — langchain Architecture

Architecture documentation for the TestOutputToolBinding class in test_responses.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488["TestOutputToolBinding"]
  b2d5d1c9_8094_b06e_1bb8_2f5447a93084["_TestModel"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|extends| b2d5d1c9_8094_b06e_1bb8_2f5447a93084
  4ec8d71c_3a26_be00_a621_f5533ddc4441["test_responses.py"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|defined in| 4ec8d71c_3a26_be00_a621_f5533ddc4441
  a44a50c6_1e9d_8261_327f_d4ece2879934["test_from_schema_spec_basic()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| a44a50c6_1e9d_8261_327f_d4ece2879934
  a689f82c_f147_d3cb_dc46_6ffdb22b076f["test_from_schema_spec_with_custom_name()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| a689f82c_f147_d3cb_dc46_6ffdb22b076f
  59db6087_d393_892a_dffd_5aea61b0177b["test_from_schema_spec_with_custom_description()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| 59db6087_d393_892a_dffd_5aea61b0177b
  4bd4d609_46d5_e542_2a04_9724d9106dde["test_from_schema_spec_with_model_docstring()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| 4bd4d609_46d5_e542_2a04_9724d9106dde
  2c538a54_0457_670a_7ba6_e8717123c5fa["test_from_schema_spec_empty_docstring()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| 2c538a54_0457_670a_7ba6_e8717123c5fa
  c01f93cd_d7f4_02fe_2827_bd1b1b0366aa["test_parse_payload_pydantic_success()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| c01f93cd_d7f4_02fe_2827_bd1b1b0366aa
  de966991_32a7_ba85_2752_3cce0387be7b["test_parse_payload_pydantic_validation_error()"]
  eae7aba5_c5d1_1ce4_8c4e_fff8ccef9488 -->|method| de966991_32a7_ba85_2752_3cce0387be7b

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_responses.py lines 134–203

class TestOutputToolBinding:
    """Test OutputToolBinding dataclass and its methods."""

    def test_from_schema_spec_basic(self) -> None:
        """Test basic OutputToolBinding creation from SchemaSpec."""
        schema_spec = _SchemaSpec(schema=_TestModel)
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        assert tool_binding.schema == _TestModel
        assert tool_binding.schema_kind == "pydantic"
        assert tool_binding.tool is not None
        assert tool_binding.tool.name == "_TestModel"

    def test_from_schema_spec_with_custom_name(self) -> None:
        """Test OutputToolBinding creation with custom name."""
        schema_spec = _SchemaSpec(schema=_TestModel, name="custom_tool_name")
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)
        assert tool_binding.tool.name == "custom_tool_name"

    def test_from_schema_spec_with_custom_description(self) -> None:
        """Test OutputToolBinding creation with custom description."""
        schema_spec = _SchemaSpec(schema=_TestModel, description="Custom tool description")
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        assert tool_binding.tool.description == "Custom tool description"

    def test_from_schema_spec_with_model_docstring(self) -> None:
        """Test OutputToolBinding creation using model docstring as description."""
        schema_spec = _SchemaSpec(schema=CustomModel)
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        assert tool_binding.tool.description == "Custom model with a custom docstring."

    def test_from_schema_spec_empty_docstring(self) -> None:
        """Test OutputToolBinding creation with model that has default docstring."""

        # Create a model with the same docstring as BaseModel
        class DefaultDocModel(BaseModel):
            # This should have the same docstring as BaseModel
            pass

        schema_spec = _SchemaSpec(schema=DefaultDocModel)
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        # Should use empty description when model has default BaseModel docstring
        assert not tool_binding.tool.description

    def test_parse_payload_pydantic_success(self) -> None:
        """Test successful parsing for Pydantic model."""
        schema_spec = _SchemaSpec(schema=_TestModel)
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        tool_args = {"name": "John", "age": 30}
        result = tool_binding.parse(tool_args)

        assert isinstance(result, _TestModel)
        assert result.name == "John"
        assert result.age == 30
        assert result.email == "default@example.com"  # default value

    def test_parse_payload_pydantic_validation_error(self) -> None:
        """Test parsing failure for invalid Pydantic data."""
        schema_spec = _SchemaSpec(schema=_TestModel)
        tool_binding = OutputToolBinding.from_schema_spec(schema_spec)

        # Missing required field 'name'
        tool_args = {"age": 30}

        with pytest.raises(ValueError, match="Failed to parse data to _TestModel"):
            tool_binding.parse(tool_args)

Extends

Frequently Asked Questions

What is the TestOutputToolBinding class?
TestOutputToolBinding is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_responses.py.
Where is TestOutputToolBinding defined?
TestOutputToolBinding is defined in libs/langchain_v1/tests/unit_tests/agents/test_responses.py at line 134.
What does TestOutputToolBinding extend?
TestOutputToolBinding extends _TestModel.

Analyze Your Own Codebase

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

Try Supermodel Free