AI Overview
@mountsqli/ai is AI native by design: generated queries go through the same
compiler validator as hand-written ones. There is no separate, unsafe SQL
generator.
Capabilities
Section titled “Capabilities”| Function | What it does |
|---|---|
nlToSql |
natural language → QueryPlan (not raw SQL) |
explainPlan |
human-readable explanation of a plan |
optimizePlan |
suggests optimizations for a plan |
reviewPlans |
security/perf findings across plans |
The ModelProvider seam
Section titled “The ModelProvider seam”The only external dependency is ModelProvider — an interface you implement
(OpenAI, Anthropic, a local model, or a test fake). The package never calls a
vendor SDK directly.
import { Ai } from "@mountsqli/ai";
const ai = new Ai({ provider: myProvider });const result = await ai.nlToSql("users over 18", [users.def]);// result.plan is a QueryPlan — compiled & type-checked like any otherWhy plans, not strings?
Section titled “Why plans, not strings?”Because the model emits a QueryPlan, the result is:
- Type-checked against your schema.
- Injection-safe — values are parameters, never concatenated.
- Explainable —
explainPlancan describe it.
Best practices
Section titled “Best practices”- Validate the returned plan (compile it) before running, like any query.
- Swap
ModelProviderper environment (fake in tests). - Use
reviewPlansin CI to catch risky generated queries.
Common mistakes
Section titled “Common mistakes”- Treating model output as trusted SQL — still compile the plan.
- Hard-coding a vendor SDK in app code (use
ModelProvider).
Related
Section titled “Related”- Natural Language → SQL —
nlToSqlin depth. - Explain / Optimize / Review — the advisors.
