# Table Tools

Gives an AI node scoped tools over exactly one table.

- Category: AI
- Input: required `input`
- Output: `tools` — wire it into an AI Agent `tools` input

The node performs no table work during workflow execution. It emits concretely-named `AgentTool`
configs; the agent calls them later.

## Configuration

| Field | Description |
|---|---|
| `table` | The table slug or ULID these tools may reach. They can reach no other. |
| `tool_name` | Optional AI-visible name prefix. Defaults to the table's name in `snake_case`. |
| `query` | Enable `{prefix}_query`: filter, sort, and page rows. On by default. |
| `get` | Enable `{prefix}_get`: read one row by id. On by default. |
| `add` | Enable `{prefix}_add`: add one row. On by default. |
| `update` | Enable `{prefix}_update`: change columns of one row. On by default. |
| `remove` | Enable `{prefix}_remove`: delete one row. **Off by default.** |

A table named `Reading List` produces `reading_list_query`, `reading_list_get`, `reading_list_add`,
`reading_list_update`, and `reading_list_remove`. The parameter schema of each is generated from the
table's declared columns, so the agent sees the real columns inline: a `select` column arrives as an
`enum`, a `list` as a typed array, an `object` as a closed shape.

One node targets one table. A second table is a second node — the tool names differ, so both nodes
can feed the same AI node.

Set `tool_name` when the derived prefix collides with another node's, or when the table's name does
not make a usable tool name. Every generated name must be ASCII letters, numbers, underscores, or
hyphens, and at most 64 characters; the node reports a name it cannot generate when the workflow is
built, rather than failing mid-conversation.

Scope is the point of this node. If the agent should reach tables it was not pointed at, use the
table management tools instead.

## Tool Call Contracts

`{prefix}_query` takes optional `filters`, `search`, `sort`, `limit`, and `offset`.

```json
{
  "filters": [{ "target": "status", "operator": "eq", "operand": "reading" }],
  "sort": { "target": "added_at", "direction": "desc" },
  "limit": 25,
  "offset": 0
}
```

Filter operators are `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains`, `is_null`, `is_not_null`,
`includes`, `includes_any`, `in`, and `not_in`. `contains` is a substring of text; `includes` is
membership of a `list` or `object` column, and `includes_any` matches any listed element. `in` and
`not_in` test a single-valued column against a set, and take a non-empty array.
Targets are column names, or `id` for the row id. Multiple filters combine with AND.
`search` is a ranked free-text match — `{ "term", "targets" }`, where `targets` are column names and
null searches the text columns. Use `search` to find a row by wording, `filters` for an exact match;
the two combine in one call.
The page defaults to 25 rows and is at most 1000; an over-large page is refused rather than clamped.

Every read publishes a row under the state it is in: a valid row is `{ "valid": { … } }`, the row as
an object of its columns with `id` among them. Rows that do not satisfy the table's declared columns
come back in place as `{ "broken": { "id", "reason", "raw" } }`, so a count taken from a read stays
honest. `total` counts them too.

`{prefix}_get` and `{prefix}_remove` take `id`.

```json
{ "id": "01J00000000000000000000000" }
```

`{prefix}_add` takes the table's declared columns.

```json
{ "title": "Piranesi", "author": "Susanna Clarke", "status": "unread" }
```

`{prefix}_update` takes `id` and the columns to change. Omit a column to leave it alone; send `null`
to empty it.

```json
{ "id": "01J00000000000000000000000", "status": "finished" }
```

Both writes are strict: a value that violates the declaration is rejected rather than stored, so
these tools never create a broken row. A `block` column is written as markdown and stored as a block
document. A key the table does not declare is refused.

A table that denies AI read or write refuses these tools for that operation.
