Lotus.AI.Prompts.Optimization (Lotus v1.0.0)

Copy Markdown View Source

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_suggestions(content)

@spec parse_suggestions(String.t()) :: [map()]

Parse the AI response into a list of suggestion maps.

Returns a list of validated suggestion maps or an empty list if parsing fails.

system_prompt(ai_context)

@spec system_prompt(map()) :: String.t()

Generate system prompt for query optimization analysis.

Composition order

  1. System role, keyed off ai_context.language (core)
  2. Response contract (core)
  3. Core optimization heuristics — language-agnostic (core)
  4. Adapter syntax_notes — filtered if untrusted (adapter)
  5. Rules / response-format example (core)

Parameters

  • ai_context — the adapter's ai_context_map (:language, :syntax_notes, ...).

user_prompt(sql, execution_plan, source_context \\ nil, fence \\ "sql")

@spec user_prompt(String.t(), String.t() | nil, String.t() | nil, String.t()) ::
  String.t()

Build the user prompt containing the SQL and execution plan.

Parameters

  • sql - The query to optimize
  • execution_plan - The execution plan string (from EXPLAIN or its equivalent)
  • source_context - Optional source context string
  • fence - Markdown fence label for the statement block, from Lotus.AI.Prompts.AdapterNotes.fence_label/1