Live demo · AI SQL

Ask a model about every row.
Right in the SELECT.

ChalkSQL's AI functions classify, extract, score and summarize text with OpenAI models, one call per row, routed through the Chalk model gateway. The answer comes back as a column, so the rest of the query is the SQL you would write anyway.

18 tickets, one query

A support queue and some product reviews from an invented home-goods store. Pick a query and a model, then run it: each one executes live in ChalkSQL and calls OpenAI through the model gateway. On the score and filter queries you can ask your own question.

ChalkSQL · OpenAI via the Chalk model gatewayOpen in new tab

Results are cached for 15 minutes per query and model. A fresh run of a preset reads all 18 tickets in about one and a half seconds.

How it works

Most text in your warehouse never gets read: tickets, reviews, notes, transcripts. A model can read all of it, and SQL decides which rows and what to do with the answers.

A function in the SELECT

ai_classify, ai_extract, ai_score and ai_filter take a text column and a question. Chalk sends each row to the model, concurrently, and returns a typed column: a label, a span, a probability or a verdict.

Through the model gateway

The url is the Chalk model gateway. It holds the OpenAI credentials, routes the call, and traces it in your environment. The query carries only a gateway key you can revoke.

Plain SQL around it

The model's answer is just another column, so GROUP BY, ORDER BY, joins and window functions work on it unchanged. A cheap WHERE runs before ai_filter, so the model only reads the rows that are left.

Getting started

Add a column, not a pipeline

Point an AI function at a text column, name a model, and give it the gateway's url and a key. Run the query from the Chalk SQL editor, the CLI, or Python.

The demo's backend is one small Python service: it runs ChalkSQL with its own workload identity and holds no client secret. The repository deploys it in one command.

chalk-ai/sql-llm-functions
-- One model call per row; the label is an ordinary string column.
SELECT id, body,
  ai_classify(body, 'What is this support ticket about?',
              ['billing', 'software_bug', 'shipping', 'returns', 'account_access'],
              model => 'gpt-4.1-mini',
              url => :gateway_url,        -- the Chalk model gateway
              api_key => :gateway_key,
              choice_constraint => 'none') AS topic
FROM tickets

The functions

Each takes model, url and api_key, plus options such as max_tokens, max_concurrency, timeout_seconds and extra_body for any further request fields.

ai_classify

Picks one label from a fixed list. With a hosted API it matches the model's answer to a label; on vLLM it constrains decoding to the labels.

ai_extract

Copies the words of the text that answer the question, such as an order number, or returns NULL when nothing does.

ai_score

Reads P(TRUE) from the model's log-probabilities, so a yes/no question becomes a number you can sort and threshold.

ai_filter

An LLM predicate in WHERE. Chalk orders several of them cheapest first, each asked only about the rows the last one kept.

openai_complete

Free-form generation with the full response struct: completion, prompt and completion tokens, finish reason and cached tokens.

Keys stay in the gateway

Provider keys never appear in a query or a client. Swap OpenAI models, or point url at vLLM on your own GPUs, without changing the SQL around it.

Read every row you already have

Support tickets, reviews, notes or transcripts. Talk to an engineer about putting models in your queries.