OptimizerConfig
Configuration dataclass for the optimizer.Properties
PromptOptimizer
The main optimizer class. Uses a builder pattern for configuration.Methods
set_dataset(dataset)
Set the evaluation dataset.
Returns
self for chaining.
add_provider(provider, model, **kwargs)
Add a model provider. Supports provider aliases (openrouter, together, groq,
etc.) which resolve automatically.
Returns
self for chaining.
add_metric(metric)
Add a scoring metric.
Returns
self for chaining.
set_target_from_verdict(path, metric=None)
Set the score threshold from a verdict results JSON file. Parses the file,
finds the best model’s score, and uses it as the optimization target.
Returns
self for chaining. Sets config.score_threshold, config.target_model,
and config.target_source.
benchmark_and_set_target(prompt, providers, metric=None)
Run verdict with multiple models, then set the target from the best. This is
the “benchmark first, then optimize” flow.
Returns a dict with
model_scores, best_model, best_score, and results.
run(system_prompt)
Run the optimization. Returns an OptimizationResult.
parse_verdict_results
Standalone function to parse a verdict results JSON file.
Returns a dict with
models, metrics, best_model, best_score,
target_model, and target_score.
Strategy registration
Register custom strategies so they can be used by name inOptimizerConfig
and the CLI -s flag.
register_strategy(name, cls)
Raises
TypeError if cls doesn’t inherit from Strategy.