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 tool results that are Pydantic models, dataclasses, enums or datetimes are sent to the LLM as Python repr #13727
Describe the bug
When a tool used by Agent returns a Pydantic model, a dataclass, an Enum, a set, a datetime/date, a UUID, a Decimal or a path (or a list/dict containing one), the tool result sent back to the LLM is a Python repr, not JSON. _result_to_string calls json.dumps on the result, it fails on the first such value, and the whole result falls back to str(). A warning is also logged on every call.
The same happens end to end with a function tool that returns these values: the ToolCallResult text the model sees is the repr.
Expected behavior {"id": 1, "status": "open"} and {"id": 1, "created": "2026-01-02"}, i.e. JSON, like for plain dicts and for objects that have to_dict().
Additional context
Returning a Pydantic model from a tool is quite common, and the reprs (<Status.OPEN: 'open'>, datetime.date(...)) are noisy for the model. I have a small fix with tests (a default= hook for json.dumps covering these types, still falling back to str() for anything else) and will open a PR.
Activity