Skip to content

fix: fall back to str() when a tool result's to_dict fails - #13843

Open
aryamangodara wants to merge 1 commit into
deepset-ai:mainfrom
aryamangodara:fix/tool-result-to-dict-fallback
Open

aryamangodara wants to merge 1 commit into
deepset-ai:mainfrom
aryamangodara:fix/tool-result-to-dict-fallback

Conversation

@aryamangodara

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

_result_to_string promises a str() fallback when a tool result can't be serialized, but the _serializable_value call (which calls result.to_dict()) sat outside the try. When an Agent tool returns an object whose to_dict raises, is not callable, or needs arguments, the error escaped the fallback. It then went past the ToolInvocationError handling and stopped the whole Agent run, even with raise_on_failure=False.

The fix moves the _serializable_value call inside the existing try, so these results get the documented warning and str(result) conversion. coerce_tag_value in haystack/tracing/utils.py already guards the same call this way.

The earlier PR for this issue (#13783) was auto-closed because its CLA was not signed.

How did you test it?

  • New parametrized unit test for _result_to_string, covering a to_dict that raises, one that isn't callable, and one that needs an argument. It also checks that the fallback warning is logged.
  • New _run_tool test: a Tool returning such an object now produces a normal tool result message ("<broken>", no error) instead of raising.
  • All 4 new tests fail on main and pass with the fix. test/components/agents/ passes (378 passed), and hatch run fmt and hatch run test:types are clean.

Notes for the reviewer

This is a one-line move. The except Exception block and its warning are unchanged.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aryamangodara
aryamangodara requested a review from a team as a code owner November 20, 2026 16:33
@aryamangodara
aryamangodara requested review from sjrl and removed request for a team November 20, 2026 16:33
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@aryamangodara is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added P2 Medium priority, add to the next sprint if no P1 available topic:tests labels Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/agents
  tool_calling.py
Project Total  

This report was generated by python-coverage-comment-action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium priority, add to the next sprint if no P1 available topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent run aborts instead of falling back to str() when a tool result's to_dict fails

1 participant