fix(providers): clarify structured output completion - #524
Merged
Jason Robert (jrob5756) merged 2 commits intoSep 11, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #524 +/- ##
=======================================
Coverage ? 92.00%
=======================================
Files ? 165
Lines ? 27336
Branches ? 0
=======================================
Hits ? 25150
Misses ? 2186
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Jason Robert (jrob5756)
approved these changes
Sep 11, 2026
Jason Robert (jrob5756)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thanks for contributing!
Closed
6 tasks
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.
Summary
final_resultoutput tool an explicit completion contractToolOutput, schema sanitization, output retries, and provider parity unchangedPydantic AI already exposes the intended customization seam through
ToolOutput(..., description=...), but its default description only says that the tool is the final response. Some models behind OpenAI- or Anthropic-compatible endpoints still finish with plain text unless the requirement to call the tool is explicit. This change puts that requirement on the tool definition rather than modifying workflow-authored system prompts.This is an alternative to the backend-wide
PromptedOutputswitch proposed in #508. It preserves forced tool output, nested-schema sanitization, parse recovery, telemetry, and continuation message formats.Validation
make checkuv run pytest tests/test_providers/test_pydantic_ai_agent_builder.py tests/test_providers/test_pydantic_ai_structured_output.py tests/test_providers/test_openai_http_stub.py -q(84 passed)chmod(0o000)behaviorfinal_resultdescription for bothbackend="openai"andbackend="anthropic"Notes
The description improves adherence for models that support tool calling. It cannot compensate for a gateway that strips tool descriptions or does not implement tool calls.