fix: keep __api_exclude__ fields out of async request bodies - #3925
Open
shoutoutuoadi325 wants to merge 1 commit into
Open
shoutoutuoadi325 wants to merge 1 commit into
shoutoutuoadi325 wants to merge 1 commit into
Conversation
_async_transform_recursive dumps pydantic models without the exclude= argument, so fields declared in __api_exclude__ (e.g. ParsedResponseFunctionToolCall.parsed_arguments) leak into request bodies sent through AsyncOpenAI while OpenAI strips them. Mirror the model_dump call from the sync path.
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.
Changes being requested
Pass
__api_exclude__tomodel_dumpin_async_transform_recursive, the same way_transform_recursivealready does.Models can declare client-only fields with
__api_exclude__; right nowParsedResponseFunctionToolCallis the only one using it forparsed_arguments. The sync transform omits those fields when it dumps a model, the async one doesn't, so a request sent throughAsyncOpenAIcarries fields the API never sees fromOpenAI.The way you run into this is multi-turn structured output: with
responses.parseyou hand the parsed output items back in asinputon the next turn. Done synchronously the function tool calls serialize toid/call_id/type/name/arguments; done with the async client, every function call in that list also ships aparsed_argumentskey.Additional context & links
Added
test_pydantic_model_api_excludetotests/test_transform.pycovering the bare-model and list-of-models paths in both lanes, since__api_exclude__had no direct test in either.