Docs, method and reports

Quickstart

From README.md at modelpin 0.5.7.

Install

Python 3.11 or newer.

pip install "modelpin[providers]"      # or: pipx install "modelpin[providers]"
modelpin version                        # -> modelpin 0.5.7

The providers extra installs the OpenAI, Anthropic and Google SDKs. Plain pip install modelpin is enough for the offline demo.

Windows PowerShell: type modelpin, not mp. PowerShell has a built-in mp alias (Move-ItemProperty) that wins over the program. mp works in cmd, bash and zsh.

Every modelpin command below also works as python -m modelpin ..., which needs no Modelpin entry on your PATH — useful in a venv you have not activated, in a container, or when a security policy blocks the generated modelpin.exe. Commands still print their follow-up suggestions as modelpin ...; prefix those the same way.

Try it offline

No API key, no cost. modelpin init --demo writes a small sandbox with four scenarios and recorded model answers, and runs the same diff and statistics as a live check (with the semantic judge off, since there is no key to call it with):

modelpin init --demo
cd modelpin-demo
modelpin baseline --fixtures traces.json
modelpin check --to demo-model-v2 --fixtures traces.json

You will see one scenario per verdict:

scenario verdict why
greeting unchanged same behavior on both models
refund_request regression the new model calls lookup_order twice — the final text is identical, so a text diff would miss it
angry_customer regression the new model refuses an action the old one performed
invoice_parse changed_minor "Total: $5" became "Total: 5", breaking the scenario's text check

The command exits 1 because regressions were found — that is what fails a CI build. The full report is written to .modelpin/last-report.md, the same file the GitHub Action posts on a pull request. Beside it, .modelpin/migration-report.md tells the same result in plain English for whoever decides on the switch: a one-paragraph verdict, each changed scenario with a before and after example, what the check did not cover, and the run's date, models, runs and calls. Edit traces.json and re-run to watch the verdicts move.

Use it on your app

1. Set up. In your repository:

modelpin init

init reads your code to find the model you already call (for example gpt-4o-mini in client.chat.completions.create(model="gpt-4o-mini", ...)) and writes modelpin.yaml with that model, its provider, and a judge model different from your current model. (If you later want to check the judge's own model as a candidate, change judge_model: first.) It also writes a starter scenario in scenarios/. It never overwrites existing files. modelpin scan shows every model id it finds.

2. Describe what your app does. Put a few real requests from your app in scenarios/, one JSON file each — the system prompt, the user message, and any tools. For example:

{
  "id": "route_ticket",
  "name": "Route a support ticket to the right queue",
  "input": {
    "messages": [
      {"role": "system", "content": "Route the ticket. Reply with exactly one of: billing, bug, account, other."},
      {"role": "user", "content": "I was charged twice for my March invoice."}
    ],
    "temperature": 0
  },
  "assertions": {"must_contain": ["billing"]}
}

Templates for classifiers, JSON extraction, refusal policies, tool-using agents and free-text answers: Writing scenarios. modelpin init --agent-example adds a runnable tool-calling agent scenario.

Faster: draft them from your code. modelpin draft app/support.py sends that one file to your configured model (one call, your key, key-shaped strings redacted first) and writes draft scenarios to scenarios/.drafts/, which baseline and check ignore. The system prompt and tools are copied only if they appear in the file; the user messages, canned tool results and suggested assertions are invented and marked as such. Review each draft, then move it into scenarios/.

3. Record your current model.

export OPENAI_API_KEY=sk-...     # your key; see "Providers and credentials" for the others
modelpin baseline

Each scenario runs 5 times; the results are saved to .modelpin/baseline-<model>.json. Commit that file if you want CI to compare against it (it holds model outputs, not your API key).

4. Check a candidate model.

modelpin check --to gpt-4.1

Before it spends anything, check prints how many calls the run will make. Then it replays your scenarios on the candidate, compares, and prints a verdict per scenario.

A good first sanity check is to compare your model against itself (modelpin check --to <your current model>): it should come back unchanged. If a scenario flags against itself, its prompt leaves the model too much freedom — see Writing scenarios.

Reading the results

Verdict Meaning Exit code
unchanged no significant behavior change 0
changed_minor something moved — a text check started failing, tool arguments changed, or a regression did not reproduce. Read it; it does not fail the build 0
regression a real, reproduced change in tool calls, refusals, or meaning 1
insufficient_evidence one side recorded nothing usable (for example empty answers) 3 (unless another scenario regressed: 1 wins)
Exit code Meaning
0 no regression
1 at least one regression — pin your current model until you have looked
3 the run could not fully answer (a scenario was unmeasurable or rejected by the provider, or nothing could be compared). Not a clean result
4 Modelpin could not run at all: missing key, invalid flag value, unreadable config, no scenarios. Nothing was measured
2 usage error: an unknown option or a missing --to

Every flagged scenario shows one example run from each model, so you can see what changed. Each check also writes .modelpin/runs/check-<from>-to-<to>-<time>.json: the exit code, every verdict with its signals, and every candidate run — for scripts, and for reading the full runs behind a verdict.

"Regression" means your app's behavior changed from the baseline — Modelpin does not judge which model is better. A new model that starts calling a tool your prompt asked for is a change worth reviewing, even if you like it.

When a run's scenarios could not have detected certain kinds of change (for example, no judge configured and no tool calls), the output says so under coverage: instead of implying a clean bill of health.