Metadata-Version: 2.5
Name: veracle
Version: 0.1.0
Summary: Honest numbers from LLM judges: audit the judge against humans, correct evaluation results for judge error, and make threshold decisions with error control.
Project-URL: Homepage, https://github.com/yunusimanov/veracle
Project-URL: Documentation, https://yunusimanov.github.io/veracle
Project-URL: Repository, https://github.com/yunusimanov/veracle
Project-URL: Issues, https://github.com/yunusimanov/veracle/issues
Project-URL: Changelog, https://github.com/yunusimanov/veracle/blob/main/CHANGELOG.md
Author-email: Yunus Imanov <yunus.imanov.fz@student.aztu.edu.az>
Maintainer-email: Yunus Imanov <yunus.imanov.fz@student.aztu.edu.az>
License-Expression: MPL-2.0
License-File: LICENSE
Keywords: ai-evaluation,bootstrap,llm-as-a-judge,llm-evaluation,measurement-error,misclassification,multiple-testing,rogan-gladen,sensitivity-specificity,statistical-inference
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Provides-Extra: dev
Requires-Dist: mkdocs-material<10,>=9.5; extra == 'dev'
Requires-Dist: mkdocs<2,>=1.6; extra == 'dev'
Requires-Dist: mkdocstrings[python]>=0.26; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: nox>=2024.4; extra == 'dev'
Requires-Dist: pre-commit>=3.7; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material<10,>=9.5; extra == 'docs'
Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.26; extra == 'docs'
Provides-Extra: lint
Requires-Dist: mypy>=1.10; extra == 'lint'
Requires-Dist: ruff>=0.6; extra == 'lint'
Provides-Extra: test
Requires-Dist: pytest-cov>=5.0; extra == 'test'
Requires-Dist: pytest>=8.0; extra == 'test'
Description-Content-Type: text/markdown

# veracle

[![CI](https://github.com/yunusimanov/veracle/actions/workflows/ci.yml/badge.svg)](https://github.com/yunusimanov/veracle/actions/workflows/ci.yml)
[![Docs](https://github.com/yunusimanov/veracle/actions/workflows/docs.yml/badge.svg)](https://yunusimanov.github.io/veracle)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL_2.0-blue.svg)](LICENSE)

**Honest numbers from LLM judges.**

Most AI evaluations today are scored by another model: an LLM judge decides
whether each answer is correct, helpful or safe. Judges make mistakes, and
those mistakes are almost never accounted for. A judge that waves through
20 % of wrong answers turns a 75 % model into an 81 % model, and the
confidence interval around that number is computed as if the judge were
perfect.

veracle fixes this in three steps:

1. **Audit the judge.** Compare it with human labels on a small sample and
   estimate its sensitivity and specificity, with exact intervals, a
   sample size planner and a test of whether it errs equally for every
   model.
2. **Correct the result and carry the uncertainty.** Remove the judge's
   bias (Rogan-Gladen, or prediction-powered inference when the audit is a
   subsample of the evaluation) and propagate the uncertainty of the audit
   into the final interval, with the delta method or a (cluster) bootstrap.
3. **Decide with error control.** Answer "did the model clear the bar?" or
   "is model A better than model B?" as pass, fail or inconclusive, with a
   guaranteed bound on the probability of a wrong claim, also across many
   models or benchmarks.

The result is not a score but a claim that can be defended.

## Installation

```bash
pip install veracle
```

Python 3.10 or newer is required. The only runtime dependency is NumPy.

## Quick start

The example simulates a model whose true pass rate is 75 %, scored by a
lenient judge that passes 40 % of wrong answers. A human audit of 400
answers measures the judge.

```python
import veracle as vc
from veracle.datasets import simulate_evaluation

data = simulate_evaluation(
    3000, true_rate=0.75, sensitivity=0.95, specificity=0.6, n_audit=400, seed=11
)

# 1. Audit: how does the judge compare with humans?
print(data.audit.summary())
# audited items: 400 (303 truly pass, 97 truly fail)
# sensitivity: 0.960 (95% CI 0.932 to 0.979)
# specificity: 0.701 (95% CI 0.600 to 0.790)
# ...

# 2. Correct the judge's pass rate and carry the audit uncertainty.
result = vc.correct_rate(data.audit, data.judge)
print(result.summary())
# corrected 0.7782 (95% CI 0.7323 to 0.8240); naive judge rate 0.8137; rogan-gladen (delta)

# 3. Did the model clear the 80 % release bar?
print(vc.threshold_decision(result, threshold=0.80, name="model-v2"))
# model-v2: INCONCLUSIVE (estimate 0.7782, bounds 0.7397 to 0.8166, threshold 0.8;
#           naive judge verdict: pass)
```

The judge alone says the model passes. Once its errors are accounted for,
the evidence does not support that claim.

With your own data, build the audit from paired labels with
`vc.JudgeAudit.from_labels(human_labels, judge_labels)` and pass the judge's
verdicts on the full evaluation to `vc.correct_rate`.

Several models against one bar, with Holm correction:

```python
results = {name: vc.correct_rate(audit, verdicts) for name, verdicts in runs.items()}
decisions = vc.decide_many(results, threshold=0.80, method="holm")
```

Is model A really better than model B?

```python
diff = vc.compare_rates(audit, verdicts_a, verdicts_b, paired=True)
vc.threshold_decision(diff, threshold=0.0, name="A minus B")
```

Several answers per prompt? Pass the prompt identifiers:

```python
vc.correct_rate(audit, judge_verdicts, clusters=prompt_ids, method="bootstrap", seed=0)
```

## What is inside

| Module | Purpose | Main objects |
| --- | --- | --- |
| `veracle.audit` | Judge sensitivity and specificity, audit planning, consistency across models | `JudgeAudit`, `audit_size`, `judge_consistency`, `naive_bias` |
| `veracle.correction` | Misclassification correction with uncertainty propagation | `correct_rate`, `ppi_rate`, `compare_rates`, `CorrectedRate` |
| `veracle.decisions` | Pass, fail or inconclusive with error control | `threshold_decision`, `decide_many`, `adjust_pvalues` |
| `veracle.datasets` | Simulated judged evaluations | `simulate_evaluation` |

## Command line

```bash
veracle correct --items 3000 --judge-pass 2460 --tp 190 --fn 10 --tn 160 --fp 40 --threshold 0.8
veracle audit-size --half-width 0.03 --rate 0.7 --sensitivity 0.9 --specificity 0.8 --items 5000
```

## Documentation

The user guide, the derivations and the API reference are at
<https://yunusimanov.github.io/veracle>.

## Related work

veracle is the third library in a series on statistically sound use of AI
systems, together with [anywatch](https://github.com/yunusimanov/anywatch)
(anytime-valid post-market monitoring) and
[fewlabels](https://github.com/yunusimanov/fewlabels) (design and robustness
for prediction-powered inference).

## Citing

If you use veracle in academic work, please cite it using the metadata in
[CITATION.cff](CITATION.cff) or the "Cite this repository" button on GitHub.

## Contributing

Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) and
the [Code of Conduct](CODE_OF_CONDUCT.md).

## License

veracle is distributed under the [Mozilla Public License 2.0](LICENSE).

## Author

**Yunus Imanov**, Researcher, Department of Engineering Mathematics and
Artificial Intelligence, Azerbaijan Technical University, Baku, Azerbaijan.
Contact: yunus.imanov.fz@student.aztu.edu.az
