Skip to content

Allow RubyLLM::Schema to be used for Tool schema (OpenAI, Anthropic and Gemini) #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bricolage
Copy link

@bricolage bricolage commented Aug 10, 2025

What this does

A modest attempt to use RubyLLM::Schema with tools. Just for OpenAI and Anthropic as proof-of-concept.

I understand this is being worked on (see refs below), I thought I'd submit this for feedback on the interface. I use this in my own app.

class TodosSchema < RubyLLM::Schema
      array :todos do
      object do
        string :content, description: 'Todo to track'
        string :status, enum: %w[pending in_progress completed]
      end
    end
end

class TodosTool < RubyLLM::Tool
  schema TodosSchema
  # ...
end

I have not worked through validation issues (e.g. if neither param nor schema is called in the tool class. Currently it returns {}

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
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

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

Related issues

#76
#11 (comment)
#332 (comment)

@tpaulshippy
Copy link
Contributor

Nice! What is missing, provider wise? Gemini?

Copy link
Contributor

@tpaulshippy tpaulshippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straightforward to me. Feels like if we get Gemini added this should be good to go.

@bricolage
Copy link
Author

@tpaulshippy all set, should be gtg

@bricolage bricolage changed the title Allow RubyLLM::Schema to be used for Tool schema (only OpenAI and Anthropic for now) Allow RubyLLM::Schema to be used for Tool schema (OpenAI, Anthropic and Gemini) Aug 10, 2025
@bricolage
Copy link
Author

@tpaulshippy I added some docs, take a look at those if you can

Copy link
Contributor

@tpaulshippy tpaulshippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I'm noticing that I expect @crmne might ask for is at least one spec that hits the real APIs (with VCR cassettes).

@crmne
Copy link
Owner

crmne commented Aug 11, 2025

Hey @bricolage thanks for your effort on this PR. I'm not sure if it's the direction I want to go into for complex parameters for Tools as it may be a bit confusing to define a schema externally from the Tool, and then using it in the tool.

I feel like in a tool we should have params instead. Before you both put a ton of effort on this, let me think about it and come up with a good design.

@crmne crmne linked an issue Aug 11, 2025 that may be closed by this pull request
@bricolage
Copy link
Author

Yeah no problem, this was just my own drop-in solution, I understood it might not be idiomatic. If I can help further let me know!

@bricolage
Copy link
Author

So you are thinking of just letting param take a block and do a light mapping to an internal RubyLLM::Schema? That's nice and simple. And is similar to what langchain.rb does: https://github.com/patterns-ai-core/langchainrb/blob/main/lib/langchain/tool_definition.rb

class TodosTool < RubyLLM::Tool
  param :todos, type: :array, desc: 'List of todos', required: true do
    param :content, description: 'Todo to track'
    param :status
  end
end

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.

JSON schema tool parameters
3 participants