Skip to main content
Vane Data / Reference

SQL ai_prompt

ai_prompt can be used only in a SQL SELECT list. It produces one text, structured, or raw-response value per input row.

Signatures

query.sql
ai_prompt(
    prompt VARCHAR,
    return_format := NULL,
    system_message := NULL,
    provider := 'openai',
    model := NULL,
    return_raw_response := FALSE,
    on_error := 'raise',
    options := NULL
)


ai_prompt(prompt VARCHAR, image BLOB, ...)
ai_prompt(prompt VARCHAR, images BLOB[], ...)

The media overloads add one required positional BLOB or BLOB[] argument after prompt; the named arguments that follow are unchanged. The selected provider and model must support image input. Native vLLM accepts text only.

Parameters

NameSQL typeDescriptionDefault
promptVARCHARPer-row text inputRequired
imageBLOBOptional second positional image input—
imagesBLOB[]Optional second positional list of images—
return_formatVARCHAR containing valid JSON, JSON via implicit cast, or NULLJSON Schema for native structured outputNULL
system_messageVARCHAR or NULLSystem instructionNULL
providerVARCHARRegistered provider'openai'
modelVARCHAR or NULLModel IDNULL
return_raw_responseBOOLEANReturn valid provider-response JSON as VARCHARFALSE
on_errorVARCHAR'raise' or 'ignore''raise'
optionsSTRUCT or NULLDocumented PromptOptionsNULL

Only prompt, image, and images can read row data. Vane evaluates the other arguments while preparing the query, so they must not depend on a row. Put provider request and execution settings inside struct_pack(...). Only documented options are accepted; provider-incompatible and credential-like fields are rejected before execution.

Result

With no JSON Schema, the result is VARCHAR. A valid return_format produces a native STRUCT type when the query is prepared. return_raw_response := TRUE returns valid JSON in VARCHAR, even when a JSON Schema is also supplied.

Example

Run this query through a Vane connection. It uses OpenAI, so install vane-ai[openai] and set OPENAI_API_KEY in the worker environment first.

query.sql
SELECT
    id,
    text,
    ai_prompt(
        text,
        provider := 'openai',
        model := 'gpt-4o-mini',
        system_message := 'Summarize the support request in one sentence.'
    ) AS summary
FROM (VALUES
    (1, 'I was charged twice.'),
    (2, 'My parcel has not arrived.')
) AS documents(id, text)
ORDER BY id;

Errors

A NULL prompt returns NULL while preserving the result type, without contacting the provider. Locally checkable errors—including invalid types, non-constant configuration arguments, unknown providers, invalid JSON Schemas or options, and known model/provider incompatibilities—raise before execution. Model availability, permissions, endpoint capabilities that cannot be determined locally, and Provider request failures may be detected only during execution. on_error := 'ignore' applies only to row execution failures.