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.
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#
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.


Generate SQL#
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.

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
INFEASIBLEwith a reason instead of returning a broken query. - Stored-procedure capabilities are never offered to the SQL generator.
Draft a saga#
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