Live demo · AI SQL

Classify and extract text with LLM functions in ChalkSQL

This demo shows how to run a model over support tickets and return its answers as SQL columns. Choose a query to classify, extract, score, filter, or summarize the text, then inspect how those outputs feed the rest of the SQL.

Turn ticket text into columns you can query

Choose a query and model, then run it. Inspect the returned labels, extracted words, scores, or summaries alongside the source text. Score and filter queries accept your own question. Their answers come from a model; they are not hand-labeled ground truth.

ChalkSQL · OpenAI via the Chalk Model GatewayOpen in new tab

Run a preset and compare the source text with its new result column. ChalkSQL calls a model per row to classify, extract, score, filter, or summarize.

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.

Built on Chalk

ChalkSQL runs the model calls and combines their typed outputs with ordinary SQL. The example provides fictional tickets, reviews, and questions; model calls go through the Chalk Model Gateway.

  • Return typed model outputs

    ChalkSQL’s AI functions turn text into labels, extracted spans, probabilities, or verdicts. Each returned value can be used as a column in the surrounding query.

  • Route model calls through the gateway

    The query calls OpenAI through the Chalk Model Gateway. Provider credentials remain in the gateway, while the client uses a gateway key.

  • Combine answers with ordinary SQL

    Use joins, grouping, sorting, and window functions on the model’s outputs. Apply cheap SQL filters before asking a model to read the remaining rows.

  • Control model work per query

    AI functions expose token limits, concurrency, and timeouts. ChalkSQL can order multiple ai_filter predicates so later predicates process only the rows retained earlier.

Deploy your own

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
git clone https://github.com/chalk-ai/sql-llm-functions
cd sql-llm-functions

# A Chalk Model Gateway key, stored as a Chalk secret the demo reads.
chalk router api-key create
chalk secrets set CHALK_ROUTER_API_KEY=<key>

# Builds the image and deploys the page + API as a ScalingGroup.
./deploy.py
Which SQL function should I use?
  • 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.