fix(openai): avoid mutating raw tool schemas for Responses#6305
Merged
longcw merged 1 commit intoJul 3, 2026
Merged
Conversation
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.
This PR prevents the OpenAI Responses provider-format conversion from mutating a raw tool schema object that may be reused by later provider conversions.
What Problem This Solves
to_responses_fnc_ctx()currently handlesRawFunctionToolby assigning the stored schema directly:schemais the same dict object astool.info.raw_schema, so adding the Responses-specific"type": "function"field mutates the tool's stored raw schema in place.This is order-dependent. If the same raw tool is first converted for
openai.responsesand then reused for regular OpenAI Chat Completions, the later Chat Completions conversion sees a raw schema that has already been polluted with a provider-format field.Responses and Chat Completions use different tool payload shells:
The bug is not that Responses needs
"type": "function"; the bug is that the formatter writes that field onto the persistent raw schema instead of a temporary payload copy.Changes
Copy the raw schema before adding the Responses-specific type field:
This keeps the generated Responses payload unchanged while preserving
RawFunctionTool.info.raw_schemafor later conversions, caller inspection, and reuse.This PR only changes raw function tool handling in the OpenAI Responses provider-format path. It does not change normal
FunctionToolschema generation, provider tools, chat message conversion, or OpenAI Chat Completions formatting.Evidence
A focused regression test now covers a single raw function tool reused across provider formats:
Before this fix, the Responses conversion added
"type"toraw_tool_1.info.raw_schema. After this fix, the Responses payload still includes"type": "function", but the raw schema object remains unchanged.Possible call chain / impact
The affected surface is raw tool schema conversion for OpenAI Responses.
Sibling surfaces checked:
openai.to_fnc_ctx()wraps raw schemas for Chat Completions but does not write provider-specific keys into the stored raw schema.FunctionToolconversion builds fresh schemas through helper functions and is not affected.to_dict()and are outside this raw-schema mutation path.Validation
All commands passed locally. A broader
uv run --no-sync pytest --unit tests/test_tools.py -k responses_raw_schema -qattempt was blocked during unrelated unit-test collection because this local Windows environment does not have several provider test dependencies installed, such aslivekit.plugins,langchain_core, andgoogle.genai.