langchain_core.exceptions.ToolException: Tool 'search_tool' called with missing required arguments. Expected: ['query'], got: [].
ID: llm/langchain-tool-call-missing-arguments
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| langchain==0.3.0 | active | — | — | — |
| langchain-core==0.3.5 | active | — | — | — |
| langchain-openai==0.2.0 | active | — | — | — |
Root Cause
The LLM generates a tool call with an empty arguments dict or missing required parameters, often due to the model misinterpreting the tool schema or truncating the function call JSON during streaming.
generic中文
LLM 生成一个参数字典为空或缺少必需参数的工具调用,通常是由于模型误解了工具架构,或在流式传输期间截断了函数调用 JSON。
Official Documentation
https://python.langchain.com/docs/how_to/custom_tools/#tool-validationWorkarounds
-
85% success Implement a validation wrapper that catches ToolException and re-prompts the LLM with a correction message: `try: result = tool.run(tool_call) except ToolException: corrected_call = llm.invoke("The previous tool call was invalid. Please provide valid arguments for 'search_tool' with a 'query' string.")`. This allows the model to self-correct.
Implement a validation wrapper that catches ToolException and re-prompts the LLM with a correction message: `try: result = tool.run(tool_call) except ToolException: corrected_call = llm.invoke("The previous tool call was invalid. Please provide valid arguments for 'search_tool' with a 'query' string.")`. This allows the model to self-correct. -
80% success Simplify the tool schema by using primitive types (str, int) instead of complex objects or enums. Example: change `query: Optional[str]` to `query: str = Field(description="...")` to make it required and explicit.
Simplify the tool schema by using primitive types (str, int) instead of complex objects or enums. Example: change `query: Optional[str]` to `query: str = Field(description="...")` to make it required and explicit.
-
75% success Use LangChain's `StructuredTool` with `handle_tool_error=True` to automatically retry with a fallback message: `tool = StructuredTool.from_function(func=search, handle_tool_error=True)`.
Use LangChain's `StructuredTool` with `handle_tool_error=True` to automatically retry with a fallback message: `tool = StructuredTool.from_function(func=search, handle_tool_error=True)`.
中文步骤
实现一个验证包装器,捕获 ToolException 并使用更正消息重新提示 LLM:`try: result = tool.run(tool_call) except ToolException: corrected_call = llm.invoke("之前的工具调用无效。请为 'search_tool' 提供有效的参数,包含 'query' 字符串。")`。这允许模型自我纠正。通过使用原始类型(str、int)而不是复杂对象或枚举来简化工具架构。示例:将 `query: Optional[str]` 改为 `query: str = Field(description="...")` 使其成为必需且明确的参数。
使用 LangChain 的 `StructuredTool` 并设置 `handle_tool_error=True` 以自动重试并回退消息:`tool = StructuredTool.from_function(func=search, handle_tool_error=True)`。
Dead Ends
Common approaches that don't work:
-
65% fail
While helpful, verbose descriptions can confuse the LLM or lead to token limit issues. The root cause is often the model's inability to consistently produce valid JSON for complex schemas.
-
70% fail
Deterministic settings reduce variability but don't fix the underlying schema parsing issue. The model may still generate malformed calls if the prompt or tool definitions are ambiguous.
-
90% fail
Retrying the same request with the same configuration will likely produce the same error because the model's behavior is consistent for the same input.