Module: ActiveAgent::SchemaGenerator::ActiveModelClassMethods

Defined in:
lib/active_agent/schema_generator.rb

Overview

Class methods added to ActiveModel classes.

Instance Method Summary collapse

Instance Method Details

#to_json_schema(options = {}) ⇒ Hash

Generates a JSON Schema representation of the ActiveModel class.

Examples:

Basic schema generation

ContactForm.to_json_schema

Exclude specific fields

ContactForm.to_json_schema(exclude: [:internal_notes])

OpenAI strict mode

ContactForm.to_json_schema(strict: true, name: "contact_form")

Parameters:

  • options (Hash) (defaults to: {})

    Options for schema generation

Options Hash (options):

  • :exclude (Array<Symbol>)

    Attributes to exclude from the schema

  • :strict (Boolean) — default: false

    Enable OpenAI strict mode (requires all properties)

  • :name (String)

    Custom name for the schema (used with strict mode)

  • :additional_properties (Boolean) — default: false

    Allow additional properties in the schema

Returns:

  • (Hash)

    JSON Schema representation of the model



104
105
106
# File 'lib/active_agent/schema_generator.rb', line 104

def to_json_schema(options = {})
  ActiveAgent::SchemaGenerator::Builder.json_schema_from_model(self, options)
end