[BUG] Fix schema name sanitization for OpenAI API compatibility#655
Merged
crmne merged 2 commits intocrmne:mainfrom Mar 5, 2026
Merged
[BUG] Fix schema name sanitization for OpenAI API compatibility#655crmne merged 2 commits intocrmne:mainfrom
crmne merged 2 commits intocrmne:mainfrom
Conversation
OpenAI requires `response_format.json_schema.name` to match `^[a-zA-Z0-9_-]+$`. When using `ruby_llm-schema`, the schema name defaults to the full Ruby class name (e.g. `MyApp::Nested::Schema`) which contains `::`. Since v1.13.0, `normalize_schema_payload` preserves the `:name` key from `to_json_schema`, causing OpenAI to reject the request with a BadRequestError. Sanitize the schema name by replacing invalid characters with `_`. Fixes crmne#654
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.
What this does
Sanitizes schema names in
build_schema_payloadby replacing characters that don't match[a-zA-Z0-9_-]with_.Since v1.13.0,
normalize_schema_payloadpreserves the:namekey fromto_json_schema. When usingruby_llm-schema, the schema name defaults to the full Ruby class name (e.g.MyApp::Nested::Schema) which contains::. OpenAI requiresresponse_format.json_schema.nameto match^[a-zA-Z0-9_-]+$, so the request is rejected with aBadRequestError.Type of change
Scope check
Quality check
overcommit --installand all hooks passbundle exec rake vcr:record[provider_name]bundle exec rspecmodels.json,aliases.json)AI-generated code
API changes
Fixes #654