Packages

Minimal Elixir AI SDK scaffolding for streaming text with tool calls.

Current section

Files

Jump to
ai_sdk_ex lib ai schema.ex
Raw

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