Python: Fix structured value parsing for split text chunks#6990
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes structured-output parsing for ChatResponse.value and AgentResponse.value by avoiding the synthetic spaces introduced by Message.text when a message contains multiple text Content chunks (which can corrupt split JSON). The public Message.text/Response.text behavior remains unchanged for display.
Changes:
- Added structured-output-only text assembly helpers that concatenate text chunks without inserting spaces.
- Updated
ChatResponse.valueandAgentResponse.valueto parse structured output from the structured-only text path instead ofself.text. - Added regression tests covering split JSON across text chunks while preserving
Message.textspacing behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_types.py | Adds structured-only text helpers and switches structured parsing to use them (avoids Message.text synthetic spacing). |
| python/packages/core/tests/core/test_types.py | Adds tests ensuring split structured JSON parses correctly without changing Message.text/response.text. |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
98dc0f1 to
a5f64d6
Compare
|
Could you please resolve the conflicts? |
|
Resolved the conflicts with current Upstream changed structured-output parsing to use the final non-empty assistant message, while this PR fixes parsing of structured JSON split across multiple text content chunks (without the spaces inserted by |
Structured response parsing currently uses the public text property, which inserts spaces between TextContent chunks inside a Message. That can corrupt split JSON structured outputs while leaving normal display text behavior correct.
This change keeps Message.text unchanged and uses a structured-output-only text path that concatenates text chunks without synthetic spaces before parsing ChatResponse.value and AgentResponse.value.
Tests: