Backfill additionalProperties: false in OpenAI strict tool schemas - #6865
Closed
JamesBLewis wants to merge 1 commit into
Closed
Backfill additionalProperties: false in OpenAI strict tool schemas#6865JamesBLewis wants to merge 1 commit into
additionalProperties: false in OpenAI strict tool schemas#6865JamesBLewis wants to merge 1 commit into
Conversation
OpenAI's strict function-calling mode requires "additionalProperties": false on every object level of a tool's input schema, and rejects the request otherwise. applyStrictModeRequirements backfills "required" and widens optional properties to nullable types, but never emitted "additionalProperties": false. Schemas produced by JsonSchemaGenerator already carry it, so the gap only bites schemas from other sources under strict mode: MCP tool schemas, hand-written inputSchema JSON, or schemas generated with ALLOW_ADDITIONAL_PROPERTIES_BY_DEFAULT. Backfill "additionalProperties": false on every object level the strict-mode rewrite already recurses through (root, $defs definitions, nested object properties, array items), preserving an explicitly declared value such as a Map<K,V>-style typed "additionalProperties", mirroring the guard in JsonSchemaGenerator#forbidAdditionalProperties. Schemas sent with strict(false) are untouched. See spring-projects#4422 Signed-off-by: James Lewis <1495031+JamesBLewis@users.noreply.github.com>
ilayaperumalg
approved these changes
Aug 28, 2026
Member
|
@JamesBLewis Thanks for the fix! Rebased and merged via e5e277f |
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.
TLDR; When a caller turns on OpenAI's strict tool-calling mode, Spring AI rewrites each tool's JSON schema to meet OpenAI's strict-mode contract but it only handles half of it. It fills in the "required" list and makes optional fields nullable, yet never adds
additionalProperties: false, which OpenAI also demands on every object in the schema. Tools whose schemas were generated by Spring AI happen to work because the generator adds it earlier, but tools from MCP servers or with hand-written schemas get rejected by the OpenAI API. This change makes the strict-mode rewrite fill inadditionalProperties: falsewherever it is missing.Problem
OpenAiChatModel#applyStrictModeRequirementsrewrites a tool's input schema whenOpenAiChatOptions#strict(true)is set: it backfillsrequiredwith every property key and widens previously optional properties to nullable types, recursing into$defs, nested object properties, and array items.OpenAI's strict function-calling mode additionally requires
additionalProperties: falseon every object level, and rejects requests otherwise with:The rewrite never emits it. Schemas produced by
JsonSchemaGeneratorare unaffected becauseforbidAdditionalPropertiesalready adds it recursively by default — which is why the gap is invisible on the@Tool/FunctionToolCallbackpath. Any schema from another source hits the 400 under strict mode:additionalProperties: false)ToolDefinition#inputSchemaJSONSchemaOption.ALLOW_ADDITIONAL_PROPERTIES_BY_DEFAULTSee #4422