Schemas
Generate a query with AI
The Query Agent tab on a schema is a Database Query Generator. Describe the result you want in plain English, and it writes the SQL, joins and all. It works from the schema’s definition inside Kenseme, so it needs no database connection and no ontology.
In the app: Data Model › Schemas › your schema › Query Agent tab
Before you start¶
- Generating queries uses your organization’s AI usage allowance. See AI usage allowance.
- It works best when tables and columns have descriptions. Cryptic names with no description are the most common reason for a wrong join.
Choose the tables, or let the AI find them¶
The Selected Tables card controls which tables the generator considers.
- Leave it empty and the AI discovers the relevant tables itself. This is the quickest way to start.
- Click
Select Tablesto pick exactly which tables to use. Worth doing on a large schema, or when the AI keeps choosing the wrong tables.
Each selected table appears as a chip. Click a chip to see its columns and types, and click its remove icon to drop it. Clear Tables removes them all.
Ask your question¶
- Pick the
SQL Dialectto write for. The query comes out in that database’s syntax. - In
What would you like to query? (Plain English), describe what you want. Be specific about filters, sorting, and time ranges: “customers who placed more than five orders in the last 30 days, sorted by total order amount” works far better than “top customers”. - Click
Generate SQL Queries.
Read the results¶
Results appear under Generated Queries. You may get more than one, each in its own card with:
- the question it answers and a short description;
- the
SQL Query, with aCopybutton; - sometimes an
Alternative Approach, a second way to get the same result with its ownCopybutton; - sometimes
Important Considerations, such as a filter that assumes a particular data shape.
Below the queries, Suggested Follow-Up Queries lists related questions, each with a relevance score. Click the copy icon to copy one, or the play icon (Use this prompt) to run it straight away.
Tip: Read the SQL before you run it. The generator only knows your schema’s names and descriptions, not your data.
Query Agent or Data Agent?¶
| Query Agent | Data Agent | |
|---|---|---|
| What you get | SQL to copy and run yourself | The answer: rows, a chart, and the SQL it ran |
| Works from | The schema’s definition in Kenseme | An ontology bound to a live database |
| Needs | Any schema | The Data Agent feature and a database-bound ontology |
Use the Query Agent to draft SQL for somewhere else. Use the Data Agent when you want the answer now.