TestResponseFormatAsToolStrategy Class — langchain Architecture
Architecture documentation for the TestResponseFormatAsToolStrategy class in test_response_format.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b84005d0_9099_43da_99ce_9d9b49344d2a["TestResponseFormatAsToolStrategy"] 25484cf0_60a8_c7b3_8913_de5d99a31ab2["WeatherBaseModel"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|extends| 25484cf0_60a8_c7b3_8913_de5d99a31ab2 868855e3_88a1_74b1_6bf3_c26452a31724["WeatherDataclass"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|extends| 868855e3_88a1_74b1_6bf3_c26452a31724 05c29ba6_1e16_e758_0a1e_5e7b7650120f["WeatherTypedDict"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|extends| 05c29ba6_1e16_e758_0a1e_5e7b7650120f d777eb6e_2373_ab32_10cb_5f0019def7b6["MultipleStructuredOutputsError"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|extends| d777eb6e_2373_ab32_10cb_5f0019def7b6 15707763_5f5b_5f3d_bc0c_7057a5ac4cfb["StructuredOutputValidationError"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|extends| 15707763_5f5b_5f3d_bc0c_7057a5ac4cfb 78b88257_eb76_9d35_8abe_db981de29160["test_response_format.py"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|defined in| 78b88257_eb76_9d35_8abe_db981de29160 784128b2_5771_118a_6965_8a8ad5973c42["test_pydantic_model()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| 784128b2_5771_118a_6965_8a8ad5973c42 1bd03361_19a7_f0f5_c185_13040bf23320["test_dataclass()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| 1bd03361_19a7_f0f5_c185_13040bf23320 b0ba21db_9bcc_927c_dfd9_822d2f313f2d["test_typed_dict()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| b0ba21db_9bcc_927c_dfd9_822d2f313f2d 27cc283b_fc88_777c_5e35_72df635fcc15["test_json_schema()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| 27cc283b_fc88_777c_5e35_72df635fcc15 c636a3ed_ebcc_978d_78e0_400ea6344937["test_union_of_json_schemas()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| c636a3ed_ebcc_978d_78e0_400ea6344937 1684dee0_45c0_27e5_54b4_a233a0b19cd8["test_union_of_types()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| 1684dee0_45c0_27e5_54b4_a233a0b19cd8 a2d68ac4_62a8_98dd_b66b_56cd93e4cc3d["test_multiple_structured_outputs_error_without_retry()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| a2d68ac4_62a8_98dd_b66b_56cd93e4cc3d ec022e91_3052_7bcc_53b9_77a39c2df175["test_multiple_structured_outputs_with_retry()"] b84005d0_9099_43da_99ce_9d9b49344d2a -->|method| ec022e91_3052_7bcc_53b9_77a39c2df175
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 232–684
class TestResponseFormatAsToolStrategy:
def test_pydantic_model(self) -> None:
"""Test response_format as ToolStrategy with Pydantic model."""
tool_calls = [
[{"args": {}, "id": "1", "name": "get_weather"}],
[
{
"name": "WeatherBaseModel",
"id": "2",
"args": WEATHER_DATA,
}
],
]
model = FakeToolCallingModel(tool_calls=tool_calls)
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherBaseModel))
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC
assert len(response["messages"]) == 5
def test_dataclass(self) -> None:
"""Test response_format as ToolStrategy with dataclass."""
tool_calls = [
[{"args": {}, "id": "1", "name": "get_weather"}],
[
{
"name": "WeatherDataclass",
"id": "2",
"args": WEATHER_DATA,
}
],
]
model = FakeToolCallingModel(tool_calls=tool_calls)
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherDataclass))
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
assert response["structured_response"] == EXPECTED_WEATHER_DATACLASS
assert len(response["messages"]) == 5
def test_typed_dict(self) -> None:
"""Test response_format as ToolStrategy with TypedDict."""
tool_calls = [
[{"args": {}, "id": "1", "name": "get_weather"}],
[
{
"name": "WeatherTypedDict",
"id": "2",
"args": WEATHER_DATA,
}
],
]
model = FakeToolCallingModel(tool_calls=tool_calls)
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherTypedDict))
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
assert response["structured_response"] == EXPECTED_WEATHER_DICT
assert len(response["messages"]) == 5
def test_json_schema(self) -> None:
"""Test response_format as ToolStrategy with JSON schema."""
tool_calls = [
[{"args": {}, "id": "1", "name": "get_weather"}],
[
{
"name": "weather_schema",
"id": "2",
"args": WEATHER_DATA,
}
],
]
model = FakeToolCallingModel(tool_calls=tool_calls)
agent = create_agent(
model, [get_weather], response_format=ToolStrategy(weather_json_schema)
Extends
Source
Frequently Asked Questions
What is the TestResponseFormatAsToolStrategy class?
TestResponseFormatAsToolStrategy is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is TestResponseFormatAsToolStrategy defined?
TestResponseFormatAsToolStrategy is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 232.
What does TestResponseFormatAsToolStrategy extend?
TestResponseFormatAsToolStrategy extends WeatherBaseModel, WeatherDataclass, WeatherTypedDict, MultipleStructuredOutputsError, StructuredOutputValidationError.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free