How-to guide

Generate SQL and sagas with AI

Register an LLM provider, turn plain-English questions into reviewable SQL, and draft sagas from a description.

Fabric Current 2 min read Updated

Prerequisites

  • Admin access to configure assistants
  • An API key or endpoint for the LLM provider you want to use

Kiwi Fabric does not ship one hard-coded model. You register any number of AI configurations, each with its own provider, credentials and model. The assistant turns a natural-language question into federated SQL, or a transaction description into a saga draft, and you review before anything runs.

Supported providers#

OpenAI, Azure OpenAI, Anthropic, Google, a local Ollama model, or any OpenAI-compatible custom endpoint.

Register a configuration#

bash
kiwi fabric ai-config-set --name default-assistant --provider OpenAI --model <model-id> --api-key "<provider-api-key>"
kiwi fabric ai-config-test --name default-assistant
kiwi fabric ai-config-default --name default-assistant

For Azure OpenAI or a self-hosted endpoint add --base-url, and --deployment for Azure. --max-tokens and --temperature tune generation. Configurations can be disabled (ai-config-disable) or removed without deleting history, and the Web UI keeps a versioned history with a diff view of every change.

The AI Assistants page listing a configured Azure OpenAI assistant marked Default, with its model, a masked endpoint and key, token limit and temperature
A configured assistant. The endpoint and key are masked in this screenshot.
The Edit panel for an assistant with name, provider, API key, Azure endpoint URL, deployment name, model id, max tokens and temperature
Editing an assistant. Only the end of the stored key is ever shown.

Generate SQL#

bash
kiwi fabric ai-sql --config default-assistant --prompt "Top 10 customers by total order value"

Add --run to execute the generated SQL immediately. In the Web UI, use Ask Fabric AI in the SQL playground: the generated statement lands in the editor where you can read and change it before running.

The Query Playground with the Ask Fabric AI box, a Generate SQL button showing the active assistant, and an empty SQL editor
Ask Fabric AI in the playground.

How it works:

  • Relevant tables are chosen by embedding similarity when capabilities have descriptions, with a keyword fallback otherwise. At most seven tables go into one prompt to keep the context focused.
  • Generation has two passes: if the first statement fails validation (for example an unknown table or unbalanced parentheses), one correction pass runs.
  • If the joins cannot be built from the available tables, the assistant answers INFEASIBLE with a reason instead of returning a broken query.
  • Stored-procedure capabilities are never offered to the SQL generator.

Draft a saga#

bash
kiwi fabric ai-saga --config default-assistant --prompt "Create an order, deduct stock for product 7, and add a shipping record"

The result is saga JSON, including steps, dependencies and compensation settings. Review it, then run it with saga-run. See Run a distributed transaction.

Security#

Natural-language queries run through the same governed access layer as every other client, as the asking user. An assistant can never return a row or column that user could not already see. See Secure data access.

Expected result

  • Generated SQL appears for review before it runs
  • AI requests are limited to what the asking user may access