# Simple dict override
optimizer = MetaPromptOptimizer(
    model="gpt-4o",
    prompt_overrides={"reasoning_system": "Be concise. Focus on clarity."}
)
```

## How It Works

Each optimizer defines its own `DEFAULT_PROMPTS` dictionary with keys specific to that algorithm. The PromptLibrary:

1. Stores the default prompts
2. Applies your overrides (dict or callable)
3. Validates that override keys exist (catches typos early)
4. Provides `get_prompt()` for runtime access

```mermaid
flowchart LR
    subgraph Optimizer
        D[DEFAULT_PROMPTS<br />reasoning: ...<br />synthesis: ...]
    end

    subgraph PromptLibrary
        M[Merge with overrides]
        V[Validate keys]
        F[Format templates]
    end

    O[prompt_overrides<br />dict or callable]

    D --> M
    O --> M
    M --> V --> F

    F --> G[optimizer.get_prompt]
```

## Override Methods

<AccordionGroup>
  <Accordion title="Dict Override (Simple Replacement)">
    Best when you know exactly which prompt to replace with a static string:

    ```python
    from opik_optimizer import EvolutionaryOptimizer

    optimizer = EvolutionaryOptimizer(
        model="gpt-4o",
        prompt_overrides={
            "synonyms_system_prompt": "Return exactly ONE synonym. No explanation.",
            "infer_style_system_prompt": "Analyze the writing style briefly.",
        }
    )
    ```
  </Accordion>

  <Accordion title="Callable Override (Dynamic Modification)">
    Best when you need to modify existing prompts, apply conditional logic, or update multiple prompts:

    ```python
    from opik_optimizer import MetaPromptOptimizer
    from opik_optimizer.utils.prompt_library import PromptLibrary

    def customize_prompts(prompts: PromptLibrary) -> None:
        # List available keys
        print("Available keys:", prompts.keys())

        # Prepend a constraint to the reasoning prompt
        original = prompts.get("reasoning_system")
        prompts.set("reasoning_system", "Always respond in English.\n\n" + original)

        # Append format instructions to another prompt
        if "candidate_generation" in prompts.keys():
            prompts.set(
                "candidate_generation",
                prompts.get("candidate_generation") + "\n\nUse markdown formatting."
            )

    optimizer = MetaPromptOptimizer(
        model="gpt-4o",
        prompt_overrides=customize_prompts
    )
    ```
  </Accordion>
</AccordionGroup>

## Discovering Available Keys

Each optimizer has different prompt keys. Use `list_prompts()` to discover them:

```python
from opik_optimizer import MetaPromptOptimizer

optimizer = MetaPromptOptimizer(model="gpt-4o")
print("Available prompt keys:")
for key in optimizer.list_prompts():
    print(f"  - {key}")
```

### Common Keys by Optimizer

| Optimizer                           | Key Examples                                                                                      |
| ----------------------------------- | ------------------------------------------------------------------------------------------------- |
| **MetaPromptOptimizer**             | `reasoning_system`, `candidate_generation`, `synthesis`, `pattern_extraction_system`              |
| **EvolutionaryOptimizer**           | `infer_style_system_prompt`, `synonyms_system_prompt`, `semantic_mutation_system_prompt_template` |
| **FewShotBayesianOptimizer**        | `example_placeholder`, `system_prompt_template`                                                   |
| **HierarchicalReflectiveOptimizer** | `batch_analysis_prompt`, `synthesis_prompt`, `improve_prompt_template`                            |

## Reading Prompts at Runtime

After creating an optimizer, you can inspect the current prompts:

```python
optimizer = MetaPromptOptimizer(
    model="gpt-4o",
    prompt_overrides={"reasoning_system": "Custom prompt here..."}
)