ai.sql

Write a DuckDB query from a description, fitted to the tables' actual schema, for duckdb.query_file to run. The query is checked against the tables before it is emitted.

  • Kind: standard
  • Network: yes
  • Secrets: llm (optional) -- see Secrets

Inputs🔗

NameTypeRequiredDefaultDescription
tablescollection of file (Parquet)yesTables to work from, named t0, t1, ... in order.
descriptionstringyesWhat the artifact should do, in plain language.
modelstringyesModel identifier, exactly as the provider names it (e.g. claude-opus-5-5).
providerstringnoanthropicWho serves the model. The key is the block's llm secret. One of anthropic, openai, openai_compatible.
base_urlstringnoblankEndpoint for an OpenAI-compatible server (vLLM, Ollama, Azure, a gateway). Leave blank for the provider's own API.
sharestringnoschemaHow much of the data the model may see. Column names are always sent; summary statistics reveal values; samples send rows. Everything sent is recorded in the provenance output. One of schema, summary, samples.
max_turnsnumberno10Model calls before the block gives up.
max_tokensnumberno200000Input plus output tokens across all calls, billed to your key.
noncestringnoblankChange to generate afresh with nothing else changed; the block ignores its value.

Outputs🔗

NameTypeDescription
queryfile (SQL)The query, with a header duckdb.query_file checks.
provenancejsonEvery tool result sent to the model, the model and endpoint used, and token usage.

Example🔗

- id: "@sql"
  name: ai.sql
  inputs: [{block: "@pivot", output: result, as: tables}]
  args:
    description: Total biomass per plot across every species column.
    provider: anthropic
    model: claude-opus-5-5
    share: schema
  secrets:
    llm: my-anthropic-key