module

Anthropic::Schema

Schema DSL for type-safe tool input definitions

Provides a cleaner way to define tool input schemas.

schema: {
  "location" => Schema.string("City name"),
  "unit"     => Schema.enum("celsius", "fahrenheit"),
}

Class methods

array(items : Property, description : String | Nil = nil, min_items : Int32 | Nil = nil, max_items : Int32 | Nil = nil) : Property

Define an array property

Schema.array(Schema.string, description: "List of names")
Schema.array(Schema.integer, min_items: 1, max_items: 10)
Source
boolean(description : String | Nil = nil, default : Bool | Nil = nil) : Property

Define a boolean property

Schema.boolean("Is active")
Schema.boolean("Enabled", default: true)
Source
enum(*values : String, description : String | Nil = nil, default : String | Nil = nil) : Property

Define an enum property with allowed string values

Schema.enum("celsius", "fahrenheit", description: "Temperature unit")
Schema.enum("low", "medium", "high")
Source
integer(description : String | Nil = nil, minimum : Int32 | Nil = nil, maximum : Int32 | Nil = nil, default : Int32 | Nil = nil) : Property

Define an integer property

Schema.integer("Number of items")
Schema.integer("Age", minimum: 0, maximum: 150)
Source
number(description : String | Nil = nil, minimum : Float64 | Nil = nil, maximum : Float64 | Nil = nil, default : Float64 | Nil = nil) : Property

Define a number property (floating point)

Schema.number("Temperature in degrees")
Schema.number("Price", minimum: 0.0, maximum: 1000.0)
Source
object(properties : Hash(String, Property), description : String | Nil = nil, required : Array(String) = [] of String) : Property

Define an object property with nested properties

Schema.object({
  "name" => Schema.string("Person's name"),
  "age"  => Schema.integer("Person's age"),
}, required: ["name"])
Source
string(description : String | Nil = nil, min_length : Int32 | Nil = nil, max_length : Int32 | Nil = nil, pattern : String | Nil = nil, default : String | Nil = nil) : Property

Define a string property

Schema.string("User's name")
Schema.string("Email", pattern: "^[a-z]+@[a-z]+\\.[a-z]+$")
Source

Nested types