> ## Documentation Index
> Fetch the complete documentation index at: https://developers.askparable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI

> Call ponder(), embed(), and the Jev functions in SQL to run models over your Workspace's tables.

`ponder()`, `embed()`, and the [Jev functions](#jev-typed-judgments) are SQL
functions on the same Flight SQL connection that you use for
[the pools](https://developers.askparable.com/data.md#query-the-pools). You can also call them in a Plot, and over
[SQL over HTTP](https://developers.askparable.com/data/sql-over-http.md). Named arguments use `=>`. Do not mix
named and positional arguments.

Each call goes to a paid AI model:

* `ponder()` sends one call for each row that reaches it.
* `embed()` sends up to 32 rows in one call.
* Each Jev function sends one call for each row that reaches it.

By default, one query can send up to 1,000,000 AI calls and spend up to
\$1,000 on them. The Jev functions `ask`, `noul`, `choice`, and `score` count
against the same limits. A query that would pass a limit stops with
`RESOURCE_EXHAUSTED` and error code `QL-SQ-010` (calls) or `QL-SQ-011`
(cost). Do not retry it. Call the function over fewer rows instead. While you
develop a query, filter the input, keep a `LIMIT`, or
[sample the table](https://developers.askparable.com/data/providers.md#sample-a-large-table).

A call to a model that Parable has no price for yet is refused, because the
cost limit could not count it. The query stops with `FAILED_PRECONDITION` and
error code `QL-SQ-012`, and the message names the function, the model and its
processor. Name a model that has a price, such as the default. The
[dry run](https://developers.askparable.com/data/sql-over-http.md#check-a-query-before-you-run-it) tells you, before
you run a query, the most AI calls that each function in it can make.

To call a function over every row of a large table, put the SQL in a
[Pipeline](https://developers.askparable.com/data/parables.md). A Refresh keeps each answer and runs under its own
limits. `workspace.query_runs` records what each Plot run spent (see
[Workspace](https://developers.askparable.com/data/workspace.md#plot-run-history-and-spend)).

## ponder()

`ponder()` runs a language model once per row and returns a typed value.

| Argument | Requirement | Meaning |
| - | - | - |
| `instruction` | Required | A constant instruction sent with every row. |
| `output` | Required | A constant output type: `Utf8`, `Int64`, `Float64`, `Boolean`, `Date32`, `Timestamp`, or `Struct`. |
| `inputs` | Required | A `named_struct`. Its field names become the labels in the prompt. |
| `schema` | Required for `Struct` | A JSON Schema object, as a constant string. |
| `provider`, `name`, `variant`, `version` | Optional | The model. Omit all of them to use the default model. |
| `model` | Optional | A model configuration from [`model()`](#name-a-model-once-with-model), instead of `provider`, `name`, `variant`, and `version`. Do not use both. |
| `server` | Optional | The route to the model: `vertex`, `anthropic`, or `openrouter`. The Workspace's AI policy decides which routes it can use. |
| `date` | Optional | The model date. The default is `latest`. |
| `effort` | Optional | Reasoning effort, as the model provider defines it. |
| `tokens` | Optional | The maximum output tokens. |
| `request_timeout_seconds` | Optional | A timeout for each call. |

Classify Linear issues with the default model:

```sql theme={null}
SELECT
  id,
  title,
  ponder(
    instruction => 'Classify the issue. Reply with one of: bug, feature, question, other.',
    output => 'Utf8',
    inputs => named_struct('title', title, 'body', description)
  ) AS category
FROM providers.linear.issues
WHERE title IS NOT NULL
LIMIT 20
```

### Choose the model

A call that names a model runs that model. A call that names no model runs
the Workspace's default model for `ponder()`, which a Workspace administrator
sets in the AI policy. Without a Workspace default, it runs Parable's default,
Gemini 3.5 Flash-Lite on Vertex (`gemini-3.5-flash-lite`).

The Workspace's AI policy lists the routes that `ponder()` can use. Parable
allows only `vertex`. `server => 'vertex'` runs in the Workspace's own Vertex
project when it has one. A call that the policy refuses fails before Parable
sends any row, with error code `QL-MP-001`. If Parable cannot read the
policy, the query fails with `QL-MP-002`. Run it again.

This call names its model:

```sql theme={null}
SELECT
  id,
  ponder(
    provider => 'google',
    name => 'gemini',
    variant => '2.5',
    version => 'flash',
    server => 'vertex',
    instruction => 'Classify the issue. Reply with one of: bug, feature, question, other.',
    output => 'Utf8',
    inputs => named_struct('title', title)
  ) AS category
FROM providers.linear.issues
WHERE title IS NOT NULL
LIMIT 20
```

### Name a model once with model()

`model()` packs a model's coordinates into one value that you pass to
`ponder()` as `model`. Its arguments are positional:

```
model(provider, name, variant, version, date, effort, tokens [, server [, request_timeout_seconds]])
```

An empty `date` means `latest`. An empty `server` uses the Provider's default
route. `tokens` can be `NULL`. `request_timeout_seconds` must be positive.

```sql theme={null}
SELECT
  id,
  ponder(
    model => model('google', 'gemini', '2.5', 'flash', '', '', NULL, 'vertex'),
    instruction => 'Classify the issue. Reply with one of: bug, feature, question, other.',
    output => 'Utf8',
    inputs => named_struct('title', title)
  ) AS category
FROM providers.linear.issues
WHERE title IS NOT NULL
LIMIT 20
```

`model()` itself calls no model. Inline coordinates and `model()` name a model
the same way, so the same AI policy rules apply to both.

### Return a struct

Use `Struct` when your SQL needs more than one typed field. The result has
the fields of your schema and a reserved `meta` field. Do not put `meta` in
your schema.

```sql theme={null}
SELECT
  id,
  classified.category,
  classified.reason,
  classified.meta.status,
  classified.meta.error
FROM (
  SELECT
    id,
    ponder(
      instruction => 'Extract a category and a one-sentence reason.',
      output => 'Struct',
      schema => '{"type":"object","properties":{"category":{"type":"string"},"reason":{"type":"string"}},"required":["category","reason"]}',
      inputs => named_struct('title', title)
    ) AS classified
  FROM providers.linear.issues
  LIMIT 20
) AS classified_rows
```

`meta.status` is one of these values:

* `ok`: every required field is present.
* `partial`: the response parsed, but at least one required field is
  missing. `meta.error` names the missing fields.
* `error`: the model call failed.

`meta` also has token usage, latency, and the model that ran. A failed call
with a primitive output type returns `NULL`. The rest of the query continues.

An argument that `ponder()` refuses, such as an unknown argument or a
`Struct` output without `schema`, fails before Parable sends any row. The
error code is `QL-PL-013`.

## embed()

`embed()` returns one unit-length vector per row. Only `input` is required.
The default model is Google `gemini-embedding`, version `001`, on `vertex`,
with 768 dimensions. A Workspace cannot set a different default for
`embed()`.

| Argument | Requirement | Meaning |
| - | - | - |
| `input` | Required | The text to embed, for each row. |
| `provider` | Optional | The default is `google`. |
| `name` | Optional | The default is `gemini-embedding`. |
| `version` | Optional | The default is `001`. |
| `server` | Optional | `vertex` or `openrouter`. The default is `vertex`. |
| `purpose` | Optional | `document`, `query`, `similarity`, `classification`, or `clustering`. The default is `document`. |

A `NULL` or empty `input` returns `NULL`. If a call to the model fails, the
affected rows are `NULL` and the query continues.

```sql theme={null}
SELECT
  id,
  title,
  embed(input => title) AS vec
FROM providers.linear.issues
WHERE title IS NOT NULL
LIMIT 50
```

Use `purpose => 'document'` for stored text and `purpose => 'query'` for a
search phrase. A constant phrase is embedded once per batch, not once per
row. Rank issues by distance from a search phrase:

```sql theme={null}
SELECT
  id,
  title,
  array_distance(
    embed(input => title),
    embed(input => 'customer billing problem', purpose => 'query')
  ) AS distance
FROM (
  SELECT id, title
  FROM providers.linear.issues
  WHERE title IS NOT NULL
  LIMIT 200
) AS issues
ORDER BY distance
LIMIT 20
```

### Keep vectors comparable

Vectors are comparable only when they come from the same model: the same
provider, name, variant, version, dimensions, and normalization. `server`
only routes the call. It does not change the vector.

A query that compares vectors from two different models fails before Parable
embeds anything. The error code is `QL-PL-008`. Equal dimensions are not
enough.

A Pipeline that selects `embed(...)` keeps the vectors in its own table, with
the model that wrote them. Parable makes no separate vector table. If a query
cannot read a Plot's vector column, run the Plot again.

## Jev: typed judgments

The Jev functions ask a model a question about each row and return a typed
answer with its confidence. Use them to classify, score, or filter rows when a
probability or a label with a confidence is more useful than free text.

| Function | Asks | Returns |
| - | - | - |
| `noul(state, instructions [, criteria [, model]])` | A yes-or-no question. | `Float64`: the probability of yes, from 0 to 1. |
| `choice(state, instructions, criteria [, model])` | Which one label fits. | A struct: `label`, `confidence`, and `probabilities`, a map from each label to its probability. |
| `score(state, instructions, criteria [, model])` | Where the row sits on an ordered scale. | A struct: `score`, `confidence`, and `probabilities`. |
| `ask(state, questions [, model])` | Several of these questions at once. | A struct with one field for each question, typed as that question's function returns it. |

| Argument | Meaning |
| - | - |
| `state` | The evidence for each row: text, JSON text, a struct, or a map. A `NULL` state returns `NULL` without a call. |
| `instructions` | The question, as text. |
| `criteria` | For `choice`, an object from each label to its meaning. For `score`, a list of the levels, lowest first. For `noul`, optional rubrics for `true` and `false`. Write it as JSON text, or build it in SQL as a map, a struct, or a list. |
| `questions` | For `ask`, constant JSON text: an object from each question's ID to its `type` (`noul`, `choice`, or `score`), its `instructions`, and its `criteria`. |
| `model` | Optional. A Jev version, such as `jev-1.13.0`. |

Use `CASE`, `COALESCE`, `NVL`, `IFNULL`, or `NVL2` to ask Jev only when a row
needs a judgment. `CASE WHEN instructions IS NOT NULL THEN noul(state,
instructions) END` skips rows with NULL instructions. `COALESCE(known,
noul(state, 'Q?'))` skips rows that already have a value. Skipped calls make
no request and cost nothing.

A condition that calls Jev, a volatile function such as `random()`, or a
subquery does not skip rows in later branches. A Jev call inside a conditional
subquery also judges every row, as before. To skip rows on an earlier judgment
or volatile value in both queries and Pipelines, store those results in a
separate query first. A direct query can also read an earlier judgment from a
subquery SELECT list or CTE.

Classify Linear issues and read the label and its confidence:

```sql theme={null}
SELECT
  id,
  title,
  choice(
    state => title,
    instructions => 'Which kind of work does this issue ask for?',
    criteria => '{"bug": "Something is broken", "feature": "New behavior", "question": "A request for information"}'
  ) AS kind
FROM providers.linear.issues
WHERE title IS NOT NULL
LIMIT 20
```

Read a field of the result as `kind['label']` or `kind['confidence']`. A
`noul` answer near 0.5 means that the model cannot tell yes from no. It does
not mean a medium amount.

Ask two questions about each row in one call with `ask`:

```sql theme={null}
SELECT
  id,
  judged['urgent'] AS p_urgent,
  judged['kind']['label'] AS kind
FROM (
  SELECT
    id,
    ask(
      state => description,
      questions => '{"urgent": {"type": "noul", "instructions": "Does the issue block a customer?"}, "kind": {"type": "choice", "instructions": "Which kind of work is it?", "criteria": {"bug": "Something is broken", "feature": "New behavior"}}}'
    ) AS judged
  FROM providers.linear.issues
  WHERE description IS NOT NULL
  LIMIT 20
) AS issues
```

`questions` must be constant text, because it fixes the fields of the result
when Parable plans the query. A column or a bound parameter there is refused
with `QL-PL-013`, and so is any other argument that Jev cannot use. A Jev
call directly in `ORDER BY`, `GROUP BY`, `DISTINCT ON`, a window, or an outer
join condition is refused with `QL-PL-013` too. Compute the call in a subquery
SELECT list, then sort, group, or join on its column alias.

### The model and the AI policy

A Jev call runs the model that its `model` argument names. Without one, it
runs the Workspace's default from its AI policy, and without that, Parable's
default.

Jev runs on the `TYPESAFE` AI processor, with Parable's default
`jev-1.13.0`. When the Workspace's AI policy does not allow `TYPESAFE`, a Jev
call that names no model runs on a decision model that Google serves on the
`VERTEX` AI processor, DeepSeek V4.1 Flash (`deepseek-v4.1-flash-decide-1`).
It gives answers of the same shape as Jev, not the same answers. It takes at
most 255 Choice options, 10 Score levels and 1,048,576 input tokens per
decision. A question over a limit fails with an error that names the model
and its limit. A Workspace administrator can choose the other decision model,
Gemini 3.1 Flash-Lite (`gemini-3.1-flash-lite-decide-1`), for the Workspace.

When the AI policy allows neither processor, or does not allow the processor
of the model a call names, Parable refuses the call while it plans the query,
with `QL-MP-001`, before it sends any row. When Parable cannot read the
policy, the query fails with `QL-MP-002`. Run it again. Ask a Workspace
administrator to allow `TYPESAFE` or `VERTEX` in the AI policy to use Jev.

By default, a Jev call that fails stops the query. If the model service does
not answer, the error code is `QL-IN-010`. Try again with backoff.

> [!TIP]
>
> [Ponder](https://docs.parable.work/plugins/plot-plugins/ponder) and
> [Embed](https://docs.parable.work/plugins/plot-plugins/embed) describe
> both functions in full.
> [Flight SQL](https://docs.parable.work/protocols/sql/flight-sql#ai-call-limits)
> lists the AI call limits and their error codes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.