test_error_handling_with_success_path() — langchain Function Reference
Architecture documentation for the test_error_handling_with_success_path() function in test_wrap_model_call.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 512d51dd_0a96_1808_db39_6bbbb81c54a5["test_error_handling_with_success_path()"] af226bc7_9003_a498_4aba_5a5b0a9f8c0c["TestErrorHandling"] 512d51dd_0a96_1808_db39_6bbbb81c54a5 -->|defined in| af226bc7_9003_a498_4aba_5a5b0a9f8c0c style 512d51dd_0a96_1808_db39_6bbbb81c54a5 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 445–493
def test_error_handling_with_success_path(self) -> None:
"""Test that error handling middleware works correctly on both success and error paths."""
call_log = []
class ErrorRecoveryMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelCallResult:
try:
call_log.append("before-yield")
result = handler(request)
call_log.append("after-yield-success")
except Exception:
call_log.append("caught-error")
return AIMessage(content="Recovered from error")
return result
# Test 1: Success path
call_log.clear()
model1 = GenericFakeChatModel(messages=iter([AIMessage(content="Success")]))
agent1 = create_agent(model=model1, middleware=[ErrorRecoveryMiddleware()])
result1 = agent1.invoke({"messages": [HumanMessage("Test")]})
assert result1["messages"][1].content == "Success"
assert call_log == ["before-yield", "after-yield-success"]
# Test 2: Error path
call_log.clear()
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)
model2 = AlwaysFailModel(messages=iter([]))
agent2 = create_agent(model=model2, middleware=[ErrorRecoveryMiddleware()])
result2 = agent2.invoke({"messages": [HumanMessage("Test")]})
assert result2["messages"][1].content == "Recovered from error"
assert call_log == ["before-yield", "caught-error"]
Domain
Subdomains
Source
Frequently Asked Questions
What does test_error_handling_with_success_path() do?
test_error_handling_with_success_path() 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_error_handling_with_success_path() defined?
test_error_handling_with_success_path() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 445.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free