Skip to main content

Promptuna

promptuna evaluates and optimizes functions that use an LM to accomplish a goal.

Such functions (hereinafter referred to as programs) are not thin wrappers around a single complete() call. Each program makes exactly one LM completion, wrapped in a deterministic scaffold — code that shapes inputs and renders the template before the call, and parses or repairs the model output after. In production, users rarely hit the raw completion; they hit the completion plus its scaffold. The harness evaluates that full product.

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
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, evaluate, 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.

Usage surfaces

promptuna can be used in three ways. All non-library surfaces share the same on-disk project layout (see samples/README.md).

Surface Status How
Library Available pip install promptuna and wire programs, metrics, and datasets in Python — see getting_started.py.
Web Server available; frontend planned Run promptuna-server against a projects root; jobs stream over HTTP + SSE. A SvelteKit UI is planned in frontend/.
Agent / terminal CLI available Run promptuna-cli against a projects root, or use SKILL.md for coding-agent workflows (run, evaluate, optimize from the terminal).

Projects live as directories under a projects root (default: repo samples/; override with PROMPTUNA_PROJECTS_ROOT). Programs and metrics are Python modules on disk — they cannot be sent over HTTP as JSON — so the server and CLI resolve them locally via name selectors.

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). promptuna treats a program as an ordinary Python function with a deterministic scaffold around a single 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. promptuna takes a list[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.

Versioning and release

This repository is a uv workspace with three publishable packages that share one version number: promptuna, promptuna-cli and promptuna-server.

Unified versioning. All three project.version fields stay in lockstep (e.g. 1.23.0 everywhere). Satellite packages declare promptuna==<that version> so pip install promptuna-cli pulls a matching core release.

What triggers a release. On every push to main, python-semantic-release scans commits since the last tag and decides whether the semver should bump.

Release steps (see .github/workflows/release.yml):

  1. PSR bumps the version in pyproject.toml, cli/pyproject.toml, and server/pyproject.toml, then runs scripts/sync_workspace_pins.py to refresh the promptuna==… pins before committing chore: release {version} and tagging v{version}.
  2. CI builds wheels for all three packages and publishes them to PyPI.
  3. A GitHub release is created for the tag.

Development. uv sync --all-groups (i.e.: just install) installs every workspace member locally. PyPI users install only what they need (promptuna, promptuna-cli, and/or promptuna-server).

License

MIT

Made with mold

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptuna-1.24.0.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptuna-1.24.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file promptuna-1.24.0.tar.gz.

File metadata

  • Download URL: promptuna-1.24.0.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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

Hashes for promptuna-1.24.0.tar.gz
Algorithm Hash digest
SHA256 fa53ad9a2eb68afeafb8e4bf944e2485df9737138766a9749609e866fa6ad5b7
MD5 4896c274fbeac0b1d183619f198c59db
BLAKE2b-256 b72affc85ca91973dc44136ecc414a0dcb9f1b6e7e6906f70a4126752ee29d64

See more details on using hashes here.

File details

Details for the file promptuna-1.24.0-py3-none-any.whl.

File metadata

  • Download URL: promptuna-1.24.0-py3-none-any.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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

Hashes for promptuna-1.24.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3122d4bf3c0dbe208b60c24c7fe5bbac93e00226e2369bde0fa6b7a7c886853
MD5 36760d0d187bb23da2bef36e7c235b94
BLAKE2b-256 84f12adedf2b0d3ff618e8774a3b5cb4eed9ae981b54e96d5180b7d95612766d

See more details on using hashes here.

Release history Release notifications | RSS feed

1.35.3

2 files

1.35.2

2 files

1.35.1

2 files

1.35.0

2 files

1.34.0

2 files

1.33.0

2 files

1.32.0

2 files

1.31.0

2 files

1.30.0

2 files

1.29.0

2 files

1.28.0

2 files

1.27.0

2 files

1.26.0

2 files

1.25.1

2 files

1.25.0

2 files

This release

1.24.0 This release

2 files

1.23.0

2 files

1.22.0

2 files

1.21.0

2 files

1.20.0

2 files

1.19.0

2 files

1.18.0

2 files

1.17.0

2 files

1.16.0

2 files

1.15.0

2 files

1.14.1

2 files

1.14.0

2 files

1.13.0

2 files

1.12.0

2 files

1.11.0

2 files

1.10.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page