Home / Function/ test_union_of_json_schemas() — langchain Function Reference

test_union_of_json_schemas() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8d21588c_aba4_ffd7_81ac_eec7bb006bcc["test_union_of_json_schemas()"]
  d1d579f8_d411_ce75_6fa3_d97e725405cb["TestResponseFormatAsToolStrategy"]
  8d21588c_aba4_ffd7_81ac_eec7bb006bcc -->|defined in| d1d579f8_d411_ce75_6fa3_d97e725405cb
  style 8d21588c_aba4_ffd7_81ac_eec7bb006bcc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 319–366

    def test_union_of_json_schemas(self) -> None:
        """Test response_format as ToolStrategy with union of JSON schemas."""
        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, get_location],
            response_format=ToolStrategy({"oneOf": [weather_json_schema, location_json_schema]}),
        )
        response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})

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

        # Test with LocationResponse
        tool_calls_location = [
            [{"args": {}, "id": "1", "name": "get_location"}],
            [
                {
                    "name": "location_schema",
                    "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({"oneOf": [weather_json_schema, location_json_schema]}),
        )
        response_location = agent_location.invoke({"messages": [HumanMessage("Where am I?")]})

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

Domain

Subdomains

Frequently Asked Questions

What does test_union_of_json_schemas() do?
test_union_of_json_schemas() 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_json_schemas() defined?
test_union_of_json_schemas() is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 319.

Analyze Your Own Codebase

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

Try Supermodel Free