Current section
Files
Jump to
Current section
Files
lib/ai/schema.ex
defmodule AI.Schema do
@moduledoc """
Validates tool inputs against JSON schemas.
"""
@doc """
Validates `value` against a JSON schema and raises on errors.
"""
def validate!(schema, value, tool_name \\ nil) do
resolved = ExJsonSchema.Schema.resolve(schema)
case ExJsonSchema.Validator.validate(resolved, value) do
:ok ->
value
{:error, errors} ->
raise AI.Errors.InvalidToolInputError,
message: "invalid tool input",
tool_name: tool_name,
input: %{value: value, errors: errors}
end
end
end