Skip to content

[Agent] Surface tool-argument resolution failures to the LLM - #2365

Merged
chr-hertel merged 1 commit into
symfony:mainfrom
Berenger:fix/2137-surface-tool-argument-resolution-errors
Sep 22, 2026
Merged

chr-hertel merged 1 commit into
symfony:mainfrom
Berenger:fix/2137-surface-tool-argument-resolution-errors

Conversation

@Berenger

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fixes #2137
License MIT

Problem

When ToolCallArgumentResolver::resolveArguments() fails because of invalid LLM-generated tool-call input—such as a missing mandatory parameter or a value that cannot be denormalized (for example, an invalid backed-enum value)—the exception is caught by the generic \Throwable arm in Toolbox::execute().

It is then wrapped in a ToolExecutionException, whose getToolCallResult() only returns:

An error occurred while executing tool "X".

As a result, FaultTolerantToolbox relays no actionable feedback to the model. The model cannot self-correct and typically repeats the same invalid call.

Solution

This PR treats argument-resolution failures as agent-correctable errors by reusing the existing InvalidToolCallArgumentsException.

This exception implements ToolExecutionExceptionInterface, allowing its message to reach the LLM as the tool result. This is the same mechanism already used by ValidateToolCallArgumentsListener.

  • A missing mandatory parameter now throws InvalidToolCallArgumentsException with the existing message:

    Parameter "number" is mandatory for tool "tool_required_params".
    
  • A denormalization failure is caught and rethrown as InvalidToolCallArgumentsException:

    Invalid value for parameter "mode" of tool "tool_with_backed_enums": The data must belong to a backed enumeration of type ...
    

    The original Serializer exception is preserved as the previous exception for debugging and logging purposes, but is not exposed directly to the LLM.

These messages are derived from the model's input and the tool's argument metadata. Exceptions raised during tool execution remain hidden and continue to produce the generic error message.

Compatibility

Code catching the component's ExceptionInterface remains unaffected, since both the old and new exceptions implement it.

Consumers catching the concrete ToolExecutionException may need to handle InvalidToolCallArgumentsException as well.

Technical Note

Toolbox::execute() now initializes $arguments before entering the try block, ensuring that it is safely available to the catch arms, as reported by PHPStan.

Tests

This behavior is covered by:

  • Unit tests for the argument resolver.
  • End-to-end tests through Toolbox and FaultTolerantToolbox.
  • Assertions on the exact error message received by the LLM.

@carsonbot carsonbot added Agent Issues & PRs about the AI Agent component Bug Something isn't working Status: Needs Review labels Jul 25, 2026
@Berenger
Berenger force-pushed the fix/2137-surface-tool-argument-resolution-errors branch from ae3ccf1 to 0e7cd15 Compare July 25, 2026 14:10
@chr-hertel
chr-hertel force-pushed the fix/2137-surface-tool-argument-resolution-errors branch from 0e7cd15 to afbe754 Compare September 22, 2026 22:22
@chr-hertel chr-hertel added the BC Break Breaking the Backwards Compatibility Promise label Sep 22, 2026
@chr-hertel
chr-hertel force-pushed the fix/2137-surface-tool-argument-resolution-errors branch from afbe754 to e50342b Compare September 22, 2026 22:28

@chr-hertel chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay @Berenger - somehow this slipped. I took care about the update and an UPGRADE.md note.

@chr-hertel
chr-hertel force-pushed the fix/2137-surface-tool-argument-resolution-errors branch from e50342b to d06678a Compare September 22, 2026 22:31
@chr-hertel

Copy link
Copy Markdown
Member

Thank you @Berenger.

@chr-hertel
chr-hertel merged commit dc0f572 into symfony:main Sep 22, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Agent Issues & PRs about the AI Agent component BC Break Breaking the Backwards Compatibility Promise Bug Something isn't working Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Agent] Tool-argument resolution failures are not surfaced to the LLM in a correctable form

3 participants