AI as SQL virtual catalog
The gluesync.ai virtual catalog makes Gluesync AI, optional Spark agents, and caller-visible read-only MCP tools available through SQL. Connect through Query Forge, ask a natural-language question, and receive one row containing the plain-language answer, an optional SQL proposal, citations, and conversation context.
SQL surface
The shortest valid query is:
SELECT *
FROM gluesync.ai
WHERE question = 'retrieve customer data';
question is required and must use an equality predicate. A prepared parameter (?) is also accepted.
The statement returns one row.
Example result
The result appears as a regular JDBC result set. Long answers and SQL are shown in full by clients such as DBeaver and DataGrip when you open the cell value.
answer |
proposed_sql |
citations |
conversation_id |
question |
pipeline_id |
agent_id |
provider_id |
spark_agent |
|---|---|---|---|---|---|---|---|---|
I found a |
|
|
|
|
|
|
|
|
The exact wording depends on the selected model or Spark agent and the schemas and tools visible to the caller. answer is the plain result. proposed_sql is a draft for review; Gluesync does not execute it.
This question names no pipeline, agent, schema, or table, so the row comes back with empty grounding and NULL IDs. See Name grounding from the question.
Scope the question to an agent
You do not need pipeline_id or agent_id in the WHERE clause. Prefer naming the pipeline, agent, schema, or table in the question so Core Hub can ground the answer:
SELECT answer, proposed_sql, citations, conversation_id
FROM gluesync.ai
WHERE question = 'retrieve the 100 most recently created customers from dbo.CUSTOMERS';
If two equally strong names collide, or you need to pin one database regardless of wording, you may optionally supply both pipeline_id and agent_id together. They are never required for a normal ask. Explicit IDs always win: when both are present in the WHERE clause, Hub uses that scope and does not read any names out of the question.
Name grounding from the question
When the query omits pipeline_id and agent_id, Core Hub tries to resolve the scope from whole names mentioned in the question — pipeline, agent, schema, and table names — against the catalogs the caller can already see.
SELECT answer, proposed_sql, pipeline_id, agent_id
FROM gluesync.ai
WHERE question = 'in the crm-sync pipeline, list the columns of the dbo.CUSTOMERS table';
-
Whole names, case-insensitive. A name takes part in resolution only when the whole catalog name appears in the question. Matching ignores case and treats punctuation as a word separator, so
dbo.CUSTOMERSmatches thedboschema and theCUSTOMERStable. Fragments and abbreviations are not resolved. -
Strongest unique match wins. Hub grounds the request on the single strongest candidate and returns the resolved
pipeline_idandagent_idin the result row, so the answer shows which scope was used. -
Weaker matches are ignored. A secondary name that matches less strongly than the leader does not make the request ambiguous.
-
Ties fail. When two or more candidates share the strongest score, the request fails with SQLSTATE
22023and lists those candidates instead of Hub choosing one. -
No match means empty grounding. When nothing in the question resolves, Hub answers with empty schema grounding and returns
NULLforpipeline_idandagent_id.
Grounding never widens what the caller can read: only the pipelines, agents, schemas, and tables already visible to the caller’s token take part in resolution.
Match strength
Names are not all worth the same. Hub first compares agent and pipeline names, then breaks a remaining tie on schema and table names:
Name mentioned in the question |
Weight |
|---|---|
Agent name |
Strongest of the two agent-level signals; an agent name beats a pipeline name. |
Pipeline name |
Selects the pipeline’s agents, and loses to a question that also names an agent. |
Table name |
Strongest of the two catalog-level signals; a table name beats a schema name. |
Schema name |
Narrows to agents exposing that schema, and loses to a question that also names a table. |
Select an LLM provider
Use provider_id to select a provider from Settings → LLM providers:
SELECT answer, proposed_sql, provider_id
FROM gluesync.ai
WHERE question = 'write a read-only query that finds duplicate customer emails'
AND provider_id = 'provider-ollama-local';
If provider_id is omitted, Core Hub resolves a configured provider for the request. When spark_agent is set, that Spark agent’s assigned provider is used unless you override it with provider_id.
Call a Spark agent
spark_agent selects an AI Studio Spark agent by id or unique name. Query Forge uses that agent’s system prompt. Tools are the intersection of the agent’s allow-list and this path’s read-only catalog; write tools never run here.
SELECT answer, proposed_sql, spark_agent
FROM gluesync.ai
WHERE question = 'summarize replication lag'
AND spark_agent = 'Ops helper';
-
answeris the Spark agent’s plain result. -
proposed_sqlis optional suggested SQL for review and is never executed. -
spark_agentis the AI Studio agent.agent_idremains a database connector used for schema grounding.
Continue a conversation
Pass the conversation_id returned by the previous query to ask a follow-up:
SELECT answer, proposed_sql, conversation_id
FROM gluesync.ai
WHERE question = 'limit that query to active customers'
AND conversation_id = 'b5acd3d2-7c9d-4100-8296-25b10132ebe0';
The returned row keeps the conversation identifier so the next query can continue the same exchange.
Use a prepared statement
Applications should bind user-provided questions instead of concatenating them into SQL:
try (PreparedStatement statement = connection.prepareStatement(
"SELECT answer, proposed_sql, citations, conversation_id " +
"FROM gluesync.ai WHERE question = ?")) {
statement.setString(1, "retrieve customer data");
try (ResultSet result = statement.executeQuery()) {
if (result.next()) {
String answer = result.getString("answer");
String proposedSql = result.getString("proposed_sql");
}
}
}
Accepted WHERE predicates
| Predicate | Hub contract |
|---|---|
|
Required equality predicate. A string literal or prepared parameter is accepted. |
|
Optional advanced pin. Not required for normal asks. If used, they must be supplied together. They select the database context used for schema grounding and take precedence over any name mentioned in the |
|
Optional. Continues an existing conversation. |
|
Optional. Selects a provider from the BYO LLM vault. |
|
Optional. AI Studio Spark agent id or unique name. Write-capable tools are never offered on this path. |
Only equality predicates on these columns are accepted. Predicates such as LIKE, ranges, and filters on output columns fail with SQLSTATE 22023.
Result columns
| Column | Hub contract |
|---|---|
|
Plain-language result for the supplied |
|
SQL proposed for review. Hub never auto-runs this statement. |
|
Citations as JSON text. |
|
Conversation identifier for the returned row. |
|
The question supplied in the |
|
The requested pipeline ID, the pipeline ID resolved from a name in the |
|
The requested agent ID, the agent ID resolved from a name in the |
|
The requested provider ID, or |
|
The requested Spark agent id or name, or |
Authentication and RBAC
Requests use the caller’s Core Hub PAT (or equivalent Bearer / Forge token). The virtual catalog does not use an elevated service account.
MCP tool discovery and invocation keep the same RBAC as that caller. Only tools that Hub exposes as readOnly on this path are used.
BYO LLM vault prerequisite
The catalog requires a configured provider in the bring-your-own LLM vault. Provider setup belongs to AI models and LLM providers; it is not duplicated here.
MCP tools
Visible tools are the MCP tools allowed for the caller under that token’s RBAC, restricted to readOnly tools. Schema discovery and allow-list behavior follow that Hub path. This page does not add extra Control Plane allow-list fields.
Safety
-
proposed_sqlis never auto-run. -
This SQL path uses readOnly MCP tools only.
-
The catalog does not elevate the caller’s permissions.
Errors
| Condition | Hub contract |
|---|---|
Empty BYO LLM vault |
The query fails. A Super admin ( |
Residual WHERE predicates |
Predicates Hub does not accept on |
Not found |
Hub maps not-found to SQLSTATE |
Only one of |
The pair must be supplied together. Supplying one alone fails with SQLSTATE |
Ambiguous name grounding |
Two or more equally strong name matches in the |
No name resolved |
Not an error. Omitting |
RBAC denial |
The caller’s PAT/RBAC applies. Hub does not grant extra rights on this path. |
Related
-
Query Forge explains how to connect a JDBC client and query the virtual catalog.
-
AI models and LLM providers explains how to configure the BYO LLM vault, including local Ollama models.
-
AI Studio is the in-product agent workspace. Spark agents defined there can be invoked from Query Forge with
spark_agent. -
Query Studio AI helper is a separate in-product chat and autocomplete surface.