Home / Class/ TestResponseFormatAsProviderStrategy Class — langchain Architecture

TestResponseFormatAsProviderStrategy Class — langchain Architecture

Architecture documentation for the TestResponseFormatAsProviderStrategy class in test_response_format.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ab8da393_2432_e6a3_7963_47ccc7b82fac["TestResponseFormatAsProviderStrategy"]
  25dfac39_7273_824a_311a_dd0bb9e1c297["WeatherBaseModel"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|extends| 25dfac39_7273_824a_311a_dd0bb9e1c297
  401ad6d7_e124_f0bd_f962_febd376a0a8d["StructuredOutputValidationError"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|extends| 401ad6d7_e124_f0bd_f962_febd376a0a8d
  8079b08d_a03b_e7fb_161a_d5ca5c8cf796["WeatherDataclass"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|extends| 8079b08d_a03b_e7fb_161a_d5ca5c8cf796
  f7da6efd_a581_ce24_190f_6a7475e8917e["WeatherTypedDict"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|extends| f7da6efd_a581_ce24_190f_6a7475e8917e
  2970c11e_b43a_df0c_1a52_30da10d3689c["test_response_format.py"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|defined in| 2970c11e_b43a_df0c_1a52_30da10d3689c
  061a614a_464f_9e0b_35c0_a82acc8032e9["test_pydantic_model()"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|method| 061a614a_464f_9e0b_35c0_a82acc8032e9
  15eab12c_0956_c53a_4e7b_716084c91cdb["test_validation_error_with_invalid_response()"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|method| 15eab12c_0956_c53a_4e7b_716084c91cdb
  8fc9f189_a950_13c2_aba8_0b5c6642e04d["test_dataclass()"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|method| 8fc9f189_a950_13c2_aba8_0b5c6642e04d
  b3705022_dc43_a898_a2cd_673c954416b8["test_typed_dict()"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|method| b3705022_dc43_a898_a2cd_673c954416b8
  209cba78_883a_6489_8dba_7f596b2fae90["test_json_schema()"]
  ab8da393_2432_e6a3_7963_47ccc7b82fac -->|method| 209cba78_883a_6489_8dba_7f596b2fae90

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 687–786

class TestResponseFormatAsProviderStrategy:
    def test_pydantic_model(self) -> None:
        """Test response_format as ProviderStrategy with Pydantic model."""
        tool_calls = [
            [{"args": {}, "id": "1", "name": "get_weather"}],
        ]

        model = FakeToolCallingModel(
            tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_PYDANTIC
        )

        agent = create_agent(
            model, [get_weather], response_format=ProviderStrategy(WeatherBaseModel)
        )
        response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})

        assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC
        assert len(response["messages"]) == 4

    def test_validation_error_with_invalid_response(self) -> None:
        """Test validation error with invalid response.

        Test that StructuredOutputValidationError is raised when provider strategy
        receives invalid response.
        """
        tool_calls = [
            [{"args": {}, "id": "1", "name": "get_weather"}],
        ]

        # But we're using WeatherBaseModel which has different field requirements
        model = FakeToolCallingModel(
            tool_calls=tool_calls,
            structured_response={"invalid": "data"},  # Wrong structure
        )

        agent = create_agent(
            model, [get_weather], response_format=ProviderStrategy(WeatherBaseModel)
        )

        with pytest.raises(
            StructuredOutputValidationError,
            match=r".*WeatherBaseModel.*",
        ):
            agent.invoke({"messages": [HumanMessage("What's the weather?")]})

    def test_dataclass(self) -> None:
        """Test response_format as ProviderStrategy with dataclass."""
        tool_calls = [
            [{"args": {}, "id": "1", "name": "get_weather"}],
        ]

        model = FakeToolCallingModel(
            tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DATACLASS
        )

        agent = create_agent(
            model, [get_weather], response_format=ProviderStrategy(WeatherDataclass)
        )
        response = agent.invoke(
            {"messages": [HumanMessage("What's the weather?")]},
        )

        assert response["structured_response"] == EXPECTED_WEATHER_DATACLASS
        assert len(response["messages"]) == 4

    def test_typed_dict(self) -> None:
        """Test response_format as ProviderStrategy with TypedDict."""
        tool_calls = [
            [{"args": {}, "id": "1", "name": "get_weather"}],
        ]

        model = FakeToolCallingModel(
            tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DICT
        )

        agent = create_agent(
            model, [get_weather], response_format=ProviderStrategy(WeatherTypedDict)
        )
        response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})

        assert response["structured_response"] == EXPECTED_WEATHER_DICT

Frequently Asked Questions

What is the TestResponseFormatAsProviderStrategy class?
TestResponseFormatAsProviderStrategy is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is TestResponseFormatAsProviderStrategy defined?
TestResponseFormatAsProviderStrategy is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 687.
What does TestResponseFormatAsProviderStrategy extend?
TestResponseFormatAsProviderStrategy extends WeatherBaseModel, StructuredOutputValidationError, WeatherDataclass, WeatherTypedDict.

Analyze Your Own Codebase

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

Try Supermodel Free