Language Model Evaluation Harness
Project description
Promptuna
promptuna evaluates and optimizes functions that use an LM to accomplish a goal.
Such functions (hereinafter referred to as programs) do not contain just the bare completion call: they can be surrounded by arbitrary code that prepares the prompt (pre-processing) and refines the model's output (post-processing) - as it is typically the case in real-world scenarios (you don't just "call a model" and return the raw output).
In the refinement loop below, promptuna provides the primitives for you to define the metrics that judge how well your program performs (3). Then, it can use those scores to drive automated improvements on the prompt template (4).
flowchart LR
A[1. Make a program] --> B[2. Run the program]
B --> C[3. Evaluate the program]
C --> D[4. Improve the program]
D --> B
The loop above maps directly onto the package layout:
| Step | Module | Role | Key API |
|---|---|---|---|
| 1. Make a program | promptuna.program |
Wire what is under test | Program, Example, Experiment, LMConfig |
| 2. Run the program | promptuna.run |
Execute a program on one dataset row | run_trial, Trial |
| 3. Evaluate the program | promptuna.evaluate |
Score trials and run full experiments | Metric, run_experiment, RunResults, default_llm_judge |
| 4. Improve the program | promptuna.optimize |
Search for a better prompt template | optimize, Step, OptimizationResult |
promptuna.report sits alongside evaluation and optimization: it renders RunResults and optimization trajectories as markdown (render_run, render_history).
See the getting started notebook for a full working example of this cycle end to end.
Optimization
Prompt-template search (OPRO-style) treats evaluation as multi-criteria: each candidate is scored on several normalized metrics, forming a quality vector in metric space. Before comparing checkpoints, that vector is collapsed by a fixed linear scalarization—the unweighted mean of per-metric means (RunResults.overall.mean), a compensatory aggregation where gains on one metric can offset losses on another. The search is therefore single-objective in template space: it maximizes one scalar utility, keeps the best checkpoint seen so far, and does not explore a Pareto front over metrics. The proposer still receives per-metric breakdowns in the trajectory (render_history); only ranking and early stopping use the headline score.
The optimizer uses the metrics to learn the representation of the data and the expectations of the task, then encodes that knowledge in the prompt template.
Inspiration
promptuna is a proud Frankenstein of DSPy, Ragas, OPRO] and Optuna.
First and foremost, promptuna's value proposition is most similar to DSPy. The differences:
- Programs: DSPy models a program as a composable graph of predictors (
dspy.Module).promptunatreats a program as an ordinary Python function: arbitrary pre/post-processing around a completion call, without forcing signature/module abstractions. - Evaluation. DSPy passes a single metric callable to its optimizers. Multiple quality dimensions must be folded into that one function by hand.
promptunatakes alist[Metric]instead: each metric has its own name, scale (Range,Ordinal, …), and scorer (programmatic or LLM judge). Results are naively aggregated to collapse multiple metrics into the single optimization objective. - Optimization. DSPy offers several teleprompters.
promptuna's simple optimizer is OPRO-style: it rewrites a free-form prompt template from a trajectory, using the same multi-metric evaluation harness at every step, keeping the full metric breakdown visible throughout the search.
Some ideas regarding evaluation metrics are taken from the seemingly already abandoned ragas: named metrics where an LLM judge scores a trial against a rubric, with typed scales and optional rationales.
The optimization loop itself takes concepts from DeepMind's OPRO: at each step an LM proposer rewrites the prompt template from scratch using the full scored history of prior candidates.
The name of the package itself is a reference to the infamous Optuna: a fixed-budget search over trials that archives every checkpoint and returns the best one seen.
License
MIT
Made with mold
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptuna-1.12.0.tar.gz.
File metadata
- Download URL: promptuna-1.12.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5358bb1184431d97b4eabb10c41568837fbb1d814dc044aa60f092953edfe349
|
|
| MD5 |
5256a0a3e14a65a2f0f853d1366f0813
|
|
| BLAKE2b-256 |
4fb8b6f43381baf012faa82cfe3e62f5b8e6b8333673a31e04b9c246911973dd
|
File details
Details for the file promptuna-1.12.0-py3-none-any.whl.
File metadata
- Download URL: promptuna-1.12.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcb7d4adb6fd56fb774d3589a29f041b2e38e2edb78a321587d891d6a7e20098
|
|
| MD5 |
7691225f7369dfb31ae70d311e54589b
|
|
| BLAKE2b-256 |
741a909a94f08a858b3fd61ae1cd1df0301581db5b5a2c93d49cf0d08f33fe2c
|