Home / Function/ test_union_of_types() — langchain Function Reference

test_union_of_types() — langchain Function Reference

Architecture documentation for the test_union_of_types() function in test_response_format.py from the langchain codebase.

Function python LangChainCore Runnables calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  c948cda5_5fc6_2444_e1bf_c723dd398626["test_union_of_types()"]
  d1d579f8_d411_ce75_6fa3_d97e725405cb["TestResponseFormatAsToolStrategy"]
  c948cda5_5fc6_2444_e1bf_c723dd398626 -->|defined in| d1d579f8_d411_ce75_6fa3_d97e725405cb
  23781697_11db_b103_59c5_3967778fc4f2["test_union_of_types()"]
  23781697_11db_b103_59c5_3967778fc4f2 -->|calls| c948cda5_5fc6_2444_e1bf_c723dd398626
  23781697_11db_b103_59c5_3967778fc4f2["test_union_of_types()"]
  c948cda5_5fc6_2444_e1bf_c723dd398626 -->|calls| 23781697_11db_b103_59c5_3967778fc4f2
  style c948cda5_5fc6_2444_e1bf_c723dd398626 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 368–416

    def test_union_of_types(self) -> None:
        """Test response_format as ToolStrategy with Union of various types."""
        # Test with WeatherBaseModel
        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, get_location],
            response_format=ToolStrategy(WeatherBaseModel | LocationResponse),
        )
        response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})

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

        # Test with LocationResponse
        tool_calls_location = [
            [{"args": {}, "id": "1", "name": "get_location"}],
            [
                {
                    "name": "LocationResponse",
                    "id": "2",
                    "args": LOCATION_DATA,
                }
            ],
        ]

        model_location = FakeToolCallingModel(tool_calls=tool_calls_location)

        agent_location = create_agent(
            model_location,
            [get_weather, get_location],
            response_format=ToolStrategy(WeatherBaseModel | LocationResponse),
        )
        response_location = agent_location.invoke({"messages": [HumanMessage("Where am I?")]})

        assert response_location["structured_response"] == EXPECTED_LOCATION
        assert len(response_location["messages"]) == 5

Domain

Subdomains

Frequently Asked Questions

What does test_union_of_types() do?
test_union_of_types() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is test_union_of_types() defined?
test_union_of_types() is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 368.
What does test_union_of_types() call?
test_union_of_types() calls 1 function(s): test_union_of_types.
What calls test_union_of_types()?
test_union_of_types() is called by 1 function(s): test_union_of_types.

Analyze Your Own Codebase

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

Try Supermodel Free