Skip to content

fix(python): serialize native values in tool results - #2374

Open
OllieinCanada wants to merge 1 commit into
github:mainfrom
OllieinCanada:fix/python-plain-tool-result-types
Open

fix(python): serialize native values in tool results#2374
OllieinCanada wants to merge 1 commit into
github:mainfrom
OllieinCanada:fix/python-plain-tool-result-types

Conversation

@OllieinCanada

Copy link
Copy Markdown

Fixes #2203

Summary

Complete the plain-container serialization case intentionally left out of #2225. Python tool handlers can now return dictionaries containing common native values without those successful results being converted into opaque tool failures.

Fix

Extend the existing json.dumps fallback with the same JSON-safe representations used for Pydantic tool results:

  • datetime, date, and time values use ISO 8601 strings
  • UUID and Decimal values use strings
  • Enum values use their underlying value
  • sets use JSON arrays

Unsupported objects continue to raise the existing clear serialization error.

Tests

The regression test failed on current main with:

TypeError: Failed to serialize tool result: Object of type UUID is not JSON serializable

Passing validation:

  • Python 3.13: 42 tool tests passed
  • Python 3.11 (the oldest CI version): 42 tool tests passed
  • complete offline root suite: 209 tests passed
  • Ruff formatting check passed
  • Ruff lint passed
  • ty check copilot passed
  • git diff --check passed

No Copilot session, model, paid API, or external service is required for the regression test. Authenticated runtime E2E tests were not run locally.

Signed-off-by: Oliver Slapinski <olliefromcanada@gmail.com>
@OllieinCanada
OllieinCanada requested a review from a team as a code owner August 22, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: tool results containing datetime/UUID/Decimal/Enum are reported to the model as a tool failure

1 participant