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

Non-Dict Tool Arguments Should Be Set Invalid

Tool call arguments that are valid JSON but not a dictionary (e.g., list, string, number) are incorrectly treated as valid, causing AIMessage ValidationError. The fix adds a type check to mark them as invalid tool calls.

highConfidence 95%LangChainAgentsEmbeddingsAffected V1.1.7

Origin Analysis

In langchain-openai's conversion function, after json.loads, the code only catches JSONDecodeError and does not validate that the result is a dict. When args is a non-dict JSON value, it is passed as the 'args' field for a ToolCall, but ToolCall.args requires dict[str, Any]. This triggers a ValidationError when constructing the AIMessage.
1. Configure an OpenAI chat model with tool calling. 2. Arrange for the model to return a tool call where the arguments JSON is not a dict, e.g., '[1,2,3]' or '"hello"'. 3. Invoke the model and observe a pydantic ValidationError for AIMessage, as the tool_call args is not a dictionary.

Fixing Code Block

Edge Case Audit

This change converts previously crashing cases into invalid tool calls, which is safer. However, it may affect any code that expected a crash or relied on non-dict tool calls (though non-standard). If issues arise, revert by removing the isinstance check. No known concurrency or cross-platform issues.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state