Class: OllamaAgent::Core::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/core/schema_validator.rb

Overview

Lightweight JSON-schema validator for tool arguments. Supports: type, required, properties, enum, minimum, maximum, minLength, maxLength. Does NOT require the json-schema gem — all validation is hand-rolled for zero dependencies.

Defined Under Namespace

Classes: ValidationError

Instance Method Summary collapse

Instance Method Details

#validate(schema, data) ⇒ Array<String>

Validate data against schema.

Parameters:

  • schema (Hash)

    JSON schema (symbol or string keys)

  • data (Hash)

    data to validate

Returns:

  • (Array<String>)

    list of error messages (empty = valid)



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ollama_agent/core/schema_validator.rb', line 16

def validate(schema, data)
  @errors = []
  schema  = stringify_keys(schema)
  data    = stringify_keys(data || {})

  check_type(schema, data)
  check_required(schema, data)
  check_properties(schema, data)

  @errors.dup
end

#validate!(schema, data) ⇒ Object

Raises ValidationError if any errors found.

Raises:



29
30
31
32
33
34
# File 'lib/ollama_agent/core/schema_validator.rb', line 29

def validate!(schema, data)
  errors = validate(schema, data)
  raise ValidationError, errors.join("; ") if errors.any?

  true
end