WeaviateEx.Validation.Property (WeaviateEx v0.7.4)

View Source

Property value validation against schema data types.

Validates that property values conform to their declared data types before sending to Weaviate, providing early error detection.

Supported Data Types

  • text - String values
  • int - Integer values
  • number - Numeric values (integer or float)
  • boolean - Boolean values
  • date - ISO8601 date/datetime strings or DateTime/Date structs
  • uuid - UUID strings
  • blob - Base64-encoded binary data
  • geoCoordinates - Geographic coordinates
  • phoneNumber - Phone number objects
  • object - Nested object (map)
  • Arrays - Append [] to any type (e.g., text[], int[])

Examples

# Validate a single value
:ok = Property.validate("hello", "text")
{:error, msg} = Property.validate(123, "text")

# Validate an entire object against a schema
schema = %{"properties" => [
  %{"name" => "title", "dataType" => ["text"]},
  %{"name" => "count", "dataType" => ["int"]}
]}
object = %{"properties" => %{"title" => "Hello", "count" => 42}}
:ok = Property.validate_object(object, schema)

Summary

Functions

Validates a property value against its declared data type.

Validates all properties in an object against a schema.

Types

validation_result()

@type validation_result() :: :ok | {:error, String.t()}

Functions

validate(value, data_type)

@spec validate(term(), atom() | String.t()) :: validation_result()

Validates a property value against its declared data type.

Examples

Property.validate("hello", "text")
# => :ok

Property.validate(123, "text")
# => {:error, "Expected string for text type, got 123"}

Property.validate([1, 2, 3], "int[]")
# => :ok

validate_object(object, schema)

@spec validate_object(map(), map()) :: :ok | {:error, [String.t()]}

Validates all properties in an object against a schema.

Examples

schema = %{"properties" => [
  %{"name" => "title", "dataType" => ["text"]},
  %{"name" => "count", "dataType" => ["int"]}
]}
object = %{"properties" => %{"title" => "Hello", "count" => 42}}
Property.validate_object(object, schema)
# => :ok

object = %{"properties" => %{"title" => 123, "count" => "not an int"}}
Property.validate_object(object, schema)
# => {:error, ["title: Expected string for text type, got 123", "count: Expected integer..."]}