Urchin.Schema (Urchin v0.4.0)

Copy Markdown View Source

Minimal structural validation of tool arguments against a JSON Schema.

This is a deliberately small subset of JSON Schema, sufficient to catch the common argument mistakes the DSL's input_schema describes, without pulling in a full validation dependency. It validates type (object, array, string, number, integer, boolean, null, and union types such as ["string", "null"]), object properties, required and additionalProperties: false, array items, and enum. Other keywords (minLength, pattern, format, ...) are ignored rather than enforced.

Schema keywords may be keyed by string or atom (so %{"type" => "object"} and %{type: "object"} both validate); the values being validated come from JSON and are expected to be string-keyed. For full JSON Schema validation, validate in your handler with a dedicated library (e.g. :ex_json_schema).

Summary

Functions

Validates value against schema.

Functions

validate(schema, value)

@spec validate(map() | nil, term()) :: :ok | {:error, String.t()}

Validates value against schema.

Returns :ok, or {:error, message} describing the first violation. A nil schema (or one without a recognized type) accepts any value.