Skip to content

fix: accept 'args' alias and null value in validate_tool_request#1491

Open
GratefulDave wants to merge 1 commit intoagent0ai:mainfrom
GratefulDave:fix/validate-tool-args-alias
Open

fix: accept 'args' alias and null value in validate_tool_request#1491
GratefulDave wants to merge 1 commit intoagent0ai:mainfrom
GratefulDave:fix/validate-tool-args-alias

Conversation

@GratefulDave
Copy link
Copy Markdown

Problem

validate_tool_request raises a ValueError intermittently when the LLM emits "args" instead of "tool_args" in its JSON response:

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

The bug is a mismatch between validation and processing:

  • process_tools already handles the "args" alias: .get("tool_args", .get("args", {}))
  • validate_tool_request only accepted "tool_args" — rejecting "args" before process_tools could normalize it

Also, a null / missing tool_args value raised erroneously, even though process_tools already defaults it to {}.

Fix

# Before
if "tool_args" not in tool_request or not isinstance(tool_request.get("tool_args"), dict):
    raise ValueError("Tool request must have a tool_args (type dictionary) field")

# After
tool_args_value = tool_request.get("tool_args", tool_request.get("args"))
if tool_args_value is not None and not isinstance(tool_args_value, dict):
    raise ValueError("Tool request must have a tool_args (type dictionary) field")
  • Accepts "args" as an alias for "tool_args" (matches what process_tools already does)
  • Tolerates null / missing value (downstream already defaults to {})
  • Still raises if the value is present but not a dict (genuine malformat)

Impact

  • Eliminates intermittent ValueError crashes when models use non-standard field names
  • No behaviour change for well-formed requests
  • 2-line change, no new dependencies

Some LLMs intermittently emit 'args' instead of 'tool_args'. The
downstream process_tools() already handles this alias via .get('tool_args',
.get('args', {})), but validate_tool_request() only accepted 'tool_args',
causing a ValueError before process_tools could normalize the response.

Also tolerate a missing/null tool_args value since process_tools already
defaults it to {}. Still raises if the value is present but not a dict.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants