Home / Function/ test_retry_with_custom_function() — langchain Function Reference

test_retry_with_custom_function() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/test_response_format.py lines 566–612

    def test_retry_with_custom_function(self) -> None:
        """Test retry with custom message generation."""
        tool_calls = [
            [
                {
                    "name": "WeatherBaseModel",
                    "id": "1",
                    "args": WEATHER_DATA,
                },
                {
                    "name": "LocationResponse",
                    "id": "2",
                    "args": LOCATION_DATA,
                },
            ],
            [
                {
                    "name": "WeatherBaseModel",
                    "id": "3",
                    "args": WEATHER_DATA,
                },
            ],
        ]

        model = FakeToolCallingModel(tool_calls=tool_calls)

        def custom_message(exception: Exception) -> str:
            if isinstance(exception, MultipleStructuredOutputsError):
                return "Custom error: Multiple outputs not allowed"
            return "Custom error"

        agent = create_agent(
            model,
            [],
            response_format=ToolStrategy(
                WeatherBaseModel | LocationResponse,
                handle_errors=custom_message,
            ),
        )

        response = agent.invoke({"messages": [HumanMessage("Give me weather")]})

        # HumanMessage, AIMessage, ToolMessage, ToolMessage, AI, ToolMessage
        assert len(response["messages"]) == 6
        assert response["messages"][2].content == "Custom error: Multiple outputs not allowed"
        assert response["messages"][3].content == "Custom error: Multiple outputs not allowed"
        assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC

Domain

Subdomains

Frequently Asked Questions

What does test_retry_with_custom_function() do?
test_retry_with_custom_function() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py.
Where is test_retry_with_custom_function() defined?
test_retry_with_custom_function() is defined in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py at line 566.

Analyze Your Own Codebase

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

Try Supermodel Free