From 81794cc5b51d11edab28598fd01953960f57997c Mon Sep 17 00:00:00 2001 From: Jon David Schober Date: Tue, 23 Dec 2025 13:07:17 -0600 Subject: [PATCH 1/2] Add enum parameter to number and integer schema methods --- lib/ruby_llm/schema/dsl/schema_builders.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ruby_llm/schema/dsl/schema_builders.rb b/lib/ruby_llm/schema/dsl/schema_builders.rb index 91ca52b..716fefb 100644 --- a/lib/ruby_llm/schema/dsl/schema_builders.rb +++ b/lib/ruby_llm/schema/dsl/schema_builders.rb @@ -16,23 +16,25 @@ 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, multiple_of: nil, enum: nil) { type: "number", description: description, minimum: minimum, maximum: maximum, - multipleOf: multiple_of + multipleOf: multiple_of, + enum: enum }.compact end - def integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) + def integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil, enum: nil) { type: "integer", description: description, minimum: minimum, maximum: maximum, - multipleOf: multiple_of + multipleOf: multiple_of, + enum: enum }.compact end From 861f300375f543460469b1faa30adc2e7bb524d8 Mon Sep 17 00:00:00 2001 From: Carmine Paolino Date: Sat, 6 Jun 2026 13:07:55 +0200 Subject: [PATCH 2/2] Add specs for numeric enum support --- README.md | 4 +++- spec/ruby_llm/schema/properties/numbers_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d4c7de..a609d42 100644 --- a/README.md +++ b/README.md @@ -241,8 +241,9 @@ string :code, min_length: 3, max_length: 10 ### Numbers -Number types support the following properties: +Number and integer types support the following properties: +- `enum`: an array of allowed numeric values (e.g. `enum: [0, 1, 2]`) - `multiple_of`: a multiple of the number (e.g. `multiple_of: 0.01`) - `minimum`: the minimum value of the number (e.g. `minimum: 0`) - `maximum`: the maximum value of the number (e.g. `maximum: 100`) @@ -250,6 +251,7 @@ Number types support the following properties: ```ruby number :price, minimum: 0, maximum: 100 number :amount, multiple_of: 0.01 +integer :level, enum: [0, 1, 2] ``` ### Booleans diff --git a/spec/ruby_llm/schema/properties/numbers_spec.rb b/spec/ruby_llm/schema/properties/numbers_spec.rb index 9e8cb12..1f8202d 100644 --- a/spec/ruby_llm/schema/properties/numbers_spec.rb +++ b/spec/ruby_llm/schema/properties/numbers_spec.rb @@ -18,6 +18,13 @@ }) end + it "supports number enum values" do + schema_class.number :score, enum: [0.5, 1.5] + + properties = schema_class.properties + expect(properties[:score]).to eq({type: "number", enum: [0.5, 1.5]}) + end + it "supports number type with description" do schema_class.number :price, description: "Price field" @@ -31,4 +38,11 @@ properties = schema_class.properties expect(properties[:count]).to eq({type: "integer", description: "Count value"}) end + + it "supports integer enum values" do + schema_class.integer :level, enum: [0, 1, 2] + + properties = schema_class.properties + expect(properties[:level]).to eq({type: "integer", enum: [0, 1, 2]}) + end end