You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Agent run aborts instead of falling back to str() when a tool result's to_dict fails #13782
Describe the bug Agent tool results are converted to a string with _result_to_string, whose docstring promises a str() fallback "if serialization fails". The _serializable_value call sits outside the try block, so when the tool result object has a to_dict attribute that raises, is not callable, or requires arguments, the exception escapes the fallback and aborts the whole run.
In _make_context_bound_invoke/_make_bounded_invoke_async the tool call itself is wrapped in a try that only catches ToolInvocationError, and futures[idx].result() re-raises anything else. So a tool returning such an object kills the Agent run even with raise_on_failure=False, while a tool that itself raises ToolInvocationError is handled gracefully.
Error message
With a tool returning an object whose to_dict raises:
ValueError: boom
raised from haystack/tracing/utils.py (value.to_dict(), line 67) through _result_to_string → _process_tool_output → _build_tool_result_message → future.result(), instead of the documented warning + str(result) fallback.
Non-callable to_dict and to_dict(self, required_arg) produce the equivalent TypeErrors on the same path.
Expected behavior _result_to_string falls back to str() conversion and logs the existing "Tool result is not JSON serializable. Falling back to str conversion." warning, for any serialization failure — including failures of the _serializable_value step, exactly like json.dumps failures already do (coerce_tag_value in tracing/utils.py wraps its _serializable_value call in try/except for the same reason).
Activity