Skip to content

v0.4.0

Choose a tag to compare

@github-actions github-actions released this 21 May 10:32
1e2608c

Support for Dependencies and Conditionals

Adds given, dependent, and inline requires: DSL methods for expressing JSON Schema conditionals and dependencies.

requires: inline property dependencies

Maps to dependentRequired. The simplest form for "if this property is present, require those":

class PaymentSchema < RubyLLM::Schema
  number :credit_card, required: false, requires: %i[billing_address cvv]
  string :billing_address, required: false
  string :cvv, required: false
end

dependent property dependencies with validations

Use a block when you need validates, upgrades output to dependentSchemas:

dependent :credit_card do
  requires :billing_address
  validates :billing_address, type: :string, min_length: 1
end

given if/then/else

Condition values are auto-coerced: strings → const, arrays → enum, regexps → pattern, hashes → raw schema.

class ShippingSchema < RubyLLM::Schema
  boolean :domestic
  string :state, required: false
  string :country, required: false

  given domestic: true do
    requires :state

    otherwise do
      requires :country
    end
  end
end

All three propagate through nested schemas via of: and define/$defs.

Thanks to @marcoroth for his PR #31

Changelog

Full Changelog: v0.3.1...v0.4.0