Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ruby_llm/schema/dsl/schema_builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ def string_schema(description: nil, enum: nil, min_length: nil, max_length: nil,
}.compact
end

def number_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil)
def number_schema(description: nil, minimum: nil, maximum: nil, greater_than: nil, less_than: nil, multiple_of: nil)
{
type: "number",
description: description,
minimum: minimum,
maximum: maximum,
exclusiveMinimum: greater_than,
exclusiveMaximum: less_than,
multipleOf: multiple_of
}.compact
end

def integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil)
def integer_schema(description: nil, minimum: nil, maximum: nil, greater_than: nil, less_than: nil, multiple_of: nil)
{
type: "integer",
description: description,
minimum: minimum,
maximum: maximum,
exclusiveMinimum: greater_than,
exclusiveMaximum: less_than,
multipleOf: multiple_of
}.compact
end
Expand Down
22 changes: 22 additions & 0 deletions spec/ruby_llm/schema/properties/numbers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
})
end

it "supports exclusive number boundaries" do
schema_class.number :score, greater_than: 0, less_than: 100

properties = schema_class.properties
expect(properties[:score]).to eq({
type: "number",
exclusiveMinimum: 0,
exclusiveMaximum: 100
})
end

it "supports number type with description" do
schema_class.number :price, description: "Price field"

Expand All @@ -31,4 +42,15 @@
properties = schema_class.properties
expect(properties[:count]).to eq({type: "integer", description: "Count value"})
end

it "supports exclusive integer boundaries" do
schema_class.integer :age, greater_than: 17, less_than: 66

properties = schema_class.properties
expect(properties[:age]).to eq({
type: "integer",
exclusiveMinimum: 17,
exclusiveMaximum: 66
})
end
end