fix(core): serialize Pydantic tool results in JSON mode - #8309
Open
Hulk (hulkbig) wants to merge 1 commit into
Open
Hulk (hulkbig) wants to merge 1 commit into
Hulk (hulkbig) wants to merge 1 commit into
Conversation
Author
@microsoft-github-policy-service agree |
Hulk (hulkbig)
marked this pull request as ready for review
October 3, 2026 12:50
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
A tool can complete successfully but still be reported as failed when it returns a Pydantic model containing a
datetime,UUID, orDecimal.BaseTool.run_json()formats the result while constructing itsToolCallEvent. The currentmodel_dump()call keeps these values as Python objects, so the followingjson.dumps()raisesTypeErrorafter the tool has already executed.StaticWorkbenchthen returns that serialization exception withis_error=True.Use
model_dump(mode="json")so Pydantic converts supported field types and applies JSON-only serializers before encoding the result. Keep the existing dictionary/string handling so a custom model serializer that returns a string remains unquoted.Regression coverage includes top-level and nested datetime/UUID/Decimal values, a JSON-only field serializer, and a successful
StaticWorkbenchcall. The execution-path tests assert that the tool executes exactly once. The existing custom string-returning model serializer test remains unchanged and passes.Related issue number
No linked issue. This fixes the Pydantic model branch; it does not change plain dict/list output handling discussed in #7867 and the related open PRs.
Validation
autogen-corepackage suite: 234 passed on Python 3.12.14 and the lockfile's Pydantic 2.10.6poe lint,ruff format --check src tests,poe pyright, andpoe mypypassedgit diff --checkpassedTests were run through
uvwith the repository's pinned check-tool versions. The package test command wasOTEL_TRACES_SAMPLER=always_on PYTEST_XDIST_AUTO_NUM_WORKERS=4 uv run --no-sync poe test. Explicit always-on sampling overrides the test environment's 1% sampling configuration so the existing tracing assertions are deterministic. No model-service credentials or live LLM calls were used. The full monorepo aggregate checks and documentation builds were not run.Checks
AI assistance
AI assistance was used to develop the fix and regression tests and draft this description. The local validation results and limitations are listed above.