Skip to main content

MIPROv2

MIPROv2 (Multiprompt Instruction PRoposal Optimizer v2) optimizes two things simultaneously: the system prompt instruction and the few-shot examples embedded in it. It uses Bayesian Optimization (Optuna/TPE) to efficiently search through combinations without testing all of them.

How it works

Phase 1 — Proposal
  • InstructionProposer generates N instruction variants from the seed prompt, each emphasizing a different aspect (conciseness, format, grounding, tone, etc.)
  • DemoBootstrapper creates M sets of few-shot examples by sampling from the dataset
Phase 2 — Bayesian Search
  • Each trial picks a combination: (instruction_i, demo_set_j)
  • Evaluates it on a minibatch of the dataset
  • Optuna/TPE models which combinations are most promising and prioritizes those
Output: the best (instruction, demo_set) pair assembled into a ready-to-use system prompt.

When to use MIPROv2 over GEPA

MIPROv2 shines when format and style matter as much as content — situations where seeing worked examples teaches the model what to do better than instructions alone. A technical troubleshooting bot that must follow a 4-section structure, a support bot that must respond step-by-step, or a classification agent that must match a specific output format.

Installation

Basic Usage

Parameters

Required

Optional

Output Schema

MIPROv2Result

Inspecting results

Score interpretation

The score is the average across all examples of what the evaluator returns (0.0–1.0). With the default LLMEvaluator, it represents how well the agent follows the objective as judged by the LLM.

Custom Executor

If your agent is more than a direct model call (has memory, tools, an API), pass a custom executor:

LLM Provider Options

Best Practices

MIPROv2 is most valuable when the expected output follows a specific format or style that’s hard to fully specify in instructions. A structured diagnosis template, a numbered step-by-step response, or a classification with a fixed schema are ideal cases.
The objective drives both instruction generation and LLM-based evaluation. Include the output format you expect:
MIPROv2 builds demo sets from your ground_truth_assistant field. The quality of your ground truth directly determines the quality of the few-shot examples the optimizer can select. Write ideal responses in your dataset.
More trials means better coverage of the search space but slower execution. With num_candidates=10 and num_demo_sets=5 there are 50 possible combinations. num_trials=20 covers 40% of the space guided by Bayesian search, which is usually enough.

Next Steps

GEPA

Iterative prompt improvement from failures

Retriever

Build a Retriever to load your evaluation dataset