Repository navigation
fix: normalize const constraints in OpenAI tool schemas - #10725
Draft
arccat-114 wants to merge 2 commits into
Draft
arccat-114 wants to merge 2 commits into
arccat-114 wants to merge 2 commits into
Conversation
Signed-off-by: YiMing Zhang <zzz777110@qq.com>
arccat-114
marked this pull request as draft
October 24, 2026 10:01
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/unit/test_tool_google_schema.py" line_range="256" />
<code_context>
+
+ expected = [{"enum": ["a"]}] if isinstance(nested, list) else {"enum": ["a"]}
+ assert result["properties"]["value"][keyword] == expected
+ assert tool.parameters == parameters
+
+
</code_context>
<issue_to_address>
**Source mutation goes undetected**
When conversion mutates `tool.parameters` for a schema-keyword or existing-enum case, when conversion mutates the source for one of these schema cases, `test_openai_schema_converts_const_in_schema_keywords` compares `tool.parameters` with the same `parameters` object, and `test_openai_schema_preserves_const_and_enum_intersection` validates against `tool.parameters` after conversion. Both tests can pass despite the source being changed.
Save a deep copy of the parameters before conversion and assert that the tool's parameters still equal that snapshot.
Also at `tests/unit/test_tool_google_schema.py:224-225`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/unit/test_tool_google_schema.py:256
Signed-off-by: YiMing Zhang <zzz777110@qq.com>
This branch has not been deployed
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.
Fixes #10720.
Modifications
I convert JSON Schema
constconstraints to single-valueenumconstraints when building OpenAI-compatible tool declarations. Nested schema nodes are handled without changing property names, defaults, examples, or the original tool parameters. Existingenumconstraints keep their intersection withconst.No new dependencies or WebUI changes.
Verification
python -m pytest tests/unit/test_tool_google_schema.py -q: 23 passed on Windows, Python 3.13.14.ruff check .andruff format --check .: passed (Ruff 0.15.22).git diff --check: passed.I tested the emitted schemas locally, including nested constraints, literal objects, conflicting enums, boolean/number equality, and unchanged Anthropic input. I have not run the full application suite or sent a live request to a Gemini gateway.
Summary by Sourcery
Normalize OpenAI tool schemas so nested
constconstraints are safely represented as compatible enums without mutating source parameters.Bug Fixes:
constconstraints to single-valueenumconstraints in OpenAI-compatible tool schemas, including nested schema nodes while preserving equivalent constraint behavior.Enhancements:
constkeys in defaults, examples, and enum values.enumandconstconstraints.Tests: