aidp-ai-sql — LLM-in-SQL with ai_generate()
Call an LLM directly inside Spark SQL on AIDP — summarize, classify, extract, or narrate over lakehouse data without leaving SQL. A signature differentiator: most competitor agents can't do this inline.
This is a SQL-helper skill. Interactive Spark SQL runs through the bundled helper
scripts/aidp_sql.py (it mints a UPST from the api_key DEFAULT profile, auto-creates a scratch notebook,
and returns JSON). No aidp MCP and no AIDP_SESSION required.
When to use
- "Summarize / classify / extract / enrich these rows with AI in SQL."
- Generate a grounded narrative over an aggregate (e.g. a finance summary over a spend rollup).
Signature (model FIRST)
e.g. ai_generate('openai.gpt-5.4', 'Summarize this supplier spend: ...').
LIVE-VERIFIED model-first (model, prompt) signature with openai.gpt-5.4, openai.gpt-4o, and
xai.grok-4.
Verify before relying on it (no-fabrication): confirm the exact signature and the available model names live on the target cluster before treating this as guaranteed — run a trivial
SELECT ai_generate('<model>', 'hello')cell first (see smoke test below). Model availability varies by environment. If a model name fails, list/ask for the correct one rather than guessing.Don't gate on the
/modelsREST catalog.ai_generateresolves the model at the Spark engine level, so it can work even whenaidp-models-catalog'sGET /models?modelType=GENERATIVE_AIreturns an empty list. The smoke test (not the catalog endpoint) is the source of truth for whetherai_generateworks.
How to run a cell
Returns JSON: {"status":"ok|error","outputs":[...],"spark_job_ids":[...]}. Exit 0 on success, 1 on
cell error. See scripts/aidp_sql.py for full flags (--profile,
--session-profile, --notebook, --timeout).
Smoke test (do this first)
Workflow (grounded RAG pattern)
- Ensure cluster RUNNING (cluster-ops via
oci raw-request; seereferences/no-mcp-rest-map.md). - Ground first: aggregate/select the rows you want the LLM to reason over (small, relevant set).
- Embed that grounded context into the prompt and call
ai_generate('<model>', '<grounded prompt>'). For per-row enrichment, call it as a column expression over a bounded set. - Present the generated text alongside the underlying data so the user can verify it.
Pass the cell to --code:
Reliability rules
- Always ground the prompt in real query output — don't ask the model to recall data it can't see.
- Bound row counts for per-row
ai_generate(cost + latency). - Show the data behind any AI narrative; never present generated numbers as ground truth without the SQL.
References
- scripts/aidp_sql.py — the SQL/notebook-cell executor (bundled helper)
- references/oci-raw-request.md — REST control-plane (clusters, auth)
- references/no-mcp-rest-map.md · pairs with
aidp-analyzing-data


