fix: do not mutate Tool schemas (and handle empty tools) in OpenAIResponsesChatGenerator#12067
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
Conversation
_prepare_api_call wrote additionalProperties into the Tool.parameters dict that Tool.tool_spec exposes by reference, permanently altering the user's Tool (and any other generator sharing it) and making serialization round trips unstable. Build the tool definition on a copied parameters dict instead. Also guard _warm_up_tools against an empty tools list, which previously raised IndexError on the unguarded self.tools[0] access.
|
@TimurRakhmatullin86 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @TimurRakhmatullin86, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
HaystackBot
marked this pull request as draft
July 19, 2026 21:36
HaystackBot
marked this pull request as ready for review
July 20, 2026 21:18
Contributor
|
Thanks for signing the CLA, @TimurRakhmatullin86! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
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.
Related Issues
None — two self-contained bugs found in
OpenAIResponsesChatGeneratortool handling.Proposed Changes
1. Do not mutate the user's
Toolschema in place.In
_prepare_api_call, tool definitions were built like:Tool.tool_specreturns{"name": ..., "description": ..., "parameters": self.parameters}—parametersby reference — and{**t.tool_spec}only shallow-copies the outer dict. SoadditionalProperties: Falsewas written permanently into the caller's liveTool.parameters. Consequences: the sameToolpassed to another generator (e.g.OpenAIChatGeneratorwithtools_strict=False, which intentionally leaves schemas open) is contaminated, andtool.to_dict()/ a serialize→load→serialize round trip is no longer stable. Fixed by building the definition on a copied parameters dict:{**function_spec["parameters"], "additionalProperties": False}.2. Guard
_warm_up_toolsagainst an empty tools list.is_openai_tool = isinstance(self.tools, list) and isinstance(self.tools[0], dict)raisedIndexErrorfortools=[](an ordinary value when tools are built programmatically). Every sibling check already guards emptiness; this one now does too viabool(self.tools).How did you test it?
Unit tests in
test/components/generators/chat/test_openai_responses.py:test_prepare_api_call_does_not_mutate_tool_parameters— asserts the originalTool.parametersis untouched while the API payload still carriesadditionalProperties=False.test_warm_up_with_empty_tools_list_does_not_raise— warms up withtools=[]without error.Both fail against the current code (
AssertionError/IndexErrorrespectively) and pass with the fix. Fulltest_openai_responses.pyunit suite passes;ruff check/ruff format --checkclean.Checklist