Define input schemas with Anthropic::BaseModel
mainUse Anthropic::BaseModel to define structured data classes for tools and structured outputs. This allows you to specify required/optional fields, types, and documentation.
Field Definitions:
required :name, Type: Field must be provided and cannot benil.optional :name, Type: Field may be omitted; if provided, it cannot benil.required :name, Type, nil?: true: Field must be provided but can benil.optional :name, Type, nil?: true: Field may be omitted or benil.
Supported Types:
- Basic:
String,Integer,Float,Anthropic::Boolean. - Complex:
Anthropic::EnumOf[:opt1, :opt2]Anthropic::ArrayOf[Type]Anthropic::UnionOf[Type1, Type2]- Nested Models: Other
Anthropic::BaseModelsubclasses.
- Nullability: Use
nil?: trueorAnthropic::UnionOf[Type, NilClass]to allow null values.
class GetWeatherInput < Anthropic::BaseModel
required :location, String, doc: "The city and state, e.g. San Francisco, CA"
optional :unit, Anthropic::EnumOf[:celsius, :fahrenheit], doc: "Temperature unit"
end