AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Agentic Run With Dynamic Filtering (Web_search_20260209) Fails Due To Missing Code_execution_tool_result Block

LangChain agent using Anthropic's web_search_20260209 tool intermittently fails with a 400 error because the request payload includes a code_execution tool_use without a corresponding code_execution_tool_result. This occurs when web_search triggers automatic code_execution and LangChain's message handling drops the tool result.

highConfidence 75%LangchainAffected Vlangchain==1.3.14Affected Vlangchain-Core==1.5.3Affected Vlanggraph==1.2.10Affected Vlangchain-Anthropic==1.5.4Affected Vanthropic==0.120.2

Origin Analysis

In langchain-anthropic's message conversion or retry middleware, when the model returns a message containing both web_search_tool_result and code_execution_tool_use, the subsequent tool_result for code_execution is not properly included in the next request sent to Anthropic. This leads to an invalid payload where a code_execution tool_use block is present without its required tool_result.
Run the provided reproduction code with a query that triggers deep web_search, causing Anthropic to automatically use code_execution. Observe intermittent 400 error: 'code_execution tool use with id ... was found without a corresponding code_execution_tool_result block'. The error occurs during the agent's model call.

Fixing Code Block

Edge Case Audit

Inserting empty tool results may mask underlying issues where the actual result is missing due to a bug or real tool failure, potentially causing the model to misinterpret the situation. This is a workaround; the root cause should be fixed in LangChain. Test thoroughly and monitor for unexpected model behavior. To rollback, remove the middleware and restart the agent.

Ecosystem Topology