Skip to content

fix(schema): keep structured output JSON serializable - #7591

Open
BlueRaddish wants to merge 1 commit into
google:mainfrom
BlueRaddish:fix/oct17-ao-adk
Open

BlueRaddish wants to merge 1 commit into
google:mainfrom
BlueRaddish:fix/oct17-ao-adk

Conversation

@BlueRaddish

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Related to the structured-output serialization problem in #7480. This addresses its date-valued AgentTool output case.

Problem: Validating JSON against a Pydantic output schema currently dumps the resulting model in Python mode. A JSON string such as {"day":"2026-10-17"} becomes a dictionary containing a datetime.date. The real Runner can carry that value into an AgentTool function response, where the Anthropic converter raises TypeError: Object of type date is not JSON serializable.

Solution: Dump validated model and list-of-model output in JSON mode, retaining the existing exclusion of None fields. The shared helper also serves LlmAgent output state and workflow output processing. No API or dependency changes are introduced.

Testing Plan

The identical three new tests produce three genuine baseline failures: model and list output retain Python dates, and an actual offline Runner / AgentTool function response fails in the real public Anthropic converter. All three pass after the fix. The complete schema, AgentTool, LlmAgent workflow-node and Anthropic owning files pass 401 tests.

Exact normally-hooked native commit a01591c78332256ca14579184f4e9091779d3851 passes the unchanged full supported tox matrix on four isolated public Ubuntu runners:

Python Full-suite job Passed Skipped Xfailed Xpassed
3.11 job 20207 93 19 2
3.12 job 20198 94 19 2
3.13 job 20198 94 19 2
3.14 job 20199 93 19 2

The supported tox configuration, source hashes, actual import origins and generated dependency lock are verified before and after execution. Normal scoped hooks and the actual Git pre-commit hook pass without changing the frozen patch. Raw logs retain warnings and normal test-defined skips, xfails and xpasses.

Unit Tests:

  • I have added tests for the model, list and real consuming conversion paths.
  • All four required full unit-test tox environments pass.

Manual End-to-End (E2E) Tests:

The consuming test runs the repository's scripted model through its real InMemoryRunner and AgentTool, then converts the resulting function-response part with part_to_message_block. It uses no live model or provider endpoint. Live provider acceptance and browser behavior were not tested.

Checklist

  • I have read CONTRIBUTING.md and reviewed the source change.
  • I have added tests that reproduce the defect on the unchanged source.
  • The full supported tox matrix passes with the final patch.
  • I have manually tested against a live provider or UI.

Additional context

OpenAI Codex assisted with diagnosis, implementation, deterministic verification and this description. A complete current open-PR path inventory and the matching diffs were reviewed for supersession. The other validate_schema proposal, #7285, validates non-model schemas and leaves the model dumps unchanged.

Serialize validated model output in JSON mode so date-valued AgentTool
results survive the real Runner and tool-result serialization. Keep the
existing exclusion of None fields for model and list output schemas.

Related to google#7480.

AI-assisted with OpenAI Codex.
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.

2 participants