Metadata-Version: 2.5
Name: evalpen
Version: 0.1.0
Summary: LLM evaluation you can trust: compare prompts, catch hallucinations, and calibrate your LLM judge. From your coding agent, CLI, Python or CI.
Project-URL: Homepage, https://github.com/Emmrui/evalpen
Project-URL: Issues, https://github.com/Emmrui/evalpen/issues
Author: Emmanuelle Ruimy
License-Expression: MIT
License-File: LICENSE
Keywords: evaluation,hallucination,llm,llm-as-a-judge,mcp,prompt-engineering
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: mcp<3,>=2.0
Description-Content-Type: text/markdown

# EvalPen

**Build an LLM judge you can trust, then use it. Open source, local, and inside your agent.**

EvalPen is a Python library for LLM evaluation, with four ways in: an MCP server for your coding agent (Claude Code, Cursor, or any MCP client), a CLI, a Python API and a CI check. There's no dashboard and no account. In your agent, you ask in plain language and get a report back in the conversation.

> "Compare prompt v1 and v2 on my 50 test cases."
> "Is this answer supported by these documents?"
> "Here are 30 hand-labeled examples. Can I trust my judge?"

> Early version (0.1). Tested with fake models so far: feedback from real use is very welcome.

## Why

- **Prompt changes get tested by vibes.** Three examples, eyeballed. Regressions ship.
- **LLM judges get trusted blindly.** Judges have known biases (position, length) and can disagree with humans on hard cases. Most setups never check.
- **Eval frameworks take setup.** Many teams never get past it.

EvalPen makes evaluation a one-sentence ask, and every report states how reliable its judge is.

## Tools

| Tool | What it does | Status |
| --- | --- | --- |
| `align_judge` | Improves a judge's rubric until it agrees with your own labels, checked on held-out examples | available |
| `compare_prompts` | Is prompt (or model) B really better than A? Order-swapped pairwise judging, confidence interval, regressions | available |
| `check_faithfulness` | Splits an answer into atomic claims and checks each against the source documents | available |
| `calibrate_judge` | Measures judge vs. human agreement (raw agreement, Cohen's kappa, disagreements) | available |
| `create_eval_set` | Builds a varied test set from your logs (no LLM) or from a description of the app | available |

## How it works

- **Pairwise judging.** The judge picks the better of two answers against your criteria. This is more stable than absolute 1–10 scores.
- **Position-bias control.** Each pair is judged twice with A/B swapped. A flipped verdict counts as a tie and gets flagged.
- **Confidence intervals.** Win rates come with an interval, so you don't conclude from 10 examples.
- **Local first.** Test cases, runs and reports stay on your machine as JSONL and Markdown. LLM calls use your own API key.

## Try it now

Five tools work today: **test set creation**, **judge alignment**, **prompt comparison**, **hallucination check** and **judge calibration**.

### Build a test set

From your own logs (preferred): EvalPen removes duplicates and picks the most varied inputs, so 30 cases cover 30 situations instead of 30 versions of the most common question. No LLM, free, deterministic.

```bash
uvx evalpen eval-set --from-logs logs.jsonl --n 30 --out cases.jsonl
```

From a description, when you have no logs yet: an LLM lists realistic scenarios (typical, edge cases, ambiguous, should refuse, tries to trick) and writes cases for each, with what a good answer must do. Review synthetic cases before trusting them.

```bash
uvx evalpen eval-set --describe "Support chatbot for a home internet provider" --n 30 --model anthropic:<model-id>
```

### Align your judge with your own labels

Label 20 to 50 examples by hand, write a first rubric, and let EvalPen improve it until the LLM judge agrees with you. Part of your examples is held out and never shown to the rewriting step, so a rubric that just memorizes your cases is rejected.

```bash
uvx evalpen align labels.jsonl \
  --rubric "Pass if the answer helps the customer." \
  --labels pass,fail \
  --judge anthropic:<model-id>
```

```
Judge alignment: holdout kappa 0.31 -> **0.78** (target 0.70 reached)
Examples: 21 to improve the rubric, 9 held out to check it

| Round | Train kappa | Holdout kappa | Kept | What changed |
| 0 | 0.35 | 0.31 | yes | starting rubric |
| 1 | 0.72 | 0.78 | yes | Hedged answers now fail; partial refunds count as helpful. |

Saved the calibrated judge to judge.json
```

*(Example output.)* Each line of `labels.jsonl` has `output` and `human`, plus optional `id`, `input` and `context`. Then grade new outputs with the calibrated judge:

```bash
uvx evalpen grade new_outputs.jsonl --judge-file judge.json --out graded.jsonl
```

`judge.json` is plain JSON with the rubric in it: read it, edit it, commit it.

### Compare two prompts (or two models)

Both versions answer every test case. The judge compares each pair twice, swapping which answer comes first; if the verdict flips with the order, the pair counts as a tie. You get B's win rate with a 95% confidence interval and a sign test, plus the cases where A still wins.

```bash
uvx evalpen compare cases.jsonl \
  --a prompts/v1.txt --b prompts/v2.txt \
  --model anthropic:<model-id> \
  --judge-file judge.json \
  --label-a v1 --label-b v2
```

```
v2 wins 31 of 44 decisive comparisons (70%, 95% CI 56–82%): **v2 is better** (sign test p = 0.010)

- v2 better: 31
- v1 better: 13
- Ties: 6 (of which 2 changed verdict when the order was swapped)

Cases where v1 beats v2 (look here before shipping v2):
- case_12: v2 drops the currency from the amount
...
```

*(Example output.)* Prompts can use `{input}` and `{context}` placeholders, or be a system prompt. Compare two models with `--model-b`, or compare existing answers (say, exported from production) by giving each case `output_a` and `output_b`. In CI, `--fail-if-worse` exits with code 1 when B is a significant regression.

### Check an answer against its sources

EvalPen splits the answer into atomic claims, then checks each one against the sources only: supported, contradicted, or unverifiable.

```bash
export ANTHROPIC_API_KEY=...        # or OPENAI_API_KEY, or run Ollama locally for free
uvx evalpen faithfulness \
  --answer answer.txt \
  --sources doc1.md doc2.md \
  --judge anthropic:<model-id>
```

```
Faithfulness: **67%** of 3 claims supported by the sources (judge: anthropic:<model-id>)

- Supported: 2
- Contradicted: 0
- Unverifiable: 1

Not found in the sources (possible hallucinations):
- Gustave Eiffel designed it alone.
  - No source names the designer.
```

*(Example output.)* `--answer` and `--sources` take file paths or plain text. Add `--fail-below 0.9` to fail a CI job when too many claims are unsupported.

**Judge models** are written `provider:model`:

| Provider | Example | Key |
| --- | --- | --- |
| Anthropic | `anthropic:<model-id>` | `ANTHROPIC_API_KEY` |
| OpenAI or any compatible API | `openai:<model-id>` | `OPENAI_API_KEY` (+ `OPENAI_BASE_URL`) |
| Ollama (local, free) | `ollama:<model-name>` | none |

Set `EVALPEN_JUDGE` to skip `--judge` every time. Replies are cached in `~/.cache/evalpen`, so re-running the same check costs nothing (`--no-cache` or `EVALPEN_NO_CACHE=1` to disable).

### Calibrate your judge

Give it a JSONL file where each line has a human label and your LLM judge's label:

```json
{"id": "case_01", "human": "pass", "judge": "pass"}
{"id": "case_05", "human": "fail", "judge": "pass"}
```

```bash
uvx evalpen calibrate examples/judge_vs_human.jsonl
```

```
Judge calibration on 20 examples: **reliable**

- Raw agreement: 85% (95% CI 64%–95%)
- Cohen's kappa: 0.69 (substantial)
- Threshold used: kappa >= 0.6

Disagreements (3):
- case_05: human='fail', judge='pass'
...
```

Add `--fail-if-unreliable` to exit with code 1 in CI when kappa is below 0.6.

### In your agent (MCP)

All tools are available to your agent through the MCP server:

```bash
claude mcp add evalpen -e EVALPEN_JUDGE=anthropic:<model-id> -e ANTHROPIC_API_KEY=... -- uvx evalpen mcp
```

Then ask: *"Check whether this answer is supported by these documents."*

## No install: the EvalPen skill

For people who use Claude in the browser rather than Claude Code, `skills/evalpen/` packages the same methods as a skill: claim-by-claim faithfulness, order-swapped comparison, calibration and alignment with a holdout, test set building. Claude acts as the judge and a small bundled script computes every statistic. Add the folder as a skill in Claude, then ask, for example, *"Compare these two prompts on these cases with the EvalPen method."*

Trade-off: with the skill the judge is always Claude and nothing is cached, so results are less reproducible than with the MCP server or CLI.

## Self-host for your team

Companies can run EvalPen inside their own cloud and add it to Claude as a remote MCP connector. Data never leaves the company: EvalPen only talks to the judge model you configure (typically your internal LLM gateway).

```bash
docker build -t evalpen .
docker run -p 8000:8000 \
  -e EVALPEN_AUTH_TOKEN=change-me \
  -e EVALPEN_JUDGE=openai:<model> \
  -e OPENAI_BASE_URL=https://llm-gateway.internal/v1 \
  -e OPENAI_API_KEY=... \
  -e EVALPEN_LOCK_JUDGE=1 \
  evalpen
```

- MCP endpoint: `https://<your-host>/mcp` (put it behind your usual HTTPS load balancer)
- Health check: `GET /healthz`, open without auth, for load balancers and Kubernetes probes
- Stateless: run as many replicas as you need, no shared session store

| Variable | Purpose |
| --- | --- |
| `EVALPEN_AUTH_TOKEN` | Shared secret. Clients send `Authorization: Bearer <token>`. Required when binding to a network address. |
| `EVALPEN_ALLOW_NO_AUTH=1` | Skip the token only if a gateway in front already authenticates users (SSO proxy). |
| `EVALPEN_ALLOWED_HOSTS` | Comma-separated hostnames to accept (DNS-rebinding protection). |
| `EVALPEN_JUDGE` | Default judge model. |
| `EVALPEN_LOCK_JUDGE=1` | Callers cannot pick another judge: every evaluation goes through the approved model. |
| `EVALPEN_CACHE_DIR` | Reply cache location (`/data/cache` in the image; mount a volume to keep it). |

Without Docker: `evalpen mcp --http --host 0.0.0.0 --port 8000` with the same variables.

## Usage (planned for v0.1)

*The commands below are the target interface. They may change.*

**In your agent (MCP + skill)**

```bash
claude mcp add evalpen -- uvx evalpen mcp
```

Then just ask: *"I changed the classification prompt. Compare it with the old one on my test cases."* The agent calls `compare_prompts`, summarizes the regressions, and can fix the prompt and re-run.

**From the terminal (CLI)**

```bash
evalpen compare prompts/v1.txt prompts/v2.txt --cases tests.jsonl
```

**From Python**

```python
from evalpen import compare, check_faithfulness, get_llm

judge = get_llm("anthropic:<model-id>")
result = compare(prompt_a, prompt_b, cases="tests.jsonl", judge=judge)
report = check_faithfulness(answer, sources=docs, judge=judge)  # works today
```

**In CI (block regressions before merge)**

```yaml
- run: evalpen compare main.txt pr.txt --cases tests.jsonl --fail-if-win-rate-below 0.5
```

## Architecture

```
  MCP + skill     CLI      Python API      CI
        \          |           |          /
         ──────  evalpen core library  ──────
         create_eval_set · compare_prompts
         check_faithfulness · calibrate_judge
         runner · judge · stats
            /                        \
     local files (JSONL)        LLM APIs (your key)
```

All logic lives in the core library. The CLI, MCP server, skill and CI check are thin layers on top.

## Roadmap

- [x] Core library + CLI + MCP server skeleton
- [x] `calibrate_judge` + Cohen's kappa (v0.0.1)
- [x] `check_faithfulness` + LLM layer (Anthropic, OpenAI-compatible, Ollama) with caching (v0.0.2)
- [x] `create_eval_set` from logs or a description, and the EvalPen skill (v0.1.0)
- [x] Hosted mode: HTTP transport, bearer auth, health check, Dockerfile (v0.0.3)
- [x] `align_judge`: automatic rubric improvement checked on a holdout, `evalpen grade` (v0.0.4)
- [x] `compare_prompts`: order-swapped pairwise judging, Wilson CI, sign test, `--fail-if-worse` (v0.0.5)
- [ ] Batch evaluation tool (many answers in one call)
- [ ] Native AWS Bedrock and Google Vertex judges
- [ ] GitHub Action
- [ ] Demo dataset, GIF, tests
- [ ] v0.1 release: PyPI + MCP registry

## Background

Built by an AI engineer who shipped LLM classification and recommendation systems at scale, where every release was validated with human review plus LLM-as-a-judge. EvalPen packages that workflow so anyone can use it from their agent.

## License

MIT
