Home / Function/ test_decorator_error_handling() — langchain Function Reference

test_decorator_error_handling() — langchain Function Reference

Architecture documentation for the test_decorator_error_handling() function in test_wrap_model_call.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1d2c3e40_e405_10ec_c17a_39755653a1d1["test_decorator_error_handling()"]
  5a3c6db0_0302_046a_d217_22fb3d4e632e["TestWrapModelCallDecorator"]
  1d2c3e40_e405_10ec_c17a_39755653a1d1 -->|defined in| 5a3c6db0_0302_046a_d217_22fb3d4e632e
  style 1d2c3e40_e405_10ec_c17a_39755653a1d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py lines 1101–1131

    def test_decorator_error_handling(self) -> None:
        """Test decorator for error recovery."""

        class AlwaysFailModel(GenericFakeChatModel):
            @override
            def _generate(
                self,
                messages: list[BaseMessage],
                stop: list[str] | None = None,
                run_manager: CallbackManagerForLLMRun | None = None,
                **kwargs: Any,
            ) -> ChatResult:
                msg = "Model error"
                raise ValueError(msg)

        @wrap_model_call
        def error_to_fallback(
            request: ModelRequest,
            handler: Callable[[ModelRequest], ModelResponse],
        ) -> ModelCallResult:
            try:
                return handler(request)
            except Exception:
                return AIMessage(content="Fallback response")

        model = AlwaysFailModel(messages=iter([]))
        agent = create_agent(model=model, middleware=[error_to_fallback])

        result = agent.invoke({"messages": [HumanMessage("Test")]})

        assert result["messages"][1].content == "Fallback response"

Domain

Subdomains

Frequently Asked Questions

What does test_decorator_error_handling() do?
test_decorator_error_handling() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py.
Where is test_decorator_error_handling() defined?
test_decorator_error_handling() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 1101.

Analyze Your Own Codebase

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

Try Supermodel Free