# `H.Schema`
[🔗](https://github.com/parlant/harness/blob/v0.3.0/lib/h/schema.ex#L1)

Boundary validator for untrusted decoded JSON maps, command envelopes,
and HTTP parameters.

Never calls `String.to_atom/1` on external input. Field specs define the exact
permitted keys and types; keys are read by `Atom.to_string(key)` with fallback
to existing atom keys for internal callers.

# `field_spec`

```elixir
@type field_spec() :: {atom(), field_type()} | {atom(), field_type(), keyword()}
```

# `field_type`

```elixir
@type field_type() ::
  :string
  | :non_empty_string
  | :id_string
  | :session_id
  | :session_tags
  | :abs_path
  | :boolean
  | :int
  | {:int, keyword()}
  | :pos_int
  | {:literal, term()}
  | {:enum, [term()]}
  | :map
  | {:map, [field_spec()]}
  | {:list, field_type()}
  | :any
```

# `normalize_title`

```elixir
@spec normalize_title(term()) :: {:ok, nil | String.t()} | {:error, String.t()}
```

Normalizes a session title: converts `nil` or blank strings to `nil`,
collapses CR/LF/tabs to spaces, trims whitespace, and rejects NUL bytes,
control characters, or titles exceeding 200 characters.

# `parse_pos_int`

```elixir
@spec parse_pos_int(term()) :: {:ok, pos_integer()} | {:error, String.t()}
```

Parses a positive integer from either an integer (`> 0`) or a base-10 digit string.

# `validate_map`

```elixir
@spec validate_map(term(), [field_spec()]) :: {:ok, map()} | {:error, String.t()}
```

Validates an untrusted map against `field_specs`.

Each spec is `{field_key, type}` or `{field_key, type, opts}` where `opts`
supports `:required`, `:default`, and `:nullable`. Unknown keys in `input`
are ignored and omitted from the returned atom-keyed map.

# `validate_session_id`

```elixir
@spec validate_session_id(term()) :: {:ok, String.t()} | {:error, String.t()}
```

Validates a session ID against `^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$`
to prevent path traversal in session directories.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
