llmguard-ci 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llmguard_ci-0.3.0/CHANGELOG.md +24 -0
- llmguard_ci-0.3.0/CONTRIBUTING.md +23 -0
- llmguard_ci-0.3.0/LICENSE +21 -0
- llmguard_ci-0.3.0/MANIFEST.in +12 -0
- llmguard_ci-0.3.0/PKG-INFO +204 -0
- llmguard_ci-0.3.0/README.md +161 -0
- llmguard_ci-0.3.0/benchmarks/__init__.py +1 -0
- llmguard_ci-0.3.0/benchmarks/download.py +56 -0
- llmguard_ci-0.3.0/benchmarks/efficient_evaluation.py +179 -0
- llmguard_ci-0.3.0/benchmarks/evaluate.py +238 -0
- llmguard_ci-0.3.0/benchmarks/prepare.py +105 -0
- llmguard_ci-0.3.0/benchmarks/requirements.txt +11 -0
- llmguard_ci-0.3.0/benchmarks/verify.py +204 -0
- llmguard_ci-0.3.0/config/evaluation.yaml +11 -0
- llmguard_ci-0.3.0/config/pricing.yaml +10 -0
- llmguard_ci-0.3.0/config/thresholds.yaml +18 -0
- llmguard_ci-0.3.0/docs/assets/llmguard-ci-dark.png +0 -0
- llmguard_ci-0.3.0/docs/assets/llmguard-ci.png +0 -0
- llmguard_ci-0.3.0/docs/benchmarks.md +100 -0
- llmguard_ci-0.3.0/docs/examples/comparison-preview.png +0 -0
- llmguard_ci-0.3.0/docs/examples/comparison.html +1 -0
- llmguard_ci-0.3.0/docs/releasing.md +88 -0
- llmguard_ci-0.3.0/docs/usage.md +505 -0
- llmguard_ci-0.3.0/examples/quickstart.py +33 -0
- llmguard_ci-0.3.0/examples/suite/baseline.jsonl +3 -0
- llmguard_ci-0.3.0/examples/suite/candidate.jsonl +3 -0
- llmguard_ci-0.3.0/examples/suite/retrieval-candidate.yaml +7 -0
- llmguard_ci-0.3.0/examples/suite/retrieval.jsonl +3 -0
- llmguard_ci-0.3.0/examples/suite/retrieval.yaml +7 -0
- llmguard_ci-0.3.0/prompts/banking77_v1.yaml +13 -0
- llmguard_ci-0.3.0/prompts/banking77_v2.yaml +16 -0
- llmguard_ci-0.3.0/pyproject.toml +50 -0
- llmguard_ci-0.3.0/requirements.txt +2 -0
- llmguard_ci-0.3.0/scripts/check_release.py +112 -0
- llmguard_ci-0.3.0/setup.cfg +4 -0
- llmguard_ci-0.3.0/src/llmguard/__init__.py +14 -0
- llmguard_ci-0.3.0/src/llmguard/_privacy.py +28 -0
- llmguard_ci-0.3.0/src/llmguard/cli.py +193 -0
- llmguard_ci-0.3.0/src/llmguard/config.py +68 -0
- llmguard_ci-0.3.0/src/llmguard/data/__init__.py +2 -0
- llmguard_ci-0.3.0/src/llmguard/data/banking77.py +100 -0
- llmguard_ci-0.3.0/src/llmguard/data/intents.py +47 -0
- llmguard_ci-0.3.0/src/llmguard/eval/__init__.py +3 -0
- llmguard_ci-0.3.0/src/llmguard/eval/aggregates.py +28 -0
- llmguard_ci-0.3.0/src/llmguard/eval/intent_judge.py +83 -0
- llmguard_ci-0.3.0/src/llmguard/eval/metrics.py +53 -0
- llmguard_ci-0.3.0/src/llmguard/eval/runner.py +75 -0
- llmguard_ci-0.3.0/src/llmguard/execution.py +190 -0
- llmguard_ci-0.3.0/src/llmguard/files.py +113 -0
- llmguard_ci-0.3.0/src/llmguard/llm/__init__.py +3 -0
- llmguard_ci-0.3.0/src/llmguard/llm/classifier.py +11 -0
- llmguard_ci-0.3.0/src/llmguard/llm/client.py +47 -0
- llmguard_ci-0.3.0/src/llmguard/llm/offline.py +44 -0
- llmguard_ci-0.3.0/src/llmguard/llm/openai.py +53 -0
- llmguard_ci-0.3.0/src/llmguard/metrics.py +35 -0
- llmguard_ci-0.3.0/src/llmguard/models.py +179 -0
- llmguard_ci-0.3.0/src/llmguard/output.py +125 -0
- llmguard_ci-0.3.0/src/llmguard/regression/__init__.py +3 -0
- llmguard_ci-0.3.0/src/llmguard/regression/comparator.py +116 -0
- llmguard_ci-0.3.0/src/llmguard/regression/gates.py +99 -0
- llmguard_ci-0.3.0/src/llmguard/regression/thresholds.py +47 -0
- llmguard_ci-0.3.0/src/llmguard/report/__init__.py +3 -0
- llmguard_ci-0.3.0/src/llmguard/report/html_report.py +91 -0
- llmguard_ci-0.3.0/src/llmguard/report/templates/report.html +61 -0
- llmguard_ci-0.3.0/src/llmguard/rest.py +189 -0
- llmguard_ci-0.3.0/src/llmguard/sdk.py +547 -0
- llmguard_ci-0.3.0/src/llmguard/statistics.py +272 -0
- llmguard_ci-0.3.0/src/llmguard/storage/__init__.py +3 -0
- llmguard_ci-0.3.0/src/llmguard/storage/case_results.py +93 -0
- llmguard_ci-0.3.0/src/llmguard/storage/database.py +149 -0
- llmguard_ci-0.3.0/src/llmguard/suite.py +517 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/PKG-INFO +204 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/SOURCES.txt +89 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/dependency_links.txt +1 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/entry_points.txt +2 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/requires.txt +36 -0
- llmguard_ci-0.3.0/src/llmguard_ci.egg-info/top_level.txt +1 -0
- llmguard_ci-0.3.0/tests/conftest.py +64 -0
- llmguard_ci-0.3.0/tests/test_banking77.py +92 -0
- llmguard_ci-0.3.0/tests/test_classifier.py +106 -0
- llmguard_ci-0.3.0/tests/test_config.py +74 -0
- llmguard_ci-0.3.0/tests/test_efficiency.py +211 -0
- llmguard_ci-0.3.0/tests/test_judge.py +74 -0
- llmguard_ci-0.3.0/tests/test_metrics.py +45 -0
- llmguard_ci-0.3.0/tests/test_pipeline.py +146 -0
- llmguard_ci-0.3.0/tests/test_prediction_files.py +156 -0
- llmguard_ci-0.3.0/tests/test_regression.py +79 -0
- llmguard_ci-0.3.0/tests/test_rest_adapter.py +195 -0
- llmguard_ci-0.3.0/tests/test_sdk.py +223 -0
- llmguard_ci-0.3.0/tests/test_statistics.py +113 -0
- llmguard_ci-0.3.0/tests/test_suite.py +119 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
First public release.
|
|
6
|
+
|
|
7
|
+
- Evaluate saved JSON, JSONL, and CSV predictions by case ID through the same
|
|
8
|
+
SDK as live systems. Reports preserve file digests and distinguish archived
|
|
9
|
+
measurements from API calls and charges incurred by the replay.
|
|
10
|
+
- Map datasets in memory with nested field selectors, including array wildcards.
|
|
11
|
+
Equivalent mapped and canonical datasets use the same fingerprint.
|
|
12
|
+
- Record and summarize per-case metadata. Register per-case custom metrics
|
|
13
|
+
with version labels and choose their direction for Quality Gates.
|
|
14
|
+
- Compare both systems, execution details, paired statistics, and matched cases
|
|
15
|
+
in a single HTML report.
|
|
16
|
+
- Install the core SDK without third-party runtime dependencies. REST, YAML,
|
|
17
|
+
OpenAI, paired statistics, BANKING77, and benchmarks use optional extras.
|
|
18
|
+
- Separate REST response caches and checkpoints by authentication context.
|
|
19
|
+
Existing REST state files require a fresh evaluation. Python-callable state
|
|
20
|
+
keeps its existing format.
|
|
21
|
+
- Reject inconsistent saved baseline scores before invoking a candidate.
|
|
22
|
+
Keep built-in HTTP request payloads out of provider debug logs.
|
|
23
|
+
- Add an offline Quick Start, a synthetic HTML report, a Python 3.11–3.13 CI
|
|
24
|
+
matrix, and a manual publication guide.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Contributing to LLMGuard CI
|
|
2
|
+
|
|
3
|
+
Create a feature branch. Install the project and development extras in a
|
|
4
|
+
virtual environment, then run the tests:
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
python -m pip install -e ".[dev]"
|
|
8
|
+
python -m pytest -q
|
|
9
|
+
python -m build
|
|
10
|
+
python -m twine check --strict dist/*
|
|
11
|
+
python scripts/check_release.py dist
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The test suite uses fixtures and mocked services. REST tests open loopback
|
|
15
|
+
sockets. Use public or synthetic fixtures for new tests and omit API keys,
|
|
16
|
+
private input data, and generated reports from commits. Keep public benchmark
|
|
17
|
+
downloads and paid experiments separate from routine tests.
|
|
18
|
+
Install `langchain-core>=0.3.86,<1` to include the optional LangChain integration test.
|
|
19
|
+
|
|
20
|
+
Record user-facing changes in `CHANGELOG.md`. Metric changes should retain a
|
|
21
|
+
reference check and update the reported metric version if their scoring
|
|
22
|
+
semantics change. For packaging changes, install the built wheel in a fresh
|
|
23
|
+
virtual environment without extras and run the SDK Quick Start.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LLMGuard CI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
include CONTRIBUTING.md CHANGELOG.md requirements.txt
|
|
2
|
+
include docs/usage.md docs/benchmarks.md docs/releasing.md docs/examples/comparison.html
|
|
3
|
+
include docs/examples/comparison-preview.png
|
|
4
|
+
include docs/assets/llmguard-ci.png docs/assets/llmguard-ci-dark.png
|
|
5
|
+
include scripts/check_release.py
|
|
6
|
+
include config/evaluation.yaml config/pricing.yaml config/thresholds.yaml
|
|
7
|
+
include prompts/banking77_v1.yaml prompts/banking77_v2.yaml
|
|
8
|
+
include examples/quickstart.py
|
|
9
|
+
include examples/suite/retrieval.jsonl examples/suite/baseline.jsonl examples/suite/candidate.jsonl
|
|
10
|
+
include examples/suite/retrieval.yaml examples/suite/retrieval-candidate.yaml
|
|
11
|
+
include benchmarks/*.py benchmarks/requirements.txt
|
|
12
|
+
include tests/conftest.py
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llmguard-ci
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A local-first regression testing framework for AI systems.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Classifier: Development Status :: 4 - Beta
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: yaml
|
|
14
|
+
Requires-Dist: PyYAML<7,>=6.0; extra == "yaml"
|
|
15
|
+
Provides-Extra: rest
|
|
16
|
+
Requires-Dist: httpx<1,>=0.28; extra == "rest"
|
|
17
|
+
Requires-Dist: llmguard-ci[yaml]; extra == "rest"
|
|
18
|
+
Requires-Dist: python-dotenv<2,>=1.0; extra == "rest"
|
|
19
|
+
Provides-Extra: openai
|
|
20
|
+
Requires-Dist: openai<3,>=2.0; extra == "openai"
|
|
21
|
+
Requires-Dist: llmguard-ci[yaml]; extra == "openai"
|
|
22
|
+
Requires-Dist: python-dotenv<2,>=1.0; extra == "openai"
|
|
23
|
+
Provides-Extra: statistics
|
|
24
|
+
Requires-Dist: numpy>=1.24; extra == "statistics"
|
|
25
|
+
Requires-Dist: scipy>=1.9; extra == "statistics"
|
|
26
|
+
Provides-Extra: banking77
|
|
27
|
+
Requires-Dist: llmguard-ci[openai]; extra == "banking77"
|
|
28
|
+
Requires-Dist: datasets<5,>=4.0; extra == "banking77"
|
|
29
|
+
Requires-Dist: scikit-learn<2,>=1.4; extra == "banking77"
|
|
30
|
+
Requires-Dist: pydantic<3,>=2.8; extra == "banking77"
|
|
31
|
+
Requires-Dist: Jinja2<4,>=3.1.6; extra == "banking77"
|
|
32
|
+
Provides-Extra: benchmarks
|
|
33
|
+
Requires-Dist: llmguard-ci[openai,statistics]; extra == "benchmarks"
|
|
34
|
+
Requires-Dist: pyarrow>=15; extra == "benchmarks"
|
|
35
|
+
Requires-Dist: rank-bm25<1,>=0.2.2; extra == "benchmarks"
|
|
36
|
+
Requires-Dist: transformers<5,>=4.57; extra == "benchmarks"
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: llmguard-ci[banking77,rest,statistics]; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest<10,>=8.0; extra == "dev"
|
|
40
|
+
Requires-Dist: build<2,>=1.2; extra == "dev"
|
|
41
|
+
Requires-Dist: twine<7,>=6; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
<h1 align="center">
|
|
45
|
+
<picture>
|
|
46
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/llmguard-ci-dark.png">
|
|
47
|
+
<img src="docs/assets/llmguard-ci.png" width="660" alt="LLMGuard CI">
|
|
48
|
+
</picture>
|
|
49
|
+
</h1>
|
|
50
|
+
|
|
51
|
+
<p align="center"><strong>A local-first regression testing framework for AI systems.</strong></p>
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
Compare AI systems on the same cases, see which results changed, and catch regressions before shipping.
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
<p align="center">
|
|
58
|
+
<a href="https://github.com/maxx0214/llmguard-ci/actions/workflows/ci.yml?query=branch%3Arelease%2F0.3.0"><img alt="GitHub Actions status for release/0.3.0" src="https://github.com/maxx0214/llmguard-ci/actions/workflows/ci.yml/badge.svg?branch=release%2F0.3.0"></a>
|
|
59
|
+
• Python 3.11–3.13 • <a href="LICENSE">MIT License</a>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<p align="center">
|
|
63
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
64
|
+
<a href="#comparison-report">Report Preview</a> ·
|
|
65
|
+
<a href="#integrations">Integrations</a> ·
|
|
66
|
+
<a href="#benchmark-validation">Benchmarks</a>
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
From a checkout or extracted source distribution, run:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python -m pip install .
|
|
75
|
+
python examples/quickstart.py
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The demo compares two local retrievers on three synthetic cases. It runs
|
|
79
|
+
without credentials and writes `results/quickstart.json` and
|
|
80
|
+
`results/quickstart.html`. It reports `WARN` because the Hit@1 drop falls
|
|
81
|
+
between the warning and failure thresholds.
|
|
82
|
+
|
|
83
|
+
## Comparison report
|
|
84
|
+
|
|
85
|
+
<a href="docs/examples/comparison.html"><img src="docs/examples/comparison-preview.png" alt="The Quick Start report compares search-v1 and search-v2. Hit@1 falls from 1.0000 to 0.6667 and receives WARN, while Recall@3 stays at 1.0000." width="960"></a>
|
|
86
|
+
|
|
87
|
+
The HTML report shows baseline and candidate scores, per-case changes, and
|
|
88
|
+
execution details together. [Download the sample HTML](docs/examples/comparison.html)
|
|
89
|
+
and open it in your browser.
|
|
90
|
+
|
|
91
|
+
## Integrations
|
|
92
|
+
|
|
93
|
+
### Python SDK
|
|
94
|
+
|
|
95
|
+
Use a Python callable to evaluate a retriever, language model, or classifier
|
|
96
|
+
and turn a Quality Gate failure into a CI failure.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from llmguard import Evaluator, System
|
|
100
|
+
|
|
101
|
+
cases = [{"id": "q1", "input": "How can I return an order?", "expected": ["returns"]}]
|
|
102
|
+
evaluator = Evaluator(
|
|
103
|
+
cases, "retrieval", ["hit@1", "recall@3"],
|
|
104
|
+
quality_gate={"max_drop": {"hit@1": 0.1}},
|
|
105
|
+
)
|
|
106
|
+
baseline = System(lambda _: ["returns", "shipping"], model_version="search-v1")
|
|
107
|
+
candidate = System(lambda _: ["shipping", "returns"], model_version="search-v2")
|
|
108
|
+
result = evaluator.compare(baseline, candidate)
|
|
109
|
+
result.report("results/search-comparison.json")
|
|
110
|
+
raise SystemExit(1 if result.status == "FAIL" else 0)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Hit@1 falls from 1 to 0 while Recall@3 stays at 1. The configured Hit@1 gate
|
|
114
|
+
returns `FAIL`. Use `min_scores` for an absolute floor, a `warn` and `fail`
|
|
115
|
+
mapping for two levels, or `on_unknown` to control how missing measurements
|
|
116
|
+
affect the verdict. A saved SDK report can serve as the baseline. See the
|
|
117
|
+
[usage guide](docs/usage.md) for async execution, custom metrics, and statistics.
|
|
118
|
+
|
|
119
|
+
### REST API
|
|
120
|
+
|
|
121
|
+
Install the REST extra with `python -m pip install ".[rest]"`. The example
|
|
122
|
+
expects a service on your machine whose response contains ranked IDs under
|
|
123
|
+
`hits`.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from llmguard import Evaluator, RESTAdapter
|
|
127
|
+
|
|
128
|
+
evaluator = Evaluator("examples/suite/retrieval.jsonl", "retrieval")
|
|
129
|
+
with RESTAdapter(
|
|
130
|
+
"http://localhost:8000/search",
|
|
131
|
+
method="POST",
|
|
132
|
+
request_mapping={"query": "input"},
|
|
133
|
+
response_mapping={"retrieved_ids": "hits.*.id"},
|
|
134
|
+
timeout=3,
|
|
135
|
+
) as search:
|
|
136
|
+
evaluator.evaluate(search).report("results/service.json")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
For an authenticated service, use HTTPS and map header names to environment
|
|
140
|
+
variables with `auth_headers`. REST calls send the mapped input fields to the
|
|
141
|
+
configured endpoint.
|
|
142
|
+
|
|
143
|
+
### Saved predictions
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from llmguard import Evaluator, PredictionFile
|
|
147
|
+
|
|
148
|
+
evaluator = Evaluator("examples/suite/retrieval.jsonl", "retrieval", ["hit@1", "mrr@3"])
|
|
149
|
+
result = evaluator.compare(
|
|
150
|
+
PredictionFile("examples/suite/baseline.jsonl"),
|
|
151
|
+
PredictionFile("examples/suite/candidate.jsonl"),
|
|
152
|
+
)
|
|
153
|
+
result.report("results/archived-comparison.json")
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
JSON, JSONL, and CSV files are joined by case ID; duplicate, missing, and
|
|
157
|
+
unexpected IDs are rejected. Use `dataset_mapping` and `prediction_mapping`
|
|
158
|
+
to read fields such as `gold_chunks.*.chunk_id` from an existing export.
|
|
159
|
+
Replaying a file makes zero model calls.
|
|
160
|
+
|
|
161
|
+
## Architecture
|
|
162
|
+
|
|
163
|
+
```mermaid
|
|
164
|
+
flowchart LR
|
|
165
|
+
Data["Dataset and field mapping"] --> Eval["Evaluator"]
|
|
166
|
+
Sources["Python, REST, or prediction files"] --> Eval
|
|
167
|
+
Eval -. Optional local state .-> SQLite[(SQLite)]
|
|
168
|
+
Eval --> Engine["Scoring and Quality Gates"]
|
|
169
|
+
Engine --> Reports["JSON and HTML reports"]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The SDK supports retrieval, lexical question-answering, and classification.
|
|
173
|
+
Optional paired inference provides bootstrap confidence intervals,
|
|
174
|
+
permutation or McNemar tests, and Holm or Bonferroni correction.
|
|
175
|
+
Generic SDK reports omit inputs, gold values, and predictions by default.
|
|
176
|
+
Use opaque case IDs and metadata. Keep SQLite state private because normalized
|
|
177
|
+
predictions are stored there. Legacy suite and BANKING77 reports include case
|
|
178
|
+
payloads. See the [data-handling notes](docs/usage.md#data-handling).
|
|
179
|
+
|
|
180
|
+
## Benchmark validation
|
|
181
|
+
|
|
182
|
+
| Dataset | Scope | Agreement with reference scorer |
|
|
183
|
+
| --- | --- | --- |
|
|
184
|
+
| SQuAD v1.1 | 100 validation questions, seed 42, two saved QA runs | Exact match and token F1 agreed within floating-point precision (maximum absolute difference below `2e-16`, on a 0–1 scale). |
|
|
185
|
+
| BEIR NFCorpus | 323 test queries, 3,633 documents, BM25 and dense rankings at K = 1, 3, 5, 10 | Hit, Recall, MRR, and nDCG agreed within the reference tool's five-decimal rounding (maximum absolute difference below `5e-6`). |
|
|
186
|
+
|
|
187
|
+
Identical predictions passed the regression gate. An intentionally degraded
|
|
188
|
+
QA variant and a truncated BM25 control failed it. These checks validate the
|
|
189
|
+
scoring and comparison paths on the recorded runs. See the
|
|
190
|
+
[benchmark methods and replay commands](docs/benchmarks.md).
|
|
191
|
+
|
|
192
|
+
## Documentation and support
|
|
193
|
+
|
|
194
|
+
The core package has no third-party runtime dependencies. Install extras for
|
|
195
|
+
REST, statistics, OpenAI, YAML, BANKING77, public benchmarks, and development
|
|
196
|
+
tools as needed. The test workflow runs without model credentials.
|
|
197
|
+
|
|
198
|
+
| Guide | What it covers |
|
|
199
|
+
| --- | --- |
|
|
200
|
+
| [Usage](docs/usage.md) | SDK, mappings, caching, statistics, and data handling |
|
|
201
|
+
| [Benchmarks](docs/benchmarks.md) | Public datasets, scoring methods, and replay instructions |
|
|
202
|
+
| [Contributing](CONTRIBUTING.md) | Local development, tests, and package checks |
|
|
203
|
+
| [Changelog](CHANGELOG.md) | Release history |
|
|
204
|
+
| [Releasing](docs/releasing.md) | Build verification and publication |
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/llmguard-ci-dark.png">
|
|
4
|
+
<img src="docs/assets/llmguard-ci.png" width="660" alt="LLMGuard CI">
|
|
5
|
+
</picture>
|
|
6
|
+
</h1>
|
|
7
|
+
|
|
8
|
+
<p align="center"><strong>A local-first regression testing framework for AI systems.</strong></p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
Compare AI systems on the same cases, see which results changed, and catch regressions before shipping.
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://github.com/maxx0214/llmguard-ci/actions/workflows/ci.yml?query=branch%3Arelease%2F0.3.0"><img alt="GitHub Actions status for release/0.3.0" src="https://github.com/maxx0214/llmguard-ci/actions/workflows/ci.yml/badge.svg?branch=release%2F0.3.0"></a>
|
|
16
|
+
• Python 3.11–3.13 • <a href="LICENSE">MIT License</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
21
|
+
<a href="#comparison-report">Report Preview</a> ·
|
|
22
|
+
<a href="#integrations">Integrations</a> ·
|
|
23
|
+
<a href="#benchmark-validation">Benchmarks</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
From a checkout or extracted source distribution, run:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install .
|
|
32
|
+
python examples/quickstart.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The demo compares two local retrievers on three synthetic cases. It runs
|
|
36
|
+
without credentials and writes `results/quickstart.json` and
|
|
37
|
+
`results/quickstart.html`. It reports `WARN` because the Hit@1 drop falls
|
|
38
|
+
between the warning and failure thresholds.
|
|
39
|
+
|
|
40
|
+
## Comparison report
|
|
41
|
+
|
|
42
|
+
<a href="docs/examples/comparison.html"><img src="docs/examples/comparison-preview.png" alt="The Quick Start report compares search-v1 and search-v2. Hit@1 falls from 1.0000 to 0.6667 and receives WARN, while Recall@3 stays at 1.0000." width="960"></a>
|
|
43
|
+
|
|
44
|
+
The HTML report shows baseline and candidate scores, per-case changes, and
|
|
45
|
+
execution details together. [Download the sample HTML](docs/examples/comparison.html)
|
|
46
|
+
and open it in your browser.
|
|
47
|
+
|
|
48
|
+
## Integrations
|
|
49
|
+
|
|
50
|
+
### Python SDK
|
|
51
|
+
|
|
52
|
+
Use a Python callable to evaluate a retriever, language model, or classifier
|
|
53
|
+
and turn a Quality Gate failure into a CI failure.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from llmguard import Evaluator, System
|
|
57
|
+
|
|
58
|
+
cases = [{"id": "q1", "input": "How can I return an order?", "expected": ["returns"]}]
|
|
59
|
+
evaluator = Evaluator(
|
|
60
|
+
cases, "retrieval", ["hit@1", "recall@3"],
|
|
61
|
+
quality_gate={"max_drop": {"hit@1": 0.1}},
|
|
62
|
+
)
|
|
63
|
+
baseline = System(lambda _: ["returns", "shipping"], model_version="search-v1")
|
|
64
|
+
candidate = System(lambda _: ["shipping", "returns"], model_version="search-v2")
|
|
65
|
+
result = evaluator.compare(baseline, candidate)
|
|
66
|
+
result.report("results/search-comparison.json")
|
|
67
|
+
raise SystemExit(1 if result.status == "FAIL" else 0)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Hit@1 falls from 1 to 0 while Recall@3 stays at 1. The configured Hit@1 gate
|
|
71
|
+
returns `FAIL`. Use `min_scores` for an absolute floor, a `warn` and `fail`
|
|
72
|
+
mapping for two levels, or `on_unknown` to control how missing measurements
|
|
73
|
+
affect the verdict. A saved SDK report can serve as the baseline. See the
|
|
74
|
+
[usage guide](docs/usage.md) for async execution, custom metrics, and statistics.
|
|
75
|
+
|
|
76
|
+
### REST API
|
|
77
|
+
|
|
78
|
+
Install the REST extra with `python -m pip install ".[rest]"`. The example
|
|
79
|
+
expects a service on your machine whose response contains ranked IDs under
|
|
80
|
+
`hits`.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from llmguard import Evaluator, RESTAdapter
|
|
84
|
+
|
|
85
|
+
evaluator = Evaluator("examples/suite/retrieval.jsonl", "retrieval")
|
|
86
|
+
with RESTAdapter(
|
|
87
|
+
"http://localhost:8000/search",
|
|
88
|
+
method="POST",
|
|
89
|
+
request_mapping={"query": "input"},
|
|
90
|
+
response_mapping={"retrieved_ids": "hits.*.id"},
|
|
91
|
+
timeout=3,
|
|
92
|
+
) as search:
|
|
93
|
+
evaluator.evaluate(search).report("results/service.json")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
For an authenticated service, use HTTPS and map header names to environment
|
|
97
|
+
variables with `auth_headers`. REST calls send the mapped input fields to the
|
|
98
|
+
configured endpoint.
|
|
99
|
+
|
|
100
|
+
### Saved predictions
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from llmguard import Evaluator, PredictionFile
|
|
104
|
+
|
|
105
|
+
evaluator = Evaluator("examples/suite/retrieval.jsonl", "retrieval", ["hit@1", "mrr@3"])
|
|
106
|
+
result = evaluator.compare(
|
|
107
|
+
PredictionFile("examples/suite/baseline.jsonl"),
|
|
108
|
+
PredictionFile("examples/suite/candidate.jsonl"),
|
|
109
|
+
)
|
|
110
|
+
result.report("results/archived-comparison.json")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
JSON, JSONL, and CSV files are joined by case ID; duplicate, missing, and
|
|
114
|
+
unexpected IDs are rejected. Use `dataset_mapping` and `prediction_mapping`
|
|
115
|
+
to read fields such as `gold_chunks.*.chunk_id` from an existing export.
|
|
116
|
+
Replaying a file makes zero model calls.
|
|
117
|
+
|
|
118
|
+
## Architecture
|
|
119
|
+
|
|
120
|
+
```mermaid
|
|
121
|
+
flowchart LR
|
|
122
|
+
Data["Dataset and field mapping"] --> Eval["Evaluator"]
|
|
123
|
+
Sources["Python, REST, or prediction files"] --> Eval
|
|
124
|
+
Eval -. Optional local state .-> SQLite[(SQLite)]
|
|
125
|
+
Eval --> Engine["Scoring and Quality Gates"]
|
|
126
|
+
Engine --> Reports["JSON and HTML reports"]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The SDK supports retrieval, lexical question-answering, and classification.
|
|
130
|
+
Optional paired inference provides bootstrap confidence intervals,
|
|
131
|
+
permutation or McNemar tests, and Holm or Bonferroni correction.
|
|
132
|
+
Generic SDK reports omit inputs, gold values, and predictions by default.
|
|
133
|
+
Use opaque case IDs and metadata. Keep SQLite state private because normalized
|
|
134
|
+
predictions are stored there. Legacy suite and BANKING77 reports include case
|
|
135
|
+
payloads. See the [data-handling notes](docs/usage.md#data-handling).
|
|
136
|
+
|
|
137
|
+
## Benchmark validation
|
|
138
|
+
|
|
139
|
+
| Dataset | Scope | Agreement with reference scorer |
|
|
140
|
+
| --- | --- | --- |
|
|
141
|
+
| SQuAD v1.1 | 100 validation questions, seed 42, two saved QA runs | Exact match and token F1 agreed within floating-point precision (maximum absolute difference below `2e-16`, on a 0–1 scale). |
|
|
142
|
+
| BEIR NFCorpus | 323 test queries, 3,633 documents, BM25 and dense rankings at K = 1, 3, 5, 10 | Hit, Recall, MRR, and nDCG agreed within the reference tool's five-decimal rounding (maximum absolute difference below `5e-6`). |
|
|
143
|
+
|
|
144
|
+
Identical predictions passed the regression gate. An intentionally degraded
|
|
145
|
+
QA variant and a truncated BM25 control failed it. These checks validate the
|
|
146
|
+
scoring and comparison paths on the recorded runs. See the
|
|
147
|
+
[benchmark methods and replay commands](docs/benchmarks.md).
|
|
148
|
+
|
|
149
|
+
## Documentation and support
|
|
150
|
+
|
|
151
|
+
The core package has no third-party runtime dependencies. Install extras for
|
|
152
|
+
REST, statistics, OpenAI, YAML, BANKING77, public benchmarks, and development
|
|
153
|
+
tools as needed. The test workflow runs without model credentials.
|
|
154
|
+
|
|
155
|
+
| Guide | What it covers |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| [Usage](docs/usage.md) | SDK, mappings, caching, statistics, and data handling |
|
|
158
|
+
| [Benchmarks](docs/benchmarks.md) | Public datasets, scoring methods, and replay instructions |
|
|
159
|
+
| [Contributing](CONTRIBUTING.md) | Local development, tests, and package checks |
|
|
160
|
+
| [Changelog](CHANGELOG.md) | Release history |
|
|
161
|
+
| [Releasing](docs/releasing.md) | Build verification and publication |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Reproducible public-dataset experiments for LLMGuard CI."""
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Fetch public inputs for the SQuAD and NFCorpus experiments."""
|
|
2
|
+
import argparse
|
|
3
|
+
import hashlib
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from time import perf_counter
|
|
7
|
+
from urllib.request import urlopen
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
NFCORPUS_REVISION = "b5026a0e96e8a7ac4f95f482a596389289d46269"
|
|
11
|
+
QRELS_REVISION = "a451b3b26d3ae1358f259c1a3a4dd61fcea35a65"
|
|
12
|
+
NFCORPUS_URL = f"https://huggingface.co/datasets/BeIR/nfcorpus/resolve/{NFCORPUS_REVISION}"
|
|
13
|
+
SOURCES = {
|
|
14
|
+
"dev-v1.1.json": "https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json",
|
|
15
|
+
"evaluate-v1.1.py": "https://raw.githubusercontent.com/allenai/bi-att-flow/master/squad/evaluate-v1.1.py",
|
|
16
|
+
"corpus.parquet": f"{NFCORPUS_URL}/corpus/corpus-00000-of-00001.parquet",
|
|
17
|
+
"queries.parquet": f"{NFCORPUS_URL}/queries/queries-00000-of-00001.parquet",
|
|
18
|
+
"test.tsv": f"https://huggingface.co/datasets/BeIR/nfcorpus-qrels/resolve/{QRELS_REVISION}/test.tsv",
|
|
19
|
+
}
|
|
20
|
+
SHA256 = {
|
|
21
|
+
"dev-v1.1.json": "95aa6a52d5d6a735563366753ca50492a658031da74f301ac5238b03966972c9",
|
|
22
|
+
"evaluate-v1.1.py": "f5a673dbbd173e29e9ea38f1b2091d883583b77b3a4c17144b223fb0f2f9bd09",
|
|
23
|
+
"corpus.parquet": "f2a1c0b570a5efdf23cfa36f5e573d062cc113c6e7251e22c69b323a33ea895e",
|
|
24
|
+
"queries.parquet": "edd2b878b8130fb3b5e3c4b9428ddc1e67fbd6eedf8ae099fca3b87838ba6b29",
|
|
25
|
+
"test.tsv": "f8fba6ef3d4dd9c3a242a8ba4ae38276fc3622fce7dcbae764766d564542fd2a",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def sha256(path: Path) -> str:
|
|
30
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def download(root: Path) -> None:
|
|
34
|
+
raw = root / "raw"
|
|
35
|
+
raw.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
for name, url in SOURCES.items():
|
|
37
|
+
path = raw / name
|
|
38
|
+
if not path.exists():
|
|
39
|
+
temp = path.with_suffix(path.suffix + ".part")
|
|
40
|
+
with urlopen(url, timeout=90) as response, temp.open("wb") as output:
|
|
41
|
+
shutil.copyfileobj(response, output)
|
|
42
|
+
if sha256(temp) != SHA256[name]:
|
|
43
|
+
raise ValueError(f"Checksum mismatch for {name}")
|
|
44
|
+
temp.replace(path)
|
|
45
|
+
digest = sha256(path)
|
|
46
|
+
if digest != SHA256[name]:
|
|
47
|
+
raise ValueError(f"Checksum mismatch for {name}")
|
|
48
|
+
print(f"{name} SHA-256 {digest}", flush=True)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
53
|
+
parser.add_argument("root", type=Path)
|
|
54
|
+
started = perf_counter()
|
|
55
|
+
download(parser.parse_args().root)
|
|
56
|
+
print(f"Download: {perf_counter() - started:.2f}s")
|