Skip to content

Bug: ValueError crash when LLM outputs "args" instead of "tool_args" #1512

@wgnrai

Description

@wgnrai

Bug Report

Problem

In agent.py, process_tools() calls validate_tool_request(tool_request) without normalizing the dictionary first. Some LLMs output "args" instead of "tool_args".

This causes a crash:

ValueError: Tool request must have a tool_args (type dictionary) field

Location

agent.py line ~877-878:

if tool_request is not None:
    await self.validate_tool_request(tool_request)

Reproduction

  1. Use an LLM that outputs "args" key instead of "tool_args"
  2. Tool request JSON: {"tool_name": "some_tool", "args": {...}}
  3. validate_tool_request() raises ValueError

Proposed Fix

Add normalization before validation:

if tool_request is not None:
    # Normalize: map "args" -> "tool_args", default to empty dict
    if "tool_args" not in tool_request:
        tool_request["tool_args"] = tool_request.get("args", {})
    if not isinstance(tool_request["tool_args"], dict):
        tool_request["tool_args"] = {}
    await self.validate_tool_request(tool_request)

Consistent with downstream handling at line ~882:

tool_args = tool_request.get("tool_args", tool_request.get("args", {}))

Impact

  • Prevents crashes with LLMs using non-standard key naming
  • No behavior change for correctly formatted requests
  • Defensive programming for edge cases

PR ready with this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions