Tolerate OpenAI model schema drift in the agents payload converter#1563
Merged
Conversation
The OpenAI SDK response models can drift from live API payloads (e.g. a deprecated-but-required field the API has stopped sending, such as ActionSearch.query on web_search_call results). The SDK tolerates this when parsing responses, but strict TypeAdapter.validate_json on the workflow side does not, which breaks deserializing ModelResponse across the activity boundary. Add a lenient fallback to the OpenAI agents payload converter: try strict pydantic validation first and, only on ValidationError, rebuild via OpenAI's own construct_type (handling the agents dataclass wrapper). The happy path is unchanged; the fallback retires once upstream fixes the field requiredness.
Mirror the current OpenAI API, which returns the search action with the plural `queries` and omits the deprecated singular `query`. Built via model_construct so the required-but-unset `query` is excluded on serialization, exercising the lenient converter fallback in the use_local_model path without needing a live API key.
Build the converter tuple directly instead of mutating self.converters after super().__init__().
JasonSteving99
approved these changes
May 28, 2026
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.
What
The OpenAI agents integration deserializes
ModelResponseacross the activity boundary with strict pydantic validation. OpenAI's SDK response models can drift from what the live API actually returns — e.g. the web searchsearchaction no longer includes the deprecated-but-requiredActionSearch.queryfield, sending only the newer pluralqueries. The SDK tolerates this when parsing responses (it builds models leniently), but strictTypeAdapter.validate_jsonon the workflow side does not, so any workflow usingWebSearchToolfails with:This breaks the workflow durably (the activity result can never be decoded), and affects both directions — model output (
ModelResponse) and the items fed back as model input (ActivityModelInput).Fix
Add a lenient fallback to the OpenAI agents payload converter: try strict pydantic validation first and, only on
ValidationError, rebuild via OpenAI's ownconstruct_type(the same lenient builder theopenai/openai-agentsSDKs use), handling theagentsdataclass wrapper around the OpenAI response types. The happy path is unchanged, and the fallback retires on its own once the field requiredness is fixed upstream (see openai/openai-python#3328).Testing
queries(noquery), matching the current API, sotest_research_workflow[use_local_model=True]exercises the fallback without a live key.test_research_workflow[use_local_model=False](live API) passes with the fix.🤖 Generated with Claude Code