adk_json_schema (erlang_adk v0.7.0)

View Source

Deterministic validation for the provider-neutral JSON Schema subset used by agent input and output contracts.

Values are normalized through adk_json before validation. Errors contain a structural path and constraint name, never the rejected value.

Summary

Functions

Validate and return the canonical JSON representation of a value.

Validate a value against a schema already returned by compile/1.

Types

error_reason/0

-type error_reason() ::
          {invalid_json_schema, [path_part()], term()} |
          {invalid_json_value, term()} |
          {schema_validation_failed, [path_part()], term()}.

path_part/0

-type path_part() :: binary() | non_neg_integer().

schema/0

-type schema() :: undefined | true | false | map().

Functions

compile(Schema0)

-spec compile(undefined | boolean() | map()) -> {ok, schema()} | {error, error_reason()}.

validate(Schema, Value0)

-spec validate(schema(), term()) -> {ok, term()} | {error, error_reason()}.

Validate and return the canonical JSON representation of a value.

validate_compiled(Schema, Value0)

-spec validate_compiled(schema(), term()) -> {ok, term()} | {error, error_reason()}.

Validate a value against a schema already returned by compile/1.

This is deliberately a separate trust boundary: callers must not pass an arbitrary schema. Catalogs can compile immutable contracts once and avoid recursively checking the schema again for every model-generated value.