fix: OpenAI StructuredModeResolver should match versioned model names#991
Open
ipalaus wants to merge 1 commit intoprism-php:mainfrom
Open
fix: OpenAI StructuredModeResolver should match versioned model names#991ipalaus wants to merge 1 commit intoprism-php:mainfrom
ipalaus wants to merge 1 commit intoprism-php:mainfrom
Conversation
StructuredModeResolver::supportsStructuredMode() uses in_array with exact string matching. Versioned model names like gpt-5-mini-2025-08-07 don't match gpt-5-mini, causing them to silently fall into JSON mode (json_object) instead of Structured mode (json_schema + strict). In JSON mode, the schema is embedded as plain text in a system message with no constrained decoding, resulting in significantly more verbose model output. Use a hybrid approach: - Keep exact matching for gpt-4o and o3-mini families where only specific versions support structured output - Use prefix matching for gpt-4.1+, gpt-4.5+, and gpt-5+ families where structured output is a baseline feature across all versions
cb0bcd6 to
ff00f86
Compare
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.
Summary
StructuredModeResolver::supportsStructuredMode()usesin_arraywith exact string matching. Versioned model names likegpt-5-mini-2025-08-07don't matchgpt-5-mini, causing them to silently fall into JSON mode (json_object) instead of Structured mode (json_schema+strict: true).In JSON mode the schema is embedded as plain text in a system message and
json_objectformat is used — no constrained decoding. This results in significantly more verbose model output compared to proper structured mode.Approach
Uses a hybrid strategy:
gpt-4oando3-minifamilies, where only specific versions support structured output (e.g.,gpt-4o-2024-08-06does, earlier versions don't)gpt-4.1+,gpt-4.5+, andgpt-5+families, where structured output is a baseline feature across all versionsThis avoids the need to update the allowlist every time OpenAI releases a new dated version of a gpt-5 family model, while remaining conservative for older model families with inconsistent support.
Changes
supportsStructuredMode()into exact matches (gpt-4o, o3) and prefix matches (gpt-4.1+, gpt-5+)StructuredModeResolverTestwith 32 test cases covering exact matches, prefix matches, JSON mode fallback, and unsupported model exceptionsTest plan
gpt-5-mini-2025-08-07→ Structured mode (was JSON mode)gpt-5-mini→ Structured mode (unchanged)gpt-4o-mini-2024-07-18→ Structured mode (unchanged, exact match preserved)gpt-4-turbo→ JSON mode (unchanged)o1-mini→ throws (unchanged)