Skip to content

[rollout] feat: improve error messages for malformed tool calls#6055

Open
xiefan46 wants to merge 1 commit intoverl-project:mainfrom
xiefan46:fix-malformed-tool-call
Open

[rollout] feat: improve error messages for malformed tool calls#6055
xiefan46 wants to merge 1 commit intoverl-project:mainfrom
xiefan46:fix-malformed-tool-call

Conversation

@xiefan46
Copy link
Copy Markdown

@xiefan46 xiefan46 commented Apr 18, 2026

Split the catch-all exception handler in _call_tool() into specific error cases so the LLM receives actionable feedback for self-correction:

  • Unknown function name: lists available tools
  • Invalid JSON arguments: reports parse error with tool name
  • Tool execution failure: includes tool name in error message

What does this PR do?

Add concise overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, vllm_omni, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

Added CPU unit tests that call the real _call_tool method via mock.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

…gentLoop

Split the catch-all exception handler in _call_tool() into specific error
cases so the LLM receives actionable feedback for self-correction:

- Unknown function name: lists available tools
- Invalid JSON arguments: reports parse error with tool name
- Tool execution failure: includes tool name in error message

Added CPU unit tests that call the real _call_tool method via mock.
@xiefan46 xiefan46 changed the title [tool] feat: improve error messages for malformed tool calls [rollout] feat: improve error messages for malformed tool calls Apr 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the error handling in the ToolAgentLoop._call_tool method by adding explicit validation for tool names and JSON arguments, providing more descriptive error messages to the agent. It also includes a new set of unit tests to verify these error paths. A potential issue was identified where an exception during the tool release process in the finally block could mask the original execution error; it is recommended to wrap the cleanup logic in its own try-except block to ensure robust error reporting.

Comment on lines 467 to 471
except Exception as e:
logger.warning(f"Error when executing tool: {e}")
return (
ToolResponse(
text=f"Error when executing tool: {e}",
),
0.0,
{},
)
logger.warning(f"Error executing tool '{tool_name}': {e}")
return ToolResponse(text=f"Error executing tool '{tool_name}': {e}"), 0.0, {}
finally:
if tool and instance_id:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The except Exception as e block catches all exceptions during tool creation and execution. However, the finally block at line 470, which calls await tool.release(instance_id), is executed before the return statement in the except block. If tool.release itself raises an exception, it will propagate and suppress the original error message being returned to the LLM. It is recommended to wrap the tool.release call in its own try-except block to ensure that cleanup failures do not mask tool execution errors.

Suggested change
except Exception as e:
logger.warning(f"Error when executing tool: {e}")
return (
ToolResponse(
text=f"Error when executing tool: {e}",
),
0.0,
{},
)
logger.warning(f"Error executing tool '{tool_name}': {e}")
return ToolResponse(text=f"Error executing tool '{tool_name}': {e}"), 0.0, {}
finally:
if tool and instance_id:
except Exception as e:
logger.warning(f"Error executing tool '{tool_name}': {e}")
return ToolResponse(text=f"Error executing tool '{tool_name}': {e}"), 0.0, {}
finally:
if tool and instance_id:
try:
await tool.release(instance_id)
except Exception as release_error:
logger.error(f"Failed to release tool '{tool_name}': {release_error}")

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.

1 participant