Basic checks
What's broken?
RubyLLM::Providers::OpenRouter::Chat#parse_completion_response calls .empty? on data without guarding for nil. When OpenRouter returns a response where data is absent (nil), this raises a NoMethodError and the entire request fails.
How to reproduce
- Configure RubyLLM with the OpenRouter provider (ruby_llm 1.14.1).
- Create a chat with tools/schema enabled (tool-calling flow).
- Call
chat.ask(...).
- Intermittently, OpenRouter returns a response where parsed
data is nil.
- RubyLLM crashes in
RubyLLM::Providers::OpenRouter::Chat#parse_completion_response when it calls data.empty?.
Note: this is intermittent in production; we cannot reproduce deterministically on every request.
Expected behavior
RubyLLM should handle missing or nil response data safely in OpenRouter parsing (e.g. nil guard before .empty?) and return a controlled error/result instead of raising NoMethodError.
What actually happened
We get this runtime error from ruby_llm:
NoMethodError: undefined method 'empty?' for nil
# lib/ruby_llm/providers/openrouter/chat.rb:55
return if data.empty?
Backtrace top:
RubyLLM::Providers::OpenRouter::Chat#parse_completion_response (lib/ruby_llm/providers/openrouter/chat.rb:55)
RubyLLM::Provider#sync_response (lib/ruby_llm/provider.rb:262)
RubyLLM::Provider#complete (lib/ruby_llm/provider.rb:62)
RubyLLM::Chat#complete / #handle_tool_calls (lib/ruby_llm/chat.rb)
This happens in production background jobs (Rails app) calling RubyLLM.chat(...).ask(...) through OpenRouter.
Environment
- Ruby version: 3.4.6
- RubyLLM version: 1.14.1
- Provider (OpenAI, Google, etc.): OpenRouter
- OS: Linux (production), macOS locally
- Framework: Rails 8.1
Basic checks
What's broken?
RubyLLM::Providers::OpenRouter::Chat#parse_completion_responsecalls.empty?ondatawithout guarding for nil. When OpenRouter returns a response wheredatais absent (nil), this raises aNoMethodErrorand the entire request fails.How to reproduce
chat.ask(...).dataisnil.RubyLLM::Providers::OpenRouter::Chat#parse_completion_responsewhen it callsdata.empty?.Note: this is intermittent in production; we cannot reproduce deterministically on every request.
Expected behavior
RubyLLM should handle missing or nil response
datasafely in OpenRouter parsing (e.g. nil guard before.empty?) and return a controlled error/result instead of raisingNoMethodError.What actually happened
We get this runtime error from ruby_llm:
NoMethodError: undefined method 'empty?' for nilBacktrace top:
RubyLLM::Providers::OpenRouter::Chat#parse_completion_response (lib/ruby_llm/providers/openrouter/chat.rb:55)
RubyLLM::Provider#sync_response (lib/ruby_llm/provider.rb:262)
RubyLLM::Provider#complete (lib/ruby_llm/provider.rb:62)
RubyLLM::Chat#complete / #handle_tool_calls (lib/ruby_llm/chat.rb)
This happens in production background jobs (Rails app) calling RubyLLM.chat(...).ask(...) through OpenRouter.
Environment