Skip to content

fix: map float type to number in RubyLlmBuilder#16

Merged
sh1nj1 merged 1 commit into
mainfrom
fix/ruby-llm-float-to-number
Feb 2, 2026
Merged

fix: map float type to number in RubyLlmBuilder#16
sh1nj1 merged 1 commit into
mainfrom
fix/ruby-llm-float-to-number

Conversation

@sh1nj1
Copy link
Copy Markdown
Member

@sh1nj1 sh1nj1 commented Feb 2, 2026

Problem

AI agents using tools with Float parameters (like progress in creative_create_service) fail with:

AI Error: undefined method 'float' for class #<Class:0x...>

Root Cause

RubyLlmBuilder maps :float type to :float, but RubyLLM's params DSL only has number method, not float.

Solution

  • scalar_method(:float) now returns :number
  • scalar_symbol(:float) now returns :number

Changes

  • app/lib/tool_schema/ruby_llm_builder.rb: Fix float → number mapping
  • test/tool_schema_test.rb: Add tests for float type handling

Testing

All 23 tests pass, including 2 new tests for float type.

RubyLLM's params DSL uses `number` method, not `float`.
This was causing 'undefined method float' errors when converting
tools with Float parameters (e.g., progress percentage).

- scalar_method(:float) now returns :number
- scalar_symbol(:float) now returns :number
- Added tests for float type handling
@sh1nj1
Copy link
Copy Markdown
Member Author

sh1nj1 commented Feb 2, 2026

Evidence: RubyLLM uses number, not float

1. RubyLLM Schema DSL - PrimitiveTypes

lib/ruby_llm/schema/dsl/primitive_types.rb

def string(name, description: nil, required: true, **options)
def number(name, description: nil, required: true, **options)  # ← number, not float!
def integer(name, description: nil, required: true, **options)
def boolean(name, description: nil, required: true, **options)
def null(name, description: nil, required: true, **options)

No float method defined. Only number.

2. RubyLLM Schema - respond_to_missing?

lib/ruby_llm/schema.rb

def respond_to_missing?(method_name, include_private = false)
  %i[string number integer boolean array object any_of one_of null].include?(method_name) || super
end

float is not in the list. Only number.

3. RubyLLM Tool - map_type

lib/ruby_llm/tool.rb

def self.map_type(type)
  case type.to_s
  when 'integer', 'int' then 'integer'
  when 'number', 'float', 'double' then 'number'  # float → number
  when 'boolean' then 'boolean'
  # ...
  end
end

This also confirms that RubyLLM maps float to number internally.

Conclusion

RubyLLM follows JSON Schema standard which uses number type (not float). The fix in this PR correctly maps :float to :number in both scalar_method and scalar_symbol.

@sh1nj1 sh1nj1 merged commit 1c29e92 into main Feb 2, 2026
1 check passed
@sh1nj1 sh1nj1 deleted the fix/ruby-llm-float-to-number branch February 2, 2026 17:56
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.

1 participant