Problem
Currently, enum is only supported for string type fields. However, JSON Schema specification supports enum for all types, including integer.
When working with LLMs and structured outputs, it's common to need integer enums for categorical data. For example, skill levels (0=basic, 1=intermediate, 2=advanced) or categories (0=technical, 1=soft, 2=language).
Current behavior
# This works
string :status, enum: ["active", "inactive"]
# This doesn't work - enum is ignored
integer :level, enum: [0, 1, 2]
Proposed solution
Add the enum parameter to integer_schema (and optionally number_schema):
# In lib/ruby_llm/schema/dsl/schema_builders.rb
def integer_schema(description: nil, enum: nil, minimum: nil, maximum: nil, multiple_of: nil)
{
type: "integer",
enum: enum,
description: description,
minimum: minimum,
maximum: maximum,
multipleOf: multiple_of
}.compact
end
Use case
class SkillSchema < RubyLLM::Schema
string :name, description: "Skill name"
integer :level, description: "Proficiency level", enum: [0, 1, 2]
integer :category, description: "Skill category", enum: [0, 1, 2, 3]
end
This is valid JSON Schema and, according to OpenAI's documentation, integer types and enums are supported in structured outputs, so this should be compatible in practice.
References
I'm happy to submit a PR if this feature is welcome.
Problem
Currently,
enumis only supported forstringtype fields. However, JSON Schema specification supportsenumfor all types, includinginteger.When working with LLMs and structured outputs, it's common to need integer enums for categorical data. For example, skill levels (0=basic, 1=intermediate, 2=advanced) or categories (0=technical, 1=soft, 2=language).
Current behavior
Proposed solution
Add the
enumparameter tointeger_schema(and optionallynumber_schema):Use case
This is valid JSON Schema and, according to OpenAI's documentation, integer types and enums are supported in structured outputs, so this should be compatible in practice.
References
I'm happy to submit a PR if this feature is welcome.