Raxol.Agent.Action.Schema (Raxol Agent v2.6.0)

Copy Markdown View Source

Lightweight schema validation for Action input/output.

No external dependencies -- pure pattern matching on keyword list specs.

Field Specs

schema = [
  path: [type: :string, required: true, description: "File path"],
  timeout: [type: :integer, default: 5000],
  format: [type: :string, enum: ["json", "text"], default: "text"]
]

Supported types: :string, :integer, :float, :boolean, :atom, :map, :list, {:list, type}.

Summary

Functions

Convert a schema to a JSON Schema-compatible tool definition.

Validate params against a schema.

Types

field_spec()

@type field_spec() :: keyword()

schema()

@type schema() :: [{atom(), field_spec()}]

Functions

to_json_schema(schema, name, description \\ "")

@spec to_json_schema(schema(), String.t(), String.t()) :: map()

Convert a schema to a JSON Schema-compatible tool definition.

Produces the OpenAI/Anthropic function calling format:

%{
  "type" => "function",
  "function" => %{
    "name" => name,
    "description" => description,
    "parameters" => %{
      "type" => "object",
      "properties" => %{...},
      "required" => [...]
    }
  }
}

validate(params, schema)

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

Validate params against a schema.

Returns {:ok, validated_params} with defaults applied, or {:error, [{field, reason}]} on failure.