Metadata-Version: 2.5
Name: prompt-moose
Version: 0.1.0
Summary: Multi-objective prompt optimization for decision models and LLM judges
Project-URL: Repository, https://github.com/adivekar-utexas/MOOSe
License-Expression: MIT
License-File: LICENSE
Requires-Python: <3.14,>=3.11
Requires-Dist: concurry>=0.13.2
Requires-Dist: datasets==4.0.0
Requires-Dist: litellm<2,>=1.109.1
Requires-Dist: morphic<0.3,>=0.2.4
Requires-Dist: numpy==2.3.4
Requires-Dist: openai>=2.20.0
Requires-Dist: pandas==2.3.3
Requires-Dist: pyarrow<21,>=15
Requires-Dist: pydantic-settings
Requires-Dist: pydantic==2.12.3
Requires-Dist: pymoo
Requires-Dist: pyyaml<7,>=6.0
Requires-Dist: scikit-learn==1.7.0
Requires-Dist: scipy
Requires-Dist: sentence-transformers>=3
Requires-Dist: slowburn>=0.7.0
Provides-Extra: analysis
Requires-Dist: bokeh; extra == 'analysis'
Requires-Dist: holoviews; extra == 'analysis'
Requires-Dist: hvplot; extra == 'analysis'
Provides-Extra: dev
Requires-Dist: bokeh; extra == 'dev'
Requires-Dist: holoviews; extra == 'dev'
Requires-Dist: hvplot; extra == 'dev'
Requires-Dist: pytest-timeout; extra == 'dev'
Requires-Dist: pytest==8.4.2; extra == 'dev'
Requires-Dist: python-dotenv>=1.2.2; extra == 'dev'
Requires-Dist: transformers>=4.45.0; extra == 'dev'
Description-Content-Type: text/markdown

# MOOSe

**Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging**

[![PyPI](https://img.shields.io/pypi/v/prompt-moose.svg)](https://pypi.org/project/prompt-moose/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

## Overview

MOOSe tunes the questions and label definitions that a judge uses to score responses. Give it labeled examples and an initial rubric, and it searches for a prompt that better matches your labels across multiple criteria. You can run the same workflow with a coding agent or directly from the command line.

![MOOSe workflow from the system-demo paper: dataset, rubric and experiment settings feed prompt optimization, with saved prompts and run evidence for later evaluation.](figures/moose-overview.png)

### Cite MOOSe

```bibtex
@software{moose2026,
  title={MOOSe: Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging},
  author={Divekar, Abhishek and Darshan, Parth},
  year={2026},
  url={https://github.com/adivekar-utexas/MOOSe}
}
```

## Installation

Requires Python 3.11–3.13.

```bash
python -m pip install prompt-moose              # CLI
python -m pip install 'prompt-moose[analysis]'  # optional plotting dependencies
python -m pip install 'prompt-moose[dev]'       # development and test dependencies
```

## Usage

Both examples use [NVIDIA HelpSteer2](https://huggingface.co/datasets/nvidia/HelpSteer2) to tune a TextGrad judge for five ratings: helpfulness, correctness, coherence, complexity, and verbosity. Set `OPENROUTER_API_KEY` in your environment before running the example. Training and evaluation make billable model calls.

### Agent UX

From your project directory, run `moose agents init`. It writes `AGENTS.md` at the project root, `.agents/skills/prompt-moose/SKILL.md`, and the bundled reference at `.agents/skills/prompt-moose/references/COMMANDS.md`. The setup itself is offline and does not launch an agent.

```bash
moose agents init
claude -p "Read AGENTS.md and the MOOSe skill. Use moose to optimize a judge prompt for nvidia/HelpSteer2 with TextGrad. Predict helpfulness, correctness, coherence, complexity, and verbosity. For each model role use openrouter/deepseek/deepseek-v4.1-flash with api_base null and api_key_name OPENROUTER_API_KEY. Run three training steps, evaluate the saved selection on held-out data, plot per-task MAE, and stop. If blocked, report the error without starting a server or changing permissions."
```

Give the same prompt to Codex or OpenCode from that directory. The agent can create the YAML files, run `moose`, and plot results from the saved evaluation data. You can also do those steps yourself below.

### CLI usage

Generate the three files offline. Here `--path` is the **output** file to create.

```bash
moose init dataset --hf --path expt/configs/data/dataset.yaml
moose init prompt --path expt/configs/rubric/prompts.yaml
moose init expt --textgrad --path expt/configs/algo/main.yaml \
  --dataset-path ../data/dataset.yaml --initial-prompt-path ../rubric/prompts.yaml
```

**Dataset (`expt/configs/data/dataset.yaml`).** Use the [complete HelpSteer2 dataset YAML](expt/configs/data/help2steer_dataset.yaml) in place of the generated template. It declares `prompt` and `response` as inputs and all five ratings as ordinal integers from 0 to 4. Its source block reads:

```yaml
# Excerpt from dataset.yaml
dataset:
  mode: huggingface
  name: HelpSteer2
  input_cols: [prompt, response]
  setup:
    hf_id: nvidia/HelpSteer2
    hf_config: default
    split_map: {train: train, test: validation}
```

MOOSe holds out part of the Hub training split for prompt selection. The Hub `validation` split serves as the separate test set here.

**Prompt (`expt/configs/rubric/prompts.yaml`).** Use the [complete HelpSteer2 rubric](expt/configs/rubric/help2steer_prompts.yaml). Each seed contains an instruction and optional label descriptions for every task. Here is the helpfulness entry:

```yaml
# Excerpt from prompts.yaml
prompt:
  input_col_labels: {prompt: User Prompt, response: Assistant Response}
  initial_instruction:
    0:
      helpfulness:
        instructions: Rate how well the response helps the user with the prompt.
        criteria:
          "0": Does not help address the prompt.
          "4": Provides excellent help and fully addresses the relevant needs.
```

**Experiment (`expt/configs/algo/main.yaml`).** Replace the generated main file with the example below. The `dataset` and `prompt` paths are relative to `main.yaml`, so other experiments can reuse either file. `run.output_dir` is relative to where you run `moose`.

```yaml
name: textgrad
dataset: data/dataset.yaml
prompt: prompts/prompts.yaml
train:
  steps: 3
  batch_size: 4
  val_size: 16
  validation_metric: mae
  task_llm: &model
    name: openrouter/deepseek/deepseek-v4.1-flash
    api_key_name: OPENROUTER_API_KEY
  loss_llm: *model
  gradient_llm: *model
  optimizer_llm: *model
eval: {metrics: [mae], size: 25}
run: {output_dir: outputs/helpsteer2}
```

```bash
moose train expt/configs/algo/main.yaml
moose eval expt/configs/algo/main.yaml --eval.prompts best_macro
moose infer expt/configs/algo/main.yaml --id a5defc --data inputs.parquet
```

`train` writes the run summary, prompt library, and step logs. `eval` measures the selected prompt on labeled test rows. For `infer`, replace `a5defc` with the six-character ID in `run_summary.json` and provide a CSV or Parquet file with `prompt` and `response`; no labels are needed.

To reuse the selected TextGrad rubric, set `prompt: ../outputs/helpsteer2/best_macro.yaml` in a new experiment YAML under `expt/configs/algo/`. Set a new `run.output_dir` before training again.

**Paper experiments.** The [experiment settings](expt/configs/algo/), [dataset definitions](expt/configs/data/), and [starting rubrics](expt/configs/rubric/) are already separate. The [experiment runners](expt/scripts/) show how to pair them; start with the [family runner](expt/scripts/run_family.sh). Check model IDs and credentials before running those configurations. For flags and artifact details, see the [command reference](src/prompt_moose/cli/COMMANDS.md).

## Algorithm Catalog

| Algorithm | How it proposes edits | What to evaluate |
|---|---|---|
| OPRO (`opro`) | Uses a history of prompts and numeric scores to propose candidates. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
| GPO (`gpo`) | Uses a scored prompt history and an edit budget. Textual feedback is optional. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
| TextGrad (`textgrad`) | By default, writes critiques and edit suggestions per task, then updates the rubric jointly. | `best_macro`: the final accepted prompt. The default validation gate uses MAE. |
| EmoPrompt (`emoprompt`) | Crosses over and mutates prompts, keeping a population rather than a single winner. | `final_front`: the saved non-dominated prompts evaluated as an ensemble. |

Each task declares its label column and output type, such as binary, categorical, ordinal integer, ordered string labels, or a bounded numeric score. Tasks can use different output types and loss metrics in the same rubric. For example, pair a binary safety judgment with a 0–4 helpfulness rating.

## Design Principles

- **Keep the rubric portable.** Reuse the same dataset and starting rubric across experiments, or take a saved rubric into another run without an export step.
- **Separate selection from reporting.** Use validation data to compare prompts; reserve test data for reporting. Pareto group evaluation follows the same separation.
- **Keep the evidence.** Run artifacts show what the judge predicted, what feedback the optimizer saw, and how the rubric changed.
- **Use the same workflow with or without an agent.** Agents call the same CLI and produce the same artifacts you get from running it directly.

## Contributing

Open an [issue](https://github.com/adivekar-utexas/MOOSe/issues) with a minimal reproduction, or submit a pull request with tests for the changed behavior. Never include API keys or private data in configs or logs you share.

## License

MOOSe is free forever under the [MIT License](LICENSE). Hosted model providers may charge for API calls.

If you use MOOSe in your research, please [cite it](#cite-moose).
