TestResponseFormatAsModel Class — langchain Architecture
Architecture documentation for the TestResponseFormatAsModel class in test_response_format.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5b61036b_6078_395b_d306_03640f401013["TestResponseFormatAsModel"] 2970c11e_b43a_df0c_1a52_30da10d3689c["test_response_format.py"] 5b61036b_6078_395b_d306_03640f401013 -->|defined in| 2970c11e_b43a_df0c_1a52_30da10d3689c bceba0ea_866a_8753_87af_396975cc6dbe["test_pydantic_model()"] 5b61036b_6078_395b_d306_03640f401013 -->|method| bceba0ea_866a_8753_87af_396975cc6dbe a1f2424c_4432_780e_f2bc_5180a64b4040["test_dataclass()"] 5b61036b_6078_395b_d306_03640f401013 -->|method| a1f2424c_4432_780e_f2bc_5180a64b4040 af9e7681_f120_a3f3_f3cb_98c627af8e9d["test_typed_dict()"] 5b61036b_6078_395b_d306_03640f401013 -->|method| af9e7681_f120_a3f3_f3cb_98c627af8e9d 3a19584d_56f8_f36c_495e_d0a23bd1d48b["test_json_schema()"] 5b61036b_6078_395b_d306_03640f401013 -->|method| 3a19584d_56f8_f36c_495e_d0a23bd1d48b 7a420102_1432_6217_e6fb_e0d0c6a960f4["test_autostrategy_with_anonymous_json_schema()"] 5b61036b_6078_395b_d306_03640f401013 -->|method| 7a420102_1432_6217_e6fb_e0d0c6a960f4
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 115–229
class TestResponseFormatAsModel:
def test_pydantic_model(self) -> None:
"""Test response_format as 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=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 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=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 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=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 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=weather_json_schema)
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
Source
Frequently Asked Questions
What is the TestResponseFormatAsModel class?
TestResponseFormatAsModel is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is TestResponseFormatAsModel defined?
TestResponseFormatAsModel is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 115.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free