System prompts for AI-powered query optimization suggestions.
Prompts are layered the same way as Lotus.AI.Prompts.QueryGeneration:
core review rules (language-agnostic) precede adapter-supplied syntax
notes, so a compromised adapter cannot repeal them via later text.
Summary
Functions
Parse the AI response into a list of suggestion maps.
Generate system prompt for query optimization analysis.
Build the user prompt containing the SQL and execution plan.
Functions
Parse the AI response into a list of suggestion maps.
Returns a list of validated suggestion maps or an empty list if parsing fails.
Generate system prompt for query optimization analysis.
Composition order
- System role, keyed off
ai_context.language(core) - Response contract (core)
- Core optimization heuristics — language-agnostic (core)
- Adapter
syntax_notes— filtered if untrusted (adapter) - Rules / response-format example (core)
Parameters
ai_context— the adapter'sai_context_map(:language,:syntax_notes, ...).
Build the user prompt containing the SQL and execution plan.
Parameters
sql- The query to optimizeexecution_plan- The execution plan string (from EXPLAIN or its equivalent)source_context- Optional source context stringfence- Markdown fence label for the statement block, fromLotus.AI.Prompts.AdapterNotes.fence_label/1