Merged
Conversation
OpenAI's response_format requires a 'name' for json_schema definitions.
This change enables custom schema names which are useful for debugging,
logging, and clarity when using multiple schemas.
Supports two formats:
1. Full: { name: 'custom_name', schema: { type: 'object', ... } }
2. Schema only: { type: 'object', ... } - defaults to 'response'
Changes:
- Updated OpenAI provider to extract schema name from wrapper format
- Added unit tests for schema name functionality
- Maintained backward compatibility (plain schemas default to 'response')
Related to schema naming discussion for better debugging and observability.
Previously, Chat#with_schema extracted only the [:schema] portion from
RubyLLM::Schema objects, discarding the class name. Now it preserves the
full hash, allowing schema class names to be automatically used in OpenAI API.
Changes:
- Updated Chat#with_schema to keep full to_json_schema result
- RubyLLM::Schema classes now automatically use their class name
- Added test for RubyLLM::Schema format with class name
- Manual wrappers and plain schemas still work as before
Example:
class PersonSchema < RubyLLM::Schema
string :name
integer :age
end
chat.with_schema(PersonSchema)
# OpenAI API receives: name: 'PersonSchema' (instead of 'response')
Documents the new custom schema name feature in the structured output section, explaining how to use the full format with custom names and when they're useful (influencing model behavior and debugging). Also adds a note in the RubyLLM::Schema section explaining that schema classes automatically use their class name in API requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6 tasks
6 tasks
…e-support # Conflicts: # lib/ruby_llm/providers/gemini/chat.rb # spec/ruby_llm/chat_schema_spec.rb
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #476 +/- ##
==========================================
+ Coverage 81.27% 81.31% +0.03%
==========================================
Files 116 116
Lines 5361 5383 +22
Branches 1404 1409 +5
==========================================
+ Hits 4357 4377 +20
- Misses 1004 1006 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
nice thnx for getting this in! |
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
Adds support for custom schema names and changes the default schema name to use the RubyLLM::Schema class name, if provided.
Screencast overview: https://www.loom.com/share/6cea87f03be94444bef28309a0ace3b0
Type of change
Scope check
Quality check
overcommit --installand all hooks passbundle exec rake vcr:record[provider_name]bundle exec rspecmodels.json,aliases.json)API changes
Related issues
Implements #475