promptdrift-py 0.1.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.
- promptdrift_py-0.1.0/.gitattributes +10 -0
- promptdrift_py-0.1.0/.github/workflows/ci.yml +46 -0
- promptdrift_py-0.1.0/.gitignore +31 -0
- promptdrift_py-0.1.0/CHANGELOG.md +34 -0
- promptdrift_py-0.1.0/CONTRIBUTING.md +64 -0
- promptdrift_py-0.1.0/LICENSE +201 -0
- promptdrift_py-0.1.0/PKG-INFO +215 -0
- promptdrift_py-0.1.0/README.md +183 -0
- promptdrift_py-0.1.0/README.zh-CN.md +177 -0
- promptdrift_py-0.1.0/docs/ci.md +67 -0
- promptdrift_py-0.1.0/docs/index.md +41 -0
- promptdrift_py-0.1.0/docs/suite-reference.md +91 -0
- promptdrift_py-0.1.0/docs/verdicts.md +58 -0
- promptdrift_py-0.1.0/examples/README.md +24 -0
- promptdrift_py-0.1.0/examples/extractor/promptest.yaml +32 -0
- promptdrift_py-0.1.0/examples/support-agent/promptest.yaml +40 -0
- promptdrift_py-0.1.0/mkdocs.yml +34 -0
- promptdrift_py-0.1.0/pyproject.toml +102 -0
- promptdrift_py-0.1.0/schema/promptest.schema.json +563 -0
- promptdrift_py-0.1.0/scripts/gen_schema.py +26 -0
- promptdrift_py-0.1.0/src/promptdrift/__init__.py +103 -0
- promptdrift_py-0.1.0/src/promptdrift/adapters/__init__.py +31 -0
- promptdrift_py-0.1.0/src/promptdrift/adapters/cache.py +75 -0
- promptdrift_py-0.1.0/src/promptdrift/adapters/mock.py +64 -0
- promptdrift_py-0.1.0/src/promptdrift/adapters/openai_compat.py +107 -0
- promptdrift_py-0.1.0/src/promptdrift/adapters/snapshot_store.py +80 -0
- promptdrift_py-0.1.0/src/promptdrift/cli/__init__.py +1 -0
- promptdrift_py-0.1.0/src/promptdrift/cli/app.py +432 -0
- promptdrift_py-0.1.0/src/promptdrift/cli/scaffold.py +127 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/__init__.py +75 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/assertions.py +318 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/results.py +120 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/snapshot.py +94 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/suite.py +322 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/templates.py +52 -0
- promptdrift_py-0.1.0/src/promptdrift/domain/verdict.py +322 -0
- promptdrift_py-0.1.0/src/promptdrift/errors.py +32 -0
- promptdrift_py-0.1.0/src/promptdrift/ports.py +75 -0
- promptdrift_py-0.1.0/src/promptdrift/py.typed +0 -0
- promptdrift_py-0.1.0/src/promptdrift/services/__init__.py +22 -0
- promptdrift_py-0.1.0/src/promptdrift/services/cost.py +55 -0
- promptdrift_py-0.1.0/src/promptdrift/services/differ.py +34 -0
- promptdrift_py-0.1.0/src/promptdrift/services/judge.py +125 -0
- promptdrift_py-0.1.0/src/promptdrift/services/junit.py +59 -0
- promptdrift_py-0.1.0/src/promptdrift/services/loader.py +65 -0
- promptdrift_py-0.1.0/src/promptdrift/services/persistence.py +38 -0
- promptdrift_py-0.1.0/src/promptdrift/services/reporter.py +252 -0
- promptdrift_py-0.1.0/src/promptdrift/services/runner.py +134 -0
- promptdrift_py-0.1.0/tests/__init__.py +0 -0
- promptdrift_py-0.1.0/tests/adapters/__init__.py +0 -0
- promptdrift_py-0.1.0/tests/adapters/test_cache.py +94 -0
- promptdrift_py-0.1.0/tests/adapters/test_factory.py +28 -0
- promptdrift_py-0.1.0/tests/adapters/test_mock.py +64 -0
- promptdrift_py-0.1.0/tests/adapters/test_openai_compat.py +157 -0
- promptdrift_py-0.1.0/tests/adapters/test_snapshot_store.py +90 -0
- promptdrift_py-0.1.0/tests/conftest.py +160 -0
- promptdrift_py-0.1.0/tests/golden/__init__.py +0 -0
- promptdrift_py-0.1.0/tests/golden/files/markdown_report.md +54 -0
- promptdrift_py-0.1.0/tests/golden/files/markdown_report_full.md +55 -0
- promptdrift_py-0.1.0/tests/golden/files/terminal_report.txt +14 -0
- promptdrift_py-0.1.0/tests/golden/test_reports.py +83 -0
- promptdrift_py-0.1.0/tests/integration/__init__.py +0 -0
- promptdrift_py-0.1.0/tests/integration/test_cli.py +177 -0
- promptdrift_py-0.1.0/tests/integration/test_examples.py +24 -0
- promptdrift_py-0.1.0/tests/integration/test_lifecycle.py +135 -0
- promptdrift_py-0.1.0/tests/test_schema_sync.py +35 -0
- promptdrift_py-0.1.0/tests/unit/__init__.py +0 -0
- promptdrift_py-0.1.0/tests/unit/test_assertions.py +128 -0
- promptdrift_py-0.1.0/tests/unit/test_cost.py +76 -0
- promptdrift_py-0.1.0/tests/unit/test_judge.py +194 -0
- promptdrift_py-0.1.0/tests/unit/test_junit.py +46 -0
- promptdrift_py-0.1.0/tests/unit/test_loader.py +49 -0
- promptdrift_py-0.1.0/tests/unit/test_runner.py +90 -0
- promptdrift_py-0.1.0/tests/unit/test_suite.py +213 -0
- promptdrift_py-0.1.0/tests/unit/test_templates.py +59 -0
- promptdrift_py-0.1.0/tests/unit/test_verdict.py +240 -0
- promptdrift_py-0.1.0/uv.lock +1619 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: astral-sh/setup-uv@v5
|
|
14
|
+
with:
|
|
15
|
+
enable-cache: true
|
|
16
|
+
- run: uv python install 3.13
|
|
17
|
+
- run: uv sync
|
|
18
|
+
- run: uv run ruff check .
|
|
19
|
+
- run: uv run ruff format --check .
|
|
20
|
+
|
|
21
|
+
typecheck:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: astral-sh/setup-uv@v5
|
|
26
|
+
with:
|
|
27
|
+
enable-cache: true
|
|
28
|
+
- run: uv python install 3.13
|
|
29
|
+
- run: uv sync
|
|
30
|
+
- run: uv run pyright
|
|
31
|
+
|
|
32
|
+
test:
|
|
33
|
+
runs-on: ${{ matrix.os }}
|
|
34
|
+
strategy:
|
|
35
|
+
fail-fast: false
|
|
36
|
+
matrix:
|
|
37
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
38
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: astral-sh/setup-uv@v5
|
|
42
|
+
with:
|
|
43
|
+
enable-cache: true
|
|
44
|
+
- run: uv python install ${{ matrix.python-version }}
|
|
45
|
+
- run: uv sync --python ${{ matrix.python-version }}
|
|
46
|
+
- run: uv run pytest --cov=promptdrift --cov-report=term-missing
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
.python-version
|
|
9
|
+
|
|
10
|
+
# Tooling caches
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.ruff_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
coverage.xml
|
|
15
|
+
.mypy_cache/
|
|
16
|
+
|
|
17
|
+
# promptdrift runtime artifacts — baselines are committed, these are not
|
|
18
|
+
.promptest/cache.db*
|
|
19
|
+
.promptest/runs/
|
|
20
|
+
|
|
21
|
+
# Editors / OS
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
.DS_Store
|
|
25
|
+
Thumbs.db
|
|
26
|
+
|
|
27
|
+
# promptdrift demo scratch dir
|
|
28
|
+
promptdrift-demo/
|
|
29
|
+
|
|
30
|
+
# mkdocs build output
|
|
31
|
+
site/
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `judge` assertion: LLM-as-judge rubric scoring on a 1-5 scale. The suite-level `judge:`
|
|
12
|
+
block configures a separate (usually cheaper) grading model, its scores feed the same
|
|
13
|
+
multi-sample statistics as deterministic assertions, and unparseable judge replies fail
|
|
14
|
+
the sample rather than the gate.
|
|
15
|
+
- mkdocs documentation site and a ready-to-copy GitHub Actions workflow for consumer repos.
|
|
16
|
+
|
|
17
|
+
### Added — M0
|
|
18
|
+
|
|
19
|
+
- Core domain: `Suite`/`Case` models with readable YAML validation, `{{var}}` templating,
|
|
20
|
+
and a config fingerprint that guards baseline comparability.
|
|
21
|
+
- Verdict engine: multi-sample pass rates compared with Wilson score intervals; verdicts
|
|
22
|
+
`regressed` / `improved` / `stable` / `unstable` / `new` / `removed`; gates
|
|
23
|
+
`--fail-on regression|flaky|any-fail`.
|
|
24
|
+
- Deterministic assertions: `equals`, `contains`, `not_contains`, `regex`, `is_json`,
|
|
25
|
+
`json_schema`, `latency_under`, `completion_tokens_under`.
|
|
26
|
+
- Providers: `openai_compat` (OpenAI/GLM/DeepSeek/Qwen/Moonshot via `base_url`, retries
|
|
27
|
+
with backoff) and an offline `mock` (rules, variant cycling for flaky simulation).
|
|
28
|
+
- Response cache (sqlite, read-through) and per-run cost estimation.
|
|
29
|
+
- Baseline snapshots as committed, human-reviewable YAML.
|
|
30
|
+
- CLI: `init`, `run`, `diff`, `approve`, `show`, `cost`, `demo`, `schema`, `version`;
|
|
31
|
+
JUnit XML and markdown report output; exit codes 0 pass / 1 gate failure / 2 error.
|
|
32
|
+
- Published JSON Schema for suite files (editor completion).
|
|
33
|
+
- Offline test suite, ruff and pyright clean, CI matrix Python 3.10-3.13 on
|
|
34
|
+
Linux/macOS/Windows.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Issues and PRs are welcome. This file covers setup, how the codebase is organized, and the
|
|
4
|
+
rules that keep the tool trustworthy.
|
|
5
|
+
|
|
6
|
+
## Setup
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
git clone https://github.com/ritaprieto900/promptdrift
|
|
10
|
+
cd promptdrift
|
|
11
|
+
uv sync # installs the dev group: pytest, ruff, pyright, respx, ...
|
|
12
|
+
uv run pytest # must be green before any PR
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
CI enforces the same gates you should run locally:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv run ruff check . # lint
|
|
19
|
+
uv run ruff format . # formatting
|
|
20
|
+
uv run pyright # types, zero errors
|
|
21
|
+
uv run pytest --cov=promptdrift # coverage gate at 90%
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Code layout
|
|
25
|
+
|
|
26
|
+
Dependencies point downward only. The domain layer imports nothing that does I/O.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
CLI (cli/app.py) entry points, exit-code mapping
|
|
30
|
+
Services (services/) orchestration: Runner, Differ, Reporter, Cost, Loader, Judge
|
|
31
|
+
Domain (domain/) pure: suite, assertions, results, snapshot, verdict engine
|
|
32
|
+
Ports (ports.py) Provider / Cache protocols
|
|
33
|
+
Adapters (adapters/) mock, openai_compat, sqlite cache, YAML snapshot store
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Two consequences worth knowing before you change things:
|
|
37
|
+
|
|
38
|
+
- Every verdict-path test runs offline on the mock provider. Adapter HTTP behavior is
|
|
39
|
+
simulated with respx, so CI never touches a real endpoint.
|
|
40
|
+
- Report formats are pinned by golden files in `tests/golden/`. If you change a format on
|
|
41
|
+
purpose, regenerate with `PROMPTDRIFT_REGEN_GOLDEN=1 uv run pytest tests/golden -q`.
|
|
42
|
+
|
|
43
|
+
The JSON Schema in `schema/` is generated from the pydantic models. After touching any
|
|
44
|
+
Suite/Case/provider/assertion model, run `uv run python scripts/gen_schema.py`;
|
|
45
|
+
`tests/test_schema_sync.py` fails if you forget.
|
|
46
|
+
|
|
47
|
+
## Design rules
|
|
48
|
+
|
|
49
|
+
These are product decisions, and PRs that weaken them need to argue why in the description.
|
|
50
|
+
|
|
51
|
+
1. Noise alone can never fail the default gate. A regression verdict requires Wilson
|
|
52
|
+
intervals to separate, or an all-pass to all-fail flip.
|
|
53
|
+
2. Prompt content changes are measured, never treated as staleness. Only model, sampling
|
|
54
|
+
params, sample count, and judge model feed the config fingerprint.
|
|
55
|
+
3. Exit codes are a contract: 0 pass, 1 gate or assertion failure, 2 config or runtime error.
|
|
56
|
+
4. The demo must work with zero API keys and zero network.
|
|
57
|
+
5. Baselines are committed, human-reviewable YAML. No binary or opaque state.
|
|
58
|
+
|
|
59
|
+
## Submitting
|
|
60
|
+
|
|
61
|
+
Use Conventional Commits (`feat:`, `fix:`, `docs:`, `test:`, `refactor:`), one logical
|
|
62
|
+
change per PR, tests included for behavior changes. Good first contributions are usually
|
|
63
|
+
the smaller roadmap items in the README; ask in an issue before picking up anything that
|
|
64
|
+
touches the verdict engine.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of whether to use or redistribute the Work and any
|
|
151
|
+
output generated pursuant to this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: promptdrift-py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Snapshot-diff-first prompt regression testing with flake-aware verdicts and CI gating. Know what your prompt change actually did.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ritaprieto900/promptdrift
|
|
6
|
+
Project-URL: Issues, https://github.com/ritaprieto900/promptdrift/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/ritaprieto900/promptdrift/blob/main/CHANGELOG.md
|
|
8
|
+
Author: promptdrift contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,ci,eval,llm,prompt,regression,snapshot,testing
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: httpx>=0.27
|
|
26
|
+
Requires-Dist: jsonschema>=4.21
|
|
27
|
+
Requires-Dist: pydantic<3,>=2.7
|
|
28
|
+
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Requires-Dist: rich>=13.7
|
|
30
|
+
Requires-Dist: typer>=0.12
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# promptdrift
|
|
34
|
+
|
|
35
|
+
**Know what your prompt change actually did.**
|
|
36
|
+
|
|
37
|
+
Prompt regression testing with CI gating. Snapshot-diff first, flake-aware by design, Python native.
|
|
38
|
+
|
|
39
|
+
[](https://github.com/ritaprieto900/promptdrift/actions/workflows/ci.yml)
|
|
40
|
+
[](https://pypi.org/project/promptdrift/)
|
|
41
|
+
[](LICENSE)
|
|
42
|
+
[](https://github.com/astral-sh/ruff)
|
|
43
|
+
|
|
44
|
+
[中文文档](README.zh-CN.md)
|
|
45
|
+
|
|
46
|
+
Teams that ship LLM features edit prompts constantly, and every edit can quietly break
|
|
47
|
+
behavior that used to work. promptdrift catches that: it re-runs the same cases against your
|
|
48
|
+
prompt, compares pass rates against a baseline snapshot you commit to git, and fails CI when
|
|
49
|
+
behavior got statistically worse. Noise never trips the gate.
|
|
50
|
+
|
|
51
|
+
## Quick tour, no API key needed
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pipx install promptdrift
|
|
55
|
+
promptdrift demo
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The demo runs a complete loop offline on a scripted mock provider:
|
|
59
|
+
|
|
60
|
+
1. `run` executes a suite (3 samples per case)
|
|
61
|
+
2. `approve` records the behavior as the baseline
|
|
62
|
+
3. the mock answer gets "improved" and loses its structured steps
|
|
63
|
+
4. `diff` catches the drift and exits 1, the way CI would
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
step 4/4 — diff: catch the drift
|
|
67
|
+
┌──────────────┬─────────────────────┬────────┬───────┬────────────────┐
|
|
68
|
+
│ case │ assertion │ before │ after │ verdict │
|
|
69
|
+
├──────────────┼─────────────────────┼────────┼───────┼────────────────┤
|
|
70
|
+
│ refund-steps │ contains-申请退款 │ 3/3 │ 0/3 │ 🔴 regressed │
|
|
71
|
+
│ │ regex-3-5-个工作日 │ 3/3 │ 0/3 │ 🔴 regressed │
|
|
72
|
+
│ invoice-json │ is_json-yes │ 3/3 │ 3/3 │ ✅ stable │
|
|
73
|
+
└──────────────┴─────────────────────┴────────┴───────┴────────────────┘
|
|
74
|
+
❌ gate FAILED — 1 regressed case(s)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Why plain assertions aren't enough
|
|
78
|
+
|
|
79
|
+
LLM output is non-deterministic. A CI check like "output must contain X" fails randomly,
|
|
80
|
+
gets retried, and eventually gets disabled. The verdict engine handles the noise instead:
|
|
81
|
+
|
|
82
|
+
| Verdict | Meaning | Gate behavior |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| 🔴 `regressed` | pass rate fell beyond sampling noise (Wilson score intervals separate) | fails `regression` (default) |
|
|
85
|
+
| ⚠️ `unstable` | samples disagree where the baseline was deterministic | fails only `flaky` |
|
|
86
|
+
| 🟢 `improved` | pass rate rose beyond noise | never fails |
|
|
87
|
+
| ✅ `stable` | within noise | passes |
|
|
88
|
+
| 🆕 `new` / ➖ `removed` | case or assertion added or removed since the baseline | fails `any-fail` when imperfect |
|
|
89
|
+
|
|
90
|
+
Concretely: at `samples: 3`, a 3/3 → 2/3 drop is ⚠️ unstable, a warning. At `samples: 10`,
|
|
91
|
+
10/10 → 3/10 is 🔴 regressed. Raise the sample count to sharpen the statistics; run
|
|
92
|
+
`promptdrift cost` first to see what that costs.
|
|
93
|
+
|
|
94
|
+
## How it fits together
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
promptest.yaml ──► Runner ──► Run ──► Differ ◄── Snapshot (.promptest/baselines/*.snap.yaml)
|
|
98
|
+
│ ▲
|
|
99
|
+
└── provider ──► sqlite cache
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Baselines are YAML files you commit. When a PR touches one, that diff *is* the behavior
|
|
103
|
+
change under review, the same way jest snapshots work. A config fingerprint (model, sampling
|
|
104
|
+
params, sample count, judge model) protects comparability: swap the model and the old
|
|
105
|
+
baseline goes stale instead of being silently mis-compared. Editing prompt text, vars, or
|
|
106
|
+
mock answers is never staleness; that is exactly the change the diff should measure.
|
|
107
|
+
|
|
108
|
+
One provider adapter covers every OpenAI-compatible endpoint (OpenAI, GLM, DeepSeek, Qwen,
|
|
109
|
+
Moonshot, vLLM, Ollama), configured with `base_url`.
|
|
110
|
+
|
|
111
|
+
## Suite file
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
$schema: https://raw.githubusercontent.com/ritaprieto900/promptdrift/main/schema/promptest.schema.json
|
|
115
|
+
suite: support-agent
|
|
116
|
+
provider:
|
|
117
|
+
openai_compat:
|
|
118
|
+
model: glm-4.7
|
|
119
|
+
base_url: https://open.bigmodel.cn/api/paas/v4
|
|
120
|
+
api_key_env: ZHIPUAI_API_KEY
|
|
121
|
+
pricing: {prompt_per_1m: 1.0, completion_per_1m: 8.0}
|
|
122
|
+
judge: # optional: grades `judge` assertions
|
|
123
|
+
openai_compat:
|
|
124
|
+
model: glm-4.7-flash
|
|
125
|
+
base_url: https://open.bigmodel.cn/api/paas/v4
|
|
126
|
+
api_key_env: ZHIPUAI_API_KEY
|
|
127
|
+
temperature: 0.1
|
|
128
|
+
samples: 3
|
|
129
|
+
cases:
|
|
130
|
+
- id: refund-steps
|
|
131
|
+
messages:
|
|
132
|
+
- role: user
|
|
133
|
+
content: "订单有点问题,我想申请{{topic}}"
|
|
134
|
+
vars:
|
|
135
|
+
topic: 退款
|
|
136
|
+
assertions:
|
|
137
|
+
- contains: "申请退款"
|
|
138
|
+
- regex: "3-5 个工作日"
|
|
139
|
+
- not_contains: "抱歉"
|
|
140
|
+
- latency_under: 3000
|
|
141
|
+
- judge:
|
|
142
|
+
rubric: |
|
|
143
|
+
回复是否包含明确的退款步骤(入口、操作、时限)?
|
|
144
|
+
5 = 步骤完整且语气友好;1 = 没有回答问题。
|
|
145
|
+
min_score: 4
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Deterministic assertions: `equals`, `contains`, `not_contains`, `regex`, `is_json`,
|
|
149
|
+
`json_schema`, `latency_under`, `completion_tokens_under`. The `judge` assertion sends each
|
|
150
|
+
sample to the judge model with your rubric and expects a 1-5 score; `min_score` sets the
|
|
151
|
+
pass bar. Judges are only human (well, only models), so their scores feed the same
|
|
152
|
+
multi-sample statistics as everything else: a wavering judge shows up as ⚠️ unstable, not as
|
|
153
|
+
a blocked merge.
|
|
154
|
+
|
|
155
|
+
## Commands
|
|
156
|
+
|
|
157
|
+
| Command | Purpose |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `promptdrift init` | scaffold a starter suite (mock provider, runs offline) |
|
|
160
|
+
| `promptdrift run` | execute once; exit 1 if any assertion failed |
|
|
161
|
+
| `promptdrift approve` | record current behavior as the baseline |
|
|
162
|
+
| `promptdrift diff` | run and compare against the baseline; this is the CI gate |
|
|
163
|
+
| `promptdrift show` | inspect the latest run or the baseline |
|
|
164
|
+
| `promptdrift cost` | estimate calls and cost (when pricing is configured) |
|
|
165
|
+
| `promptdrift demo` | the offline end-to-end walkthrough |
|
|
166
|
+
| `promptdrift schema` | JSON Schema for suite files (editor completion) |
|
|
167
|
+
|
|
168
|
+
`diff` options that matter in CI: `--fail-on regression|flaky|any-fail`,
|
|
169
|
+
`--require-baseline`, and `--md report.md` to write a PR-ready markdown report.
|
|
170
|
+
|
|
171
|
+
Exit codes: 0 pass, 1 gate or assertion failure, 2 config or runtime error.
|
|
172
|
+
|
|
173
|
+
```yaml
|
|
174
|
+
# GitHub Actions, minimal version (see docs/ci.md for the full one)
|
|
175
|
+
- run: uv tool install git+https://github.com/ritaprieto900/promptdrift
|
|
176
|
+
- run: promptdrift diff --require-baseline --md pr-report.md
|
|
177
|
+
env:
|
|
178
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## How it compares
|
|
182
|
+
|
|
183
|
+
| | promptdrift | promptfoo | DeepEval |
|
|
184
|
+
|---|---|---|---|
|
|
185
|
+
| Language | Python | Node/TypeScript | Python |
|
|
186
|
+
| Core primitive | baseline snapshot diff | eval runs + web viewer | pytest metrics |
|
|
187
|
+
| Non-determinism | multi-sample + interval statistics | per-run assertions | metric thresholds |
|
|
188
|
+
| Review flow | snapshot diff in the PR | open the web UI | read pytest output |
|
|
189
|
+
|
|
190
|
+
promptfoo is the broader eval platform and DeepEval is strong on metric research. This
|
|
191
|
+
project stays narrow: gate prompt changes in CI, with a verdict you can trust.
|
|
192
|
+
|
|
193
|
+
## Roadmap
|
|
194
|
+
|
|
195
|
+
- selective re-runs of changed cases only; embedding-similarity assertion
|
|
196
|
+
- composite GitHub Action + sticky PR comments once the PyPI release lands
|
|
197
|
+
- multi-suite projects, cross-model comparison mode
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
git clone https://github.com/ritaprieto900/promptdrift
|
|
203
|
+
cd promptdrift
|
|
204
|
+
uv sync
|
|
205
|
+
uv run pytest # 150+ tests, fully offline
|
|
206
|
+
uv run ruff check .
|
|
207
|
+
uv run pyright
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The whole test suite runs on the mock provider, so CI never touches a real endpoint.
|
|
211
|
+
CONTRIBUTING.md has the architecture map and the design invariants.
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
[Apache-2.0](LICENSE)
|