Home / Function/ test_selective_error_handling() — langchain Function Reference

test_selective_error_handling() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  0cd07b8b_eafe_5ebf_f9e4_b52d74309f5f["test_selective_error_handling()"]
  af226bc7_9003_a498_4aba_5a5b0a9f8c0c["TestErrorHandling"]
  0cd07b8b_eafe_5ebf_f9e4_b52d74309f5f -->|defined in| af226bc7_9003_a498_4aba_5a5b0a9f8c0c
  style 0cd07b8b_eafe_5ebf_f9e4_b52d74309f5f 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 412–443

    def test_selective_error_handling(self) -> None:
        """Test middleware that only handles specific errors."""

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

        class SelectiveErrorMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ModelCallResult:
                try:
                    return handler(request)
                except ConnectionError:
                    return AIMessage(content="Network issue, try again later")

        model = SpecificErrorModel(messages=iter([]))
        agent = create_agent(model=model, middleware=[SelectiveErrorMiddleware()])

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

        assert result["messages"][1].content == "Network issue, try again later"

Domain

Subdomains

Frequently Asked Questions

What does test_selective_error_handling() do?
test_selective_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_selective_error_handling() defined?
test_selective_error_handling() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 412.

Analyze Your Own Codebase

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

Try Supermodel Free