Skip to content

[BUG] assume_model_exists not working with Rails integration and custom RubyLLM model names #555

@schoblaska

Description

@schoblaska

Basic checks

  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code

What's broken?

Trying to use a model that does not exist in the registry does not seem to work as documented when using the Rails integration with custom names for the RubyLLM model classes.

How to reproduce

I created a test repo with a rake task that shows

  1. RubyLLM.chat working with a model that requires assume_model_exists to be set
  2. Llm::Chat (Rails model) working with a known model
  3. Llm::Chat failing with an unknown model

Expected behavior

All three chats succeed.

What actually happened

$ OPENROUTER_API_KEY=sk-or-v1-asdf1234 bin/rake test_ruby_llm

Testing RubyLLM.chat with unknown model
Hi there! How can I help you today?

Testing Llm::Chat with known model
Hi there! How can I help you today?

Testing Llm::Chat with unknown model
rake aborted!
RubyLLM::ModelNotFoundError: Unknown model: anthropic/claude-opus-4.5 for provider: openrouter (RubyLLM::ModelNotFoundError)
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/models.rb:222:in `find_with_provider'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/models.rb:178:in `find'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/models.rb:84:in `method_missing'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/models.rb:74:in `resolve'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/chat.rb:60:in `with_model'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/chat.rb:18:in `initialize'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm.rb:47:in `new'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm.rb:47:in `chat'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/active_record/chat_methods.rb:80:in `to_llm'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/active_record/chat_methods.rb:198:in `complete'
/Users/joseph/.rvm/gems/ruby-3.3.5/gems/ruby_llm-1.9.1/lib/ruby_llm/active_record/chat_methods.rb:192:in `ask'
/Users/joseph/projects/ruby_llm_test/lib/tasks/test_ruby_llm.rake:26:in `block in <main>'

Environment

  • Ruby version: ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin24]
  • RubyLLM version: 1.9.1
  • Provider: OpenRouter
  • OS: Mac OS

Fixed by #564

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions