Skip to content

[BUG] Fix schema name sanitization for OpenAI API compatibility#655

Merged
crmne merged 2 commits intocrmne:mainfrom
alexey-hunter-io:fix/sanitize-schema-name
Mar 5, 2026
Merged

[BUG] Fix schema name sanitization for OpenAI API compatibility#655
crmne merged 2 commits intocrmne:mainfrom
alexey-hunter-io:fix/sanitize-schema-name

Conversation

@alexey-hunter-io
Copy link
Contributor

What this does

Sanitizes schema names in build_schema_payload by replacing characters that don't match [a-zA-Z0-9_-] with _.

Since v1.13.0, normalize_schema_payload preserves the :name key from to_json_schema. When using ruby_llm-schema, the schema name defaults to the full Ruby class name (e.g. MyApp::Nested::Schema) which contains ::. OpenAI requires response_format.json_schema.name to match ^[a-zA-Z0-9_-]+$, so the request is rejected with a BadRequestError.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Fixes #654

Alexey2257 and others added 2 commits March 5, 2026 11:15
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
@crmne crmne merged commit afe7d04 into crmne:main Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Schema name with :: sent to OpenAI violates json_schema.name pattern

3 participants