_send_tool_result: a circular tool result skips the stringify fallback and raises ValueError
Author: sclfczCreated Sep 30, 2026Updated Sep 30, 2026
What happened
ElevenLabsConnector._send_tool_result has a fallback for a client tool result that cannot be encoded, and its comment states the intent:
try:
encoded = json.dumps(message)
except TypeError:
# Better to hand the agent a stringified result than to leave it
# waiting for a message that can never be encoded.
message["result"] = repr(result)
encoded = json.dumps(message)json.dumps raises ValueError (not TypeError) for a circular value, so that case skips the fallback and the exception escapes:
circular = {}
circular["self"] = circular
await connector._send_tool_result(tool_name="t", tool_call_id="id", result=circular, is_error=False)
# ValueError: Circular reference detectedAn unserializable object (object()) does go through the fallback and is sent as a string, so the two non-serializable cases behave differently.
Expected
Both mean the same thing here — the result cannot be encoded — so both should be sent as a string, as the comment promises.
Version
deepeval on main, Python 3.13.
Source: confident-ai/deepeval