# `Lotus.AI.Prompts.Optimization`
[🔗](https://github.com/elixir-lotus/lotus/blob/v1.0.0/lib/lotus/ai/prompts/optimization.ex#L1)

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.

# `parse_suggestions`

```elixir
@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`

```elixir
@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`

```elixir
@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`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
