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

# infer

> Run typed inference over text and image columns.

`infer` runs typed inference with a prompt over a text or image column and returns a column of [AI envelopes](#ai-envelope), one for each row. An AI envelope is a `STRUCT` value with the typed AI response, field-level confidence scores, and associated metadata.

Chowder picks the model from your input and output schema. See [Models](https://docs.chowder.ai/concepts/models.md).

## Signature

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
infer(input, prompt, output_schema)
```

| Parameter | Type | Description |
| - | - | - |
| `input` | `VARCHAR` or image `BINARY` | Text, or the `image` column from a table function. |
| `prompt` | `VARCHAR` | Per-row or constant question or instruction. |
| `output_schema` | Constant SQL type | SQL type of the AI response. |

## Input

Pass text, such as the `content` column from `read_documents` or a text column from `read_parquet`.

For images, pass the `image` column from `read_images`, `read_videos`, or `read_mcap`. It holds the encoded image bytes, which `infer` decodes for the vision model.

## Prompt

The prompt can be a question or an instruction. For `BOOL` output, write a statement or question that the input can confirm as true or false, such as `'The customer intends to cancel.'` or `'Does the customer intend to cancel?'`. If text input doesn't provide enough evidence, `output` is `NULL`, meaning [unknown](#boolean-classification).

## Output schema

`output_schema` defines the SQL type of the AI response, and `output` conforms to that type.

| Output schema | Use for | Returns |
| - | - | - |
| `BOOL` | True/false decisions and Boolean filters | `true` or `false`. For text input, `NULL` means unknown: the text doesn't provide enough evidence. |
| `TEXT` | Summaries and open-ended responses | Free-form text |
| `ENUM('a', 'b', ...)` | Classification into one label | One of the listed labels |
| `INT`, `BIGINT`, `FLOAT`, `DOUBLE` | Counts, ratings, and amounts | A number |
| `ARRAY<T>` | Tagging with several labels, or extracting lists | A list of values |
| `STRUCT<name T, ...>` | Extracting several fields at once | Named fields, each with its own type |

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
infer(content, 'Does the reviewer describe a failure?', BOOL)
infer(content, 'Summarize this review.', TEXT)
infer(content, 'Classify the sentiment.', ENUM('positive', 'negative', 'mixed'))
infer(content, 'How many stars does the reviewer give?', INT)
infer(content, 'Extract tags.', ARRAY<VARCHAR>)
infer(
    content,
    'Extract the product and reported problem.',
    STRUCT<
        product TEXT,
        problem TEXT
    >
)
```

Nested structs and lists are supported. Chowder resolves the type during planning, so a standalone `ENUM` with an empty label, such as `ENUM('', 'other')`, fails before any model runs. See [SQL data types](https://docs.chowder.ai/reference/sql-types.md) for canonical names, aliases, and the supported inference subset.

## AI envelope

Each row's AI envelope has these fields:

| Field | Type | Description |
| - | - | - |
| `output` | Matches `output_schema` | The typed AI response. |
| `confidence` | `FLOAT`, or the structure of `output` with a `FLOAT` for each value | Confidence scores for the values in `output`. `TEXT` output gets one score for the whole response. See [Confidence scores](https://docs.chowder.ai/concepts/confidence.md). |
| `error` | `VARCHAR` | Why the row failed, or why confidence couldn't be computed. Null otherwise. |
| `input_tokens` | `BIGINT` | Number of input tokens. |
| `input_ms` | `DOUBLE` | Time spent processing the input, in milliseconds. |
| `output_tokens` | `BIGINT` | Number of output tokens. |
| `output_ms` | `DOUBLE` | Time spent generating the AI response, in milliseconds. |
| `model` | `VARCHAR` | The model that produced the AI response. |
| `model_id` | `VARCHAR` | A compact identifier for the model. |
| `probabilities` | `STRUCT<true FLOAT, false FLOAT, unknown FLOAT>` for `BOOL` output | For text input with `BOOL` output, the probabilities of `true`, `false`, and `unknown`. Null otherwise. |

Rows that fail or have null input stay in the result with a null `output`. For failed rows, `error` explains why.

## Use the AI response

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
SELECT
    title,
    infer(
        content,
        'Does the reviewer describe a product breaking or failing?',
        BOOL
    ).output AS product_failed
FROM read_parquet('hf://buckets/chowderai/chowder-demo/parquet/data/amazon-reviews/*.parquet')
WHERE tokens(content) < 120 -- Keep model inputs short
AND product_failed
LIMIT 3;
```

Same-`SELECT` aliases can be referenced by the `WHERE` clause.

## Boolean classification

By default, text input with `BOOL` uses [Bitsy](https://huggingface.co/chowderai/Bitsy-3.3B), a classifier built for Boolean decisions grounded in documents. It checks your statement or question against the text and returns probabilities for `true`, `false`, and `unknown` in one forward pass, without generating text. `unknown` means the text doesn't provide enough evidence to decide, so missing evidence isn't forced into `true` or `false`. Bitsy is trained to decide from the text you pass, not from facts it remembers.

Bitsy selects the most probable label: `true`, `false`, or `unknown`. The `probabilities` field is a struct with one probability for each label. These probabilities sum to 1, subject to floating-point rounding.

The `confidence` field is the model's probability for the selected label. For example, if `probabilities` is `{"true": 0.15, "false": 0.80, "unknown": 0.05}`, `output` is `false` and `confidence` is `0.80`.

When `unknown` is selected, `output` is SQL `NULL` and `confidence` equals `probabilities.unknown`. This is a classifier prediction and does not itself indicate an inference error. Inspect `error` to distinguish it from a failure.

Only Bitsy returns `probabilities`. Other outputs, including image input with `BOOL`, use [field-level confidence](https://docs.chowder.ai/concepts/confidence.md).

## Behavior

* `infer` runs only on the rows the query needs. For example, it runs on rows that satisfy the `WHERE` conditions.
* Results are cached, so `infer` doesn't recompute results for the same input, prompt, and output schema. See [Caching](https://docs.chowder.ai/concepts/caching.md).


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