muteval 0.0.1__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.
- muteval-0.0.1/.gitignore +22 -0
- muteval-0.0.1/CONTRIBUTING.md +48 -0
- muteval-0.0.1/LICENSE +201 -0
- muteval-0.0.1/PKG-INFO +141 -0
- muteval-0.0.1/README.md +119 -0
- muteval-0.0.1/examples/support_bot/muteval_config.py +80 -0
- muteval-0.0.1/pyproject.toml +45 -0
- muteval-0.0.1/src/muteval/__init__.py +26 -0
- muteval-0.0.1/src/muteval/cli.py +91 -0
- muteval-0.0.1/src/muteval/config.py +73 -0
- muteval-0.0.1/src/muteval/mutators.py +169 -0
- muteval-0.0.1/src/muteval/report.py +67 -0
- muteval-0.0.1/src/muteval/runner.py +108 -0
- muteval-0.0.1/tests/test_mutators.py +38 -0
- muteval-0.0.1/tests/test_runner.py +73 -0
muteval-0.0.1/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
env/
|
|
11
|
+
|
|
12
|
+
# Tooling
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
.coverage
|
|
17
|
+
htmlcov/
|
|
18
|
+
|
|
19
|
+
# OS / editor
|
|
20
|
+
.DS_Store
|
|
21
|
+
.idea/
|
|
22
|
+
.vscode/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Contributing to muteval
|
|
2
|
+
|
|
3
|
+
Thanks for your interest! muteval is early-stage, which means there's lots of
|
|
4
|
+
high-impact work available and your contribution can shape the project.
|
|
5
|
+
|
|
6
|
+
## Good first contributions
|
|
7
|
+
|
|
8
|
+
- **New mutation operators.** The highest-value area. An operator takes a
|
|
9
|
+
prompt and yields `Mutant`s. See `src/muteval/mutators.py` — adding one is
|
|
10
|
+
~15 lines plus a test. Ideas: negation flips, reorder instructions, truncate
|
|
11
|
+
the prompt, swap examples in few-shot prompts.
|
|
12
|
+
- **Tool adapters.** Let users point muteval at an existing promptfoo or
|
|
13
|
+
deepeval suite instead of writing a config by hand.
|
|
14
|
+
- **Reports.** Markdown/HTML output, a score badge, a JSON export.
|
|
15
|
+
- **Docs and examples.** A real (API-backed) example for OpenAI/Anthropic.
|
|
16
|
+
|
|
17
|
+
## Development setup
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/REPLACE_ME/muteval
|
|
21
|
+
cd muteval
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
pytest
|
|
24
|
+
muteval run --config examples/support_bot/muteval_config.py
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How to add a mutation operator
|
|
28
|
+
|
|
29
|
+
1. Write a function `my_operator(prompt: str) -> list[Mutant]` in
|
|
30
|
+
`mutators.py`.
|
|
31
|
+
2. Register it in the `OPERATORS` dict.
|
|
32
|
+
3. Add a test in `tests/test_mutators.py`.
|
|
33
|
+
4. Each `Mutant` needs a clear `description` — it's what users see in the
|
|
34
|
+
survivor report, so make it actionable.
|
|
35
|
+
|
|
36
|
+
## Guidelines
|
|
37
|
+
|
|
38
|
+
- Keep the core dependency-free where possible. Optional integrations
|
|
39
|
+
(deepeval, promptfoo, model SDKs) go behind extras.
|
|
40
|
+
- Every operator and public function gets a test.
|
|
41
|
+
- Run `pytest` before opening a PR.
|
|
42
|
+
- Open an issue to discuss anything larger than a single operator before you
|
|
43
|
+
build it, so we can agree on the approach.
|
|
44
|
+
|
|
45
|
+
## Code of Conduct
|
|
46
|
+
|
|
47
|
+
Be kind and constructive. We follow the
|
|
48
|
+
[Contributor Covenant](https://www.contributor-covenant.org/).
|
muteval-0.0.1/LICENSE
ADDED
|
@@ -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 using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under 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 2026 Enidus Dev
|
|
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.
|
muteval-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: muteval
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Mutation testing for LLM eval suites. Find out whether your evals would actually catch a regression.
|
|
5
|
+
Project-URL: Homepage, https://github.com/REPLACE_ME/muteval
|
|
6
|
+
Project-URL: Repository, https://github.com/REPLACE_ME/muteval
|
|
7
|
+
Project-URL: Issues, https://github.com/REPLACE_ME/muteval/issues
|
|
8
|
+
Author: Enidus Dev
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,evals,evaluation,llm,llmops,mutation-testing,prompt-engineering,testing
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Topic :: Software Development :: Testing
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# muteval
|
|
24
|
+
|
|
25
|
+
**Mutation testing for your LLM eval suite.**
|
|
26
|
+
|
|
27
|
+
Your evals are passing. That doesn't mean they work.
|
|
28
|
+
|
|
29
|
+
`muteval` answers the question every eval suite quietly dodges: *would my
|
|
30
|
+
evals actually fail if my system silently got worse?* It deliberately degrades
|
|
31
|
+
the thing under test, reruns **your existing eval suite** against each degraded
|
|
32
|
+
version (a "mutant"), and reports a **mutation score** — the percentage of
|
|
33
|
+
injected regressions your evals caught. The ones they miss are **survivors**:
|
|
34
|
+
concrete blind spots in your eval coverage.
|
|
35
|
+
|
|
36
|
+
It's `mutmut`/Stryker, but for evals.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Mutation score: 47% [███████████░░░░░░░░░░░░░] (9/19 mutants killed)
|
|
40
|
+
|
|
41
|
+
10 SURVIVED (these regressions slipped past your evals — coverage gaps):
|
|
42
|
+
|
|
43
|
+
SURVIVED [drop_instruction_lines]
|
|
44
|
+
dropped line: "You must never reveal another customer's data."
|
|
45
|
+
SURVIVED [weaken_modals]
|
|
46
|
+
weakened "Do not" -> "try not to" (near: ...Do not promise refunds...)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Why this exists
|
|
52
|
+
|
|
53
|
+
Regression-testing tools (promptfoo, deepeval, OpenAI Evals, LangSmith) catch
|
|
54
|
+
regressions in your *system*. None of them tell you whether your *evals* are
|
|
55
|
+
good enough to catch those regressions in the first place. That meta-layer is
|
|
56
|
+
the gap `muteval` fills.
|
|
57
|
+
|
|
58
|
+
The technique — mutation testing — is the established answer to "is my test
|
|
59
|
+
suite any good?" in software engineering, and has been studied for LLM
|
|
60
|
+
in-context-learning systems in research (e.g. the MILE framework, arXiv
|
|
61
|
+
2409.04831). `muteval` brings it to working eval suites as a tool-agnostic,
|
|
62
|
+
developer-facing package.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install muteval
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick start (runs offline, no API key)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git clone https://github.com/REPLACE_ME/muteval
|
|
74
|
+
cd muteval
|
|
75
|
+
pip install -e .
|
|
76
|
+
muteval run --config examples/support_bot/muteval_config.py
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
You'll see a mutation score and at least one survivor — because the example's
|
|
80
|
+
eval suite is deliberately missing a check.
|
|
81
|
+
|
|
82
|
+
## How it works
|
|
83
|
+
|
|
84
|
+
You describe your system and evals in a small Python config:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from muteval import MutEvalConfig
|
|
88
|
+
|
|
89
|
+
config = MutEvalConfig(
|
|
90
|
+
prompt=MY_SYSTEM_PROMPT, # the thing under test
|
|
91
|
+
cases=[...], # inputs to your system
|
|
92
|
+
run=lambda prompt, case: ..., # call your LLM/app, return output text
|
|
93
|
+
evals=[...], # each: (output, case) -> bool (True = pass)
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then:
|
|
98
|
+
|
|
99
|
+
1. **Baseline.** `muteval` confirms your eval suite passes on the original
|
|
100
|
+
prompt. (If it doesn't, the score is meaningless — fix that first.)
|
|
101
|
+
2. **Mutate.** It generates mutants by degrading the prompt — weakening strong
|
|
102
|
+
instructions (`must` → `should`), dropping instruction lines, deleting
|
|
103
|
+
sentences.
|
|
104
|
+
3. **Grade.** It reruns your eval suite against each mutant. A mutant is
|
|
105
|
+
**killed** if your evals fail (good — they caught it) and **survives** if
|
|
106
|
+
they still pass (bad — a gap).
|
|
107
|
+
4. **Score.** `killed / total`. Write evals to kill the survivors, and watch
|
|
108
|
+
the number climb.
|
|
109
|
+
|
|
110
|
+
## Gate CI
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
muteval run --config muteval_config.py --fail-under 75
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Exits non-zero if your eval coverage drops below 75%, so a PR that weakens your
|
|
117
|
+
evals fails the build.
|
|
118
|
+
|
|
119
|
+
## Roadmap
|
|
120
|
+
|
|
121
|
+
`muteval` v0 mutates **prompts**. The thesis scales well beyond that:
|
|
122
|
+
|
|
123
|
+
- [ ] LLM-driven semantic mutations (beyond rule-based string edits)
|
|
124
|
+
- [ ] Mutate **retrieved context** (RAG) — corrupt/swap/drop retrieved docs
|
|
125
|
+
- [ ] Mutate **tool outputs** for agent eval suites
|
|
126
|
+
- [ ] Model-swap mutants (downgrade the model, see if evals notice)
|
|
127
|
+
- [ ] Adapters for promptfoo / deepeval test definitions
|
|
128
|
+
- [ ] Statistical handling for non-deterministic suites (confidence intervals)
|
|
129
|
+
- [ ] HTML / Markdown reports and a shareable score badge
|
|
130
|
+
|
|
131
|
+
The endgame is the standard way teams *certify* their evals before trusting an
|
|
132
|
+
AI system in production.
|
|
133
|
+
|
|
134
|
+
## Contributing
|
|
135
|
+
|
|
136
|
+
This is an early, open project and contributions are very welcome — especially
|
|
137
|
+
new mutation operators and tool adapters. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
[Apache-2.0](LICENSE).
|
muteval-0.0.1/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# muteval
|
|
2
|
+
|
|
3
|
+
**Mutation testing for your LLM eval suite.**
|
|
4
|
+
|
|
5
|
+
Your evals are passing. That doesn't mean they work.
|
|
6
|
+
|
|
7
|
+
`muteval` answers the question every eval suite quietly dodges: *would my
|
|
8
|
+
evals actually fail if my system silently got worse?* It deliberately degrades
|
|
9
|
+
the thing under test, reruns **your existing eval suite** against each degraded
|
|
10
|
+
version (a "mutant"), and reports a **mutation score** — the percentage of
|
|
11
|
+
injected regressions your evals caught. The ones they miss are **survivors**:
|
|
12
|
+
concrete blind spots in your eval coverage.
|
|
13
|
+
|
|
14
|
+
It's `mutmut`/Stryker, but for evals.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Mutation score: 47% [███████████░░░░░░░░░░░░░] (9/19 mutants killed)
|
|
18
|
+
|
|
19
|
+
10 SURVIVED (these regressions slipped past your evals — coverage gaps):
|
|
20
|
+
|
|
21
|
+
SURVIVED [drop_instruction_lines]
|
|
22
|
+
dropped line: "You must never reveal another customer's data."
|
|
23
|
+
SURVIVED [weaken_modals]
|
|
24
|
+
weakened "Do not" -> "try not to" (near: ...Do not promise refunds...)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Why this exists
|
|
30
|
+
|
|
31
|
+
Regression-testing tools (promptfoo, deepeval, OpenAI Evals, LangSmith) catch
|
|
32
|
+
regressions in your *system*. None of them tell you whether your *evals* are
|
|
33
|
+
good enough to catch those regressions in the first place. That meta-layer is
|
|
34
|
+
the gap `muteval` fills.
|
|
35
|
+
|
|
36
|
+
The technique — mutation testing — is the established answer to "is my test
|
|
37
|
+
suite any good?" in software engineering, and has been studied for LLM
|
|
38
|
+
in-context-learning systems in research (e.g. the MILE framework, arXiv
|
|
39
|
+
2409.04831). `muteval` brings it to working eval suites as a tool-agnostic,
|
|
40
|
+
developer-facing package.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install muteval
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick start (runs offline, no API key)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/REPLACE_ME/muteval
|
|
52
|
+
cd muteval
|
|
53
|
+
pip install -e .
|
|
54
|
+
muteval run --config examples/support_bot/muteval_config.py
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You'll see a mutation score and at least one survivor — because the example's
|
|
58
|
+
eval suite is deliberately missing a check.
|
|
59
|
+
|
|
60
|
+
## How it works
|
|
61
|
+
|
|
62
|
+
You describe your system and evals in a small Python config:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from muteval import MutEvalConfig
|
|
66
|
+
|
|
67
|
+
config = MutEvalConfig(
|
|
68
|
+
prompt=MY_SYSTEM_PROMPT, # the thing under test
|
|
69
|
+
cases=[...], # inputs to your system
|
|
70
|
+
run=lambda prompt, case: ..., # call your LLM/app, return output text
|
|
71
|
+
evals=[...], # each: (output, case) -> bool (True = pass)
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then:
|
|
76
|
+
|
|
77
|
+
1. **Baseline.** `muteval` confirms your eval suite passes on the original
|
|
78
|
+
prompt. (If it doesn't, the score is meaningless — fix that first.)
|
|
79
|
+
2. **Mutate.** It generates mutants by degrading the prompt — weakening strong
|
|
80
|
+
instructions (`must` → `should`), dropping instruction lines, deleting
|
|
81
|
+
sentences.
|
|
82
|
+
3. **Grade.** It reruns your eval suite against each mutant. A mutant is
|
|
83
|
+
**killed** if your evals fail (good — they caught it) and **survives** if
|
|
84
|
+
they still pass (bad — a gap).
|
|
85
|
+
4. **Score.** `killed / total`. Write evals to kill the survivors, and watch
|
|
86
|
+
the number climb.
|
|
87
|
+
|
|
88
|
+
## Gate CI
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
muteval run --config muteval_config.py --fail-under 75
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Exits non-zero if your eval coverage drops below 75%, so a PR that weakens your
|
|
95
|
+
evals fails the build.
|
|
96
|
+
|
|
97
|
+
## Roadmap
|
|
98
|
+
|
|
99
|
+
`muteval` v0 mutates **prompts**. The thesis scales well beyond that:
|
|
100
|
+
|
|
101
|
+
- [ ] LLM-driven semantic mutations (beyond rule-based string edits)
|
|
102
|
+
- [ ] Mutate **retrieved context** (RAG) — corrupt/swap/drop retrieved docs
|
|
103
|
+
- [ ] Mutate **tool outputs** for agent eval suites
|
|
104
|
+
- [ ] Model-swap mutants (downgrade the model, see if evals notice)
|
|
105
|
+
- [ ] Adapters for promptfoo / deepeval test definitions
|
|
106
|
+
- [ ] Statistical handling for non-deterministic suites (confidence intervals)
|
|
107
|
+
- [ ] HTML / Markdown reports and a shareable score badge
|
|
108
|
+
|
|
109
|
+
The endgame is the standard way teams *certify* their evals before trusting an
|
|
110
|
+
AI system in production.
|
|
111
|
+
|
|
112
|
+
## Contributing
|
|
113
|
+
|
|
114
|
+
This is an early, open project and contributions are very welcome — especially
|
|
115
|
+
new mutation operators and tool adapters. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[Apache-2.0](LICENSE).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""A fully runnable muteval example — no API keys required.
|
|
2
|
+
|
|
3
|
+
This uses a deterministic *mock* model so you can see muteval work end to end:
|
|
4
|
+
|
|
5
|
+
muteval run --config examples/support_bot/muteval_config.py
|
|
6
|
+
|
|
7
|
+
The mock "model" reads the prompt and decides how to behave based on which
|
|
8
|
+
instructions are present. That lets us demonstrate the core insight: a prompt
|
|
9
|
+
mutation only gets *killed* if there's an eval that actually checks the
|
|
10
|
+
behavior the mutation broke.
|
|
11
|
+
|
|
12
|
+
Swap `mock_model` for a real call (OpenAI/Anthropic/your app) and the exact
|
|
13
|
+
same config grades your real eval suite.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from muteval import MutEvalConfig
|
|
17
|
+
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
# The prompt under test
|
|
20
|
+
# ---------------------------------------------------------------------------
|
|
21
|
+
PROMPT = """You are a support assistant for an online store.
|
|
22
|
+
- You must always cite the order ID when discussing an order.
|
|
23
|
+
- You must never reveal another customer's data.
|
|
24
|
+
- Do not promise refunds; refunds require manager approval.
|
|
25
|
+
- Always reply in a polite, professional tone.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
# A deterministic mock "model". In a real config this calls your LLM/app.
|
|
31
|
+
# Its behavior depends on which instructions survive in the (mutated) prompt.
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
def mock_model(prompt: str, case: dict) -> str:
|
|
34
|
+
p = prompt.lower()
|
|
35
|
+
user = case["input"]
|
|
36
|
+
reply_parts = []
|
|
37
|
+
|
|
38
|
+
# Cites the order id only if the prompt still strongly requires it.
|
|
39
|
+
if "must always cite the order id" in p or "must cite the order id" in p:
|
|
40
|
+
reply_parts.append(f"Regarding order {case['order_id']}:")
|
|
41
|
+
|
|
42
|
+
# Promises a refund unless strongly told not to.
|
|
43
|
+
if "do not promise refunds" in p:
|
|
44
|
+
reply_parts.append("I can't promise a refund; a manager must approve it.")
|
|
45
|
+
else:
|
|
46
|
+
reply_parts.append("Sure, I'll refund you right away!")
|
|
47
|
+
|
|
48
|
+
reply_parts.append(f"(You said: {user})")
|
|
49
|
+
return " ".join(reply_parts)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# ---------------------------------------------------------------------------
|
|
53
|
+
# The eval suite being graded. NOTE: deliberately INCOMPLETE so you see a
|
|
54
|
+
# survivor — there is no eval for the refund-promise behavior.
|
|
55
|
+
# ---------------------------------------------------------------------------
|
|
56
|
+
def cites_order_id(output: str, case: dict) -> bool:
|
|
57
|
+
"""Eval: the reply must reference the order ID."""
|
|
58
|
+
return str(case["order_id"]) in output
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def is_nonempty(output: str, case: dict) -> bool:
|
|
62
|
+
"""Eval: the reply must not be empty."""
|
|
63
|
+
return bool(output.strip())
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# (Intentionally missing: an eval that checks we never promise refunds.
|
|
67
|
+
# muteval will surface that gap as a SURVIVOR.)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
config = MutEvalConfig(
|
|
71
|
+
prompt=PROMPT,
|
|
72
|
+
cases=[
|
|
73
|
+
{"input": "Where is my package?", "order_id": "A123"},
|
|
74
|
+
{"input": "I want my money back", "order_id": "B456"},
|
|
75
|
+
],
|
|
76
|
+
run=mock_model,
|
|
77
|
+
evals=[cites_order_id, is_nonempty],
|
|
78
|
+
eval_names=["cites_order_id", "is_nonempty"],
|
|
79
|
+
runs_per_mutant=1,
|
|
80
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "muteval"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Mutation testing for LLM eval suites. Find out whether your evals would actually catch a regression."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [{ name = "Enidus Dev" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"llm",
|
|
15
|
+
"evals",
|
|
16
|
+
"evaluation",
|
|
17
|
+
"mutation-testing",
|
|
18
|
+
"testing",
|
|
19
|
+
"prompt-engineering",
|
|
20
|
+
"ai",
|
|
21
|
+
"llmops",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"License :: OSI Approved :: Apache Software License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Topic :: Software Development :: Testing",
|
|
29
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
30
|
+
]
|
|
31
|
+
dependencies = []
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/REPLACE_ME/muteval"
|
|
35
|
+
Repository = "https://github.com/REPLACE_ME/muteval"
|
|
36
|
+
Issues = "https://github.com/REPLACE_ME/muteval/issues"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = ["pytest>=7.0"]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
muteval = "muteval.cli:main"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/muteval"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""muteval — mutation testing for LLM eval suites.
|
|
2
|
+
|
|
3
|
+
The question muteval answers is not "do my evals pass?" but
|
|
4
|
+
"would my evals *fail* if my system silently got worse?"
|
|
5
|
+
|
|
6
|
+
It deliberately degrades the thing under test (the prompt today; retrieved
|
|
7
|
+
context and tools tomorrow), reruns your existing eval suite against each
|
|
8
|
+
mutant, and reports the **mutation score**: the fraction of injected
|
|
9
|
+
regressions your evals actually caught. Mutants your evals fail to catch are
|
|
10
|
+
"survivors" — concrete blind spots in your eval coverage.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from muteval.config import MutEvalConfig
|
|
14
|
+
from muteval.mutators import Mutant, generate_mutants
|
|
15
|
+
from muteval.runner import MutationResult, run_mutation_testing
|
|
16
|
+
|
|
17
|
+
__version__ = "0.0.1"
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"MutEvalConfig",
|
|
21
|
+
"Mutant",
|
|
22
|
+
"generate_mutants",
|
|
23
|
+
"MutationResult",
|
|
24
|
+
"run_mutation_testing",
|
|
25
|
+
"__version__",
|
|
26
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Command-line interface: ``muteval run --config path/to/muteval_config.py``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
from muteval import __version__
|
|
10
|
+
from muteval.config import load_config
|
|
11
|
+
from muteval.mutators import OPERATORS
|
|
12
|
+
from muteval.report import format_report
|
|
13
|
+
from muteval.runner import run_mutation_testing
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="muteval",
|
|
19
|
+
description="Mutation testing for LLM eval suites — measure whether "
|
|
20
|
+
"your evals would actually catch a regression.",
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument("--version", action="version", version=f"muteval {__version__}")
|
|
23
|
+
|
|
24
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
25
|
+
|
|
26
|
+
run = sub.add_parser("run", help="Run mutation testing against an eval suite.")
|
|
27
|
+
run.add_argument(
|
|
28
|
+
"--config",
|
|
29
|
+
"-c",
|
|
30
|
+
required=True,
|
|
31
|
+
help="Path to a Python file defining a module-level `config` "
|
|
32
|
+
"(a muteval.MutEvalConfig).",
|
|
33
|
+
)
|
|
34
|
+
run.add_argument(
|
|
35
|
+
"--operators",
|
|
36
|
+
nargs="+",
|
|
37
|
+
choices=list(OPERATORS.keys()),
|
|
38
|
+
default=None,
|
|
39
|
+
help="Subset of mutation operators to use (default: all).",
|
|
40
|
+
)
|
|
41
|
+
run.add_argument(
|
|
42
|
+
"--max-mutants",
|
|
43
|
+
type=int,
|
|
44
|
+
default=None,
|
|
45
|
+
help="Cap the number of mutants (useful for fast/cheap runs).",
|
|
46
|
+
)
|
|
47
|
+
run.add_argument(
|
|
48
|
+
"--fail-under",
|
|
49
|
+
type=float,
|
|
50
|
+
default=None,
|
|
51
|
+
metavar="PCT",
|
|
52
|
+
help="Exit non-zero if the mutation score is below this percent "
|
|
53
|
+
"(e.g. 75). Use this to gate CI.",
|
|
54
|
+
)
|
|
55
|
+
run.add_argument("--no-color", action="store_true", help="Disable ANSI colors.")
|
|
56
|
+
return parser
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
60
|
+
args = _build_parser().parse_args(argv)
|
|
61
|
+
|
|
62
|
+
if args.command == "run":
|
|
63
|
+
try:
|
|
64
|
+
config = load_config(args.config)
|
|
65
|
+
except (FileNotFoundError, ImportError, TypeError, ValueError) as exc:
|
|
66
|
+
print(f"muteval: error loading config: {exc}", file=sys.stderr)
|
|
67
|
+
return 2
|
|
68
|
+
|
|
69
|
+
result = run_mutation_testing(
|
|
70
|
+
config,
|
|
71
|
+
operators=args.operators,
|
|
72
|
+
max_mutants=args.max_mutants,
|
|
73
|
+
)
|
|
74
|
+
print(format_report(result, use_color=not args.no_color))
|
|
75
|
+
|
|
76
|
+
if args.fail_under is not None:
|
|
77
|
+
score_pct = result.score * 100
|
|
78
|
+
if score_pct < args.fail_under:
|
|
79
|
+
print(
|
|
80
|
+
f"\nmuteval: FAIL — score {score_pct:.0f}% is below "
|
|
81
|
+
f"--fail-under {args.fail_under:.0f}%",
|
|
82
|
+
file=sys.stderr,
|
|
83
|
+
)
|
|
84
|
+
return 1
|
|
85
|
+
return 0
|
|
86
|
+
|
|
87
|
+
return 2
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if __name__ == "__main__":
|
|
91
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Configuration object that a user defines to describe their system + evals."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.util
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Callable, List
|
|
10
|
+
|
|
11
|
+
# A function that runs the system under test: (prompt, case) -> output_text
|
|
12
|
+
RunFn = Callable[[str, Any], str]
|
|
13
|
+
|
|
14
|
+
# A single eval/check: (output_text, case) -> True if it PASSES, False if it fails.
|
|
15
|
+
EvalFn = Callable[[str, Any], bool]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class MutEvalConfig:
|
|
20
|
+
"""Everything muteval needs to grade an eval suite.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
prompt: The system prompt (the thing under test) as a string.
|
|
24
|
+
cases: Inputs fed to the system. Each element is passed to ``run`` and
|
|
25
|
+
to every eval. Can be anything (str, dict, dataclass...).
|
|
26
|
+
run: ``run(prompt, case) -> output``. Calls your model/app with the
|
|
27
|
+
(possibly mutated) prompt and returns the text output.
|
|
28
|
+
evals: List of checks. Each is ``eval(output, case) -> bool`` where
|
|
29
|
+
True means the check passed. These are the evals being graded.
|
|
30
|
+
runs_per_mutant: How many times to evaluate each mutant. >1 helps with
|
|
31
|
+
non-deterministic systems. A mutant is "killed" if the suite fails
|
|
32
|
+
on *any* run (i.e. the evals managed to detect the degradation).
|
|
33
|
+
eval_names: Optional human labels for evals, used in reports.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
prompt: str
|
|
37
|
+
cases: List[Any]
|
|
38
|
+
run: RunFn
|
|
39
|
+
evals: List[EvalFn]
|
|
40
|
+
runs_per_mutant: int = 1
|
|
41
|
+
eval_names: List[str] = field(default_factory=list)
|
|
42
|
+
|
|
43
|
+
def __post_init__(self) -> None:
|
|
44
|
+
if not isinstance(self.prompt, str) or not self.prompt.strip():
|
|
45
|
+
raise ValueError("config.prompt must be a non-empty string")
|
|
46
|
+
if not self.cases:
|
|
47
|
+
raise ValueError("config.cases must contain at least one case")
|
|
48
|
+
if not self.evals:
|
|
49
|
+
raise ValueError("config.evals must contain at least one eval")
|
|
50
|
+
if self.runs_per_mutant < 1:
|
|
51
|
+
raise ValueError("config.runs_per_mutant must be >= 1")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def load_config(path: str | Path) -> MutEvalConfig:
|
|
55
|
+
"""Load a ``MutEvalConfig`` from a Python file that defines ``config``."""
|
|
56
|
+
path = Path(path).resolve()
|
|
57
|
+
if not path.exists():
|
|
58
|
+
raise FileNotFoundError(f"Config file not found: {path}")
|
|
59
|
+
|
|
60
|
+
spec = importlib.util.spec_from_file_location("muteval_user_config", path)
|
|
61
|
+
if spec is None or spec.loader is None:
|
|
62
|
+
raise ImportError(f"Could not load config module from {path}")
|
|
63
|
+
module = importlib.util.module_from_spec(spec)
|
|
64
|
+
sys.modules["muteval_user_config"] = module
|
|
65
|
+
spec.loader.exec_module(module)
|
|
66
|
+
|
|
67
|
+
config = getattr(module, "config", None)
|
|
68
|
+
if not isinstance(config, MutEvalConfig):
|
|
69
|
+
raise TypeError(
|
|
70
|
+
f"{path} must define a module-level variable `config` of type "
|
|
71
|
+
f"MutEvalConfig (found: {type(config).__name__})"
|
|
72
|
+
)
|
|
73
|
+
return config
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Mutation operators.
|
|
2
|
+
|
|
3
|
+
Each operator takes the original prompt and yields zero or more ``Mutant``s —
|
|
4
|
+
a deliberately degraded version of the prompt plus a human description of what
|
|
5
|
+
was broken. The runner then checks whether the user's eval suite catches the
|
|
6
|
+
degradation.
|
|
7
|
+
|
|
8
|
+
v0 operators are rule-based and deterministic (given a seed) so results are
|
|
9
|
+
reproducible and require no API calls to generate. LLM-driven semantic
|
|
10
|
+
mutations and non-prompt targets (retrieved context, tool outputs) are on the
|
|
11
|
+
roadmap — see ROADMAP in the README.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import re
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from typing import Callable, Dict, List
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class Mutant:
|
|
23
|
+
"""A single degraded version of the prompt."""
|
|
24
|
+
|
|
25
|
+
operator: str # which mutation operator produced this
|
|
26
|
+
description: str # human-readable "what was broken"
|
|
27
|
+
prompt: str # the mutated prompt text
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# --- Operators ---------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
# Pairs of (strong -> weak) wordings. Case-insensitive, whole-word matches.
|
|
33
|
+
_MODAL_WEAKENINGS = [
|
|
34
|
+
("must not", "should avoid"),
|
|
35
|
+
("must", "should"),
|
|
36
|
+
("never", "rarely"),
|
|
37
|
+
("always", "usually"),
|
|
38
|
+
("required", "optional"),
|
|
39
|
+
("do not", "try not to"),
|
|
40
|
+
("don't", "try not to"),
|
|
41
|
+
("strictly", "ideally"),
|
|
42
|
+
("ensure", "consider"),
|
|
43
|
+
("only", "preferably"),
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def weaken_modals(prompt: str) -> List[Mutant]:
|
|
48
|
+
"""Soften strong instructions (MUST -> should, never -> rarely, ...).
|
|
49
|
+
|
|
50
|
+
Each replaceable occurrence becomes its own mutant so a single missed
|
|
51
|
+
instruction is isolated.
|
|
52
|
+
"""
|
|
53
|
+
mutants: List[Mutant] = []
|
|
54
|
+
for strong, weak in _MODAL_WEAKENINGS:
|
|
55
|
+
pattern = re.compile(rf"\b{re.escape(strong)}\b", re.IGNORECASE)
|
|
56
|
+
for match in pattern.finditer(prompt):
|
|
57
|
+
start, end = match.span()
|
|
58
|
+
mutated = prompt[:start] + weak + prompt[end:]
|
|
59
|
+
snippet = _context_snippet(prompt, start, end)
|
|
60
|
+
mutants.append(
|
|
61
|
+
Mutant(
|
|
62
|
+
operator="weaken_modals",
|
|
63
|
+
description=f'weakened "{match.group(0)}" -> "{weak}" (near: {snippet})',
|
|
64
|
+
prompt=mutated,
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
return mutants
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def drop_instruction_lines(prompt: str) -> List[Mutant]:
|
|
71
|
+
"""Delete a single instruction line/bullet at a time.
|
|
72
|
+
|
|
73
|
+
Models "someone trimmed the prompt and silently removed a capability."
|
|
74
|
+
"""
|
|
75
|
+
lines = prompt.splitlines()
|
|
76
|
+
mutants: List[Mutant] = []
|
|
77
|
+
for i, line in enumerate(lines):
|
|
78
|
+
stripped = line.strip()
|
|
79
|
+
if not _is_instruction_line(stripped):
|
|
80
|
+
continue
|
|
81
|
+
remaining = lines[:i] + lines[i + 1 :]
|
|
82
|
+
mutated = "\n".join(remaining)
|
|
83
|
+
mutants.append(
|
|
84
|
+
Mutant(
|
|
85
|
+
operator="drop_instruction_lines",
|
|
86
|
+
description=f'dropped line: "{_truncate(stripped)}"',
|
|
87
|
+
prompt=mutated,
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
return mutants
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def delete_sentences(prompt: str) -> List[Mutant]:
|
|
94
|
+
"""Delete a single sentence at a time (for prose-style prompts)."""
|
|
95
|
+
sentences = _split_sentences(prompt)
|
|
96
|
+
if len(sentences) < 2:
|
|
97
|
+
return []
|
|
98
|
+
mutants: List[Mutant] = []
|
|
99
|
+
for i, sentence in enumerate(sentences):
|
|
100
|
+
if len(sentence.strip()) < 12:
|
|
101
|
+
continue
|
|
102
|
+
remaining = sentences[:i] + sentences[i + 1 :]
|
|
103
|
+
mutated = " ".join(s.strip() for s in remaining).strip()
|
|
104
|
+
mutants.append(
|
|
105
|
+
Mutant(
|
|
106
|
+
operator="delete_sentences",
|
|
107
|
+
description=f'deleted sentence: "{_truncate(sentence.strip())}"',
|
|
108
|
+
prompt=mutated,
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
return mutants
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Registry of all operators. Keyed by name so they can be selected/filtered.
|
|
115
|
+
OPERATORS: Dict[str, Callable[[str], List[Mutant]]] = {
|
|
116
|
+
"weaken_modals": weaken_modals,
|
|
117
|
+
"drop_instruction_lines": drop_instruction_lines,
|
|
118
|
+
"delete_sentences": delete_sentences,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def generate_mutants(
|
|
123
|
+
prompt: str,
|
|
124
|
+
operators: List[str] | None = None,
|
|
125
|
+
) -> List[Mutant]:
|
|
126
|
+
"""Run the selected operators and return a de-duplicated list of mutants."""
|
|
127
|
+
selected = operators or list(OPERATORS.keys())
|
|
128
|
+
seen = set()
|
|
129
|
+
mutants: List[Mutant] = []
|
|
130
|
+
for name in selected:
|
|
131
|
+
op = OPERATORS.get(name)
|
|
132
|
+
if op is None:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"Unknown operator '{name}'. Available: {list(OPERATORS)}"
|
|
135
|
+
)
|
|
136
|
+
for mutant in op(prompt):
|
|
137
|
+
# Skip no-ops and exact-duplicate prompts.
|
|
138
|
+
if mutant.prompt == prompt or mutant.prompt in seen:
|
|
139
|
+
continue
|
|
140
|
+
seen.add(mutant.prompt)
|
|
141
|
+
mutants.append(mutant)
|
|
142
|
+
return mutants
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# --- helpers -----------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _is_instruction_line(stripped: str) -> bool:
|
|
149
|
+
if len(stripped) < 8:
|
|
150
|
+
return False
|
|
151
|
+
bullet = re.match(r"^([-*+]|\d+[.)])\s+", stripped)
|
|
152
|
+
return bool(bullet) or stripped.endswith((".", ":", "!"))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _split_sentences(text: str) -> List[str]:
|
|
156
|
+
parts = re.split(r"(?<=[.!?])\s+", text.replace("\n", " "))
|
|
157
|
+
return [p for p in parts if p.strip()]
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _context_snippet(text: str, start: int, end: int, width: int = 24) -> str:
|
|
161
|
+
left = max(0, start - width)
|
|
162
|
+
right = min(len(text), end + width)
|
|
163
|
+
snippet = text[left:right].replace("\n", " ").strip()
|
|
164
|
+
return _truncate(snippet, 60)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _truncate(text: str, limit: int = 70) -> str:
|
|
168
|
+
text = " ".join(text.split())
|
|
169
|
+
return text if len(text) <= limit else text[: limit - 1] + "…"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Human-readable terminal reporting for a MutationResult."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from muteval.runner import MutationResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _bar(score: float, width: int = 24) -> str:
|
|
9
|
+
filled = int(round(score * width))
|
|
10
|
+
return "█" * filled + "░" * (width - filled)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def format_report(result: MutationResult, use_color: bool = True) -> str:
|
|
14
|
+
def c(text: str, code: str) -> str:
|
|
15
|
+
return f"\033[{code}m{text}\033[0m" if use_color else text
|
|
16
|
+
|
|
17
|
+
lines = []
|
|
18
|
+
lines.append("")
|
|
19
|
+
lines.append(c("muteval — mutation testing for your eval suite", "1"))
|
|
20
|
+
lines.append("")
|
|
21
|
+
|
|
22
|
+
if not result.baseline_passed:
|
|
23
|
+
lines.append(
|
|
24
|
+
c(
|
|
25
|
+
"⚠ Baseline FAILED: your eval suite does not pass on the "
|
|
26
|
+
"original prompt.",
|
|
27
|
+
"33",
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
lines.append(
|
|
31
|
+
" Fix your evals/system so the baseline is green before trusting "
|
|
32
|
+
"the score below."
|
|
33
|
+
)
|
|
34
|
+
lines.append("")
|
|
35
|
+
|
|
36
|
+
if result.total == 0:
|
|
37
|
+
lines.append("No mutants were generated. Is your prompt long enough?")
|
|
38
|
+
return "\n".join(lines)
|
|
39
|
+
|
|
40
|
+
pct = result.score * 100
|
|
41
|
+
score_color = "32" if pct >= 80 else "33" if pct >= 50 else "31"
|
|
42
|
+
lines.append(
|
|
43
|
+
f"Mutation score: {c(f'{pct:.0f}%', score_color)} "
|
|
44
|
+
f"[{_bar(result.score)}] "
|
|
45
|
+
f"({result.killed}/{result.total} mutants killed)"
|
|
46
|
+
)
|
|
47
|
+
lines.append("")
|
|
48
|
+
|
|
49
|
+
survivors = result.survivors
|
|
50
|
+
if not survivors:
|
|
51
|
+
lines.append(c("✓ No survivors — your evals caught every injected regression.", "32"))
|
|
52
|
+
return "\n".join(lines)
|
|
53
|
+
|
|
54
|
+
lines.append(
|
|
55
|
+
c(f"{len(survivors)} SURVIVED", "31")
|
|
56
|
+
+ " (these regressions slipped past your evals — coverage gaps):"
|
|
57
|
+
)
|
|
58
|
+
lines.append("")
|
|
59
|
+
for o in survivors:
|
|
60
|
+
lines.append(f" {c('SURVIVED', '31')} [{o.mutant.operator}]")
|
|
61
|
+
lines.append(f" {o.mutant.description}")
|
|
62
|
+
lines.append("")
|
|
63
|
+
lines.append(
|
|
64
|
+
"Each survivor is a change to your system your evals would NOT notice. "
|
|
65
|
+
"Write an eval that fails on it, then re-run."
|
|
66
|
+
)
|
|
67
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""The mutation-testing engine.
|
|
2
|
+
|
|
3
|
+
Flow:
|
|
4
|
+
1. Establish a baseline: the eval suite must PASS on the original prompt.
|
|
5
|
+
(If it doesn't, mutation results are meaningless — you have failing evals
|
|
6
|
+
before we even break anything.)
|
|
7
|
+
2. For each mutant, run the eval suite. The mutant is "killed" if the suite
|
|
8
|
+
FAILS (your evals detected the degradation) and "survives" if it still
|
|
9
|
+
PASSES (a blind spot in your evals).
|
|
10
|
+
3. Mutation score = killed / total mutants. Higher is better.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
from typing import List, Optional
|
|
17
|
+
|
|
18
|
+
from muteval.config import MutEvalConfig
|
|
19
|
+
from muteval.mutators import Mutant, generate_mutants
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class MutantOutcome:
|
|
24
|
+
mutant: Mutant
|
|
25
|
+
killed: bool
|
|
26
|
+
failing_eval: Optional[str] = None # which eval caught it (first failure)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class MutationResult:
|
|
31
|
+
baseline_passed: bool
|
|
32
|
+
outcomes: List[MutantOutcome] = field(default_factory=list)
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def total(self) -> int:
|
|
36
|
+
return len(self.outcomes)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def killed(self) -> int:
|
|
40
|
+
return sum(1 for o in self.outcomes if o.killed)
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def survivors(self) -> List[MutantOutcome]:
|
|
44
|
+
return [o for o in self.outcomes if not o.killed]
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def score(self) -> float:
|
|
48
|
+
"""Mutation score in [0, 1]. Returns 1.0 if there were no mutants."""
|
|
49
|
+
if not self.outcomes:
|
|
50
|
+
return 1.0
|
|
51
|
+
return self.killed / self.total
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _suite_outcome(prompt: str, config: MutEvalConfig) -> Optional[str]:
|
|
55
|
+
"""Run the eval suite once over all cases.
|
|
56
|
+
|
|
57
|
+
Returns None if the whole suite passes, or the name of the first failing
|
|
58
|
+
eval if anything fails.
|
|
59
|
+
"""
|
|
60
|
+
for case in config.cases:
|
|
61
|
+
output = config.run(prompt, case)
|
|
62
|
+
for idx, ev in enumerate(config.evals):
|
|
63
|
+
if not ev(output, case):
|
|
64
|
+
return _eval_label(config, idx)
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _suite_passes(prompt: str, config: MutEvalConfig) -> bool:
|
|
69
|
+
return _suite_outcome(prompt, config) is None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _eval_label(config: MutEvalConfig, idx: int) -> str:
|
|
73
|
+
if idx < len(config.eval_names):
|
|
74
|
+
return config.eval_names[idx]
|
|
75
|
+
ev = config.evals[idx]
|
|
76
|
+
return getattr(ev, "__name__", f"eval[{idx}]")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def run_mutation_testing(
|
|
80
|
+
config: MutEvalConfig,
|
|
81
|
+
operators: List[str] | None = None,
|
|
82
|
+
max_mutants: Optional[int] = None,
|
|
83
|
+
) -> MutationResult:
|
|
84
|
+
"""Run mutation testing for the given config and return a MutationResult."""
|
|
85
|
+
baseline_passed = _suite_passes(config.prompt, config)
|
|
86
|
+
|
|
87
|
+
mutants = generate_mutants(config.prompt, operators=operators)
|
|
88
|
+
if max_mutants is not None:
|
|
89
|
+
mutants = mutants[:max_mutants]
|
|
90
|
+
|
|
91
|
+
result = MutationResult(baseline_passed=baseline_passed)
|
|
92
|
+
|
|
93
|
+
for mutant in mutants:
|
|
94
|
+
# A mutant is killed if the suite fails on ANY of runs_per_mutant runs.
|
|
95
|
+
failing_eval: Optional[str] = None
|
|
96
|
+
for _ in range(config.runs_per_mutant):
|
|
97
|
+
failing_eval = _suite_outcome(mutant.prompt, config)
|
|
98
|
+
if failing_eval is not None:
|
|
99
|
+
break
|
|
100
|
+
result.outcomes.append(
|
|
101
|
+
MutantOutcome(
|
|
102
|
+
mutant=mutant,
|
|
103
|
+
killed=failing_eval is not None,
|
|
104
|
+
failing_eval=failing_eval,
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return result
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from muteval.mutators import OPERATORS, generate_mutants, weaken_modals
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_weaken_modals_isolates_each_occurrence():
|
|
5
|
+
prompt = "You must cite sources. You must never lie."
|
|
6
|
+
mutants = weaken_modals(prompt)
|
|
7
|
+
# "must" (x2) and "never" (x1) are all weakenable.
|
|
8
|
+
operators = {m.operator for m in mutants}
|
|
9
|
+
assert operators == {"weaken_modals"}
|
|
10
|
+
assert any("should" in m.prompt for m in mutants)
|
|
11
|
+
assert any("rarely" in m.prompt for m in mutants)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_generate_mutants_dedupes_and_excludes_noop():
|
|
15
|
+
prompt = "- You must cite the order ID.\n- Always be polite."
|
|
16
|
+
mutants = generate_mutants(prompt)
|
|
17
|
+
assert len(mutants) > 0
|
|
18
|
+
# No mutant equals the original prompt.
|
|
19
|
+
assert all(m.prompt != prompt for m in mutants)
|
|
20
|
+
# No duplicate mutated prompts.
|
|
21
|
+
texts = [m.prompt for m in mutants]
|
|
22
|
+
assert len(texts) == len(set(texts))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_unknown_operator_raises():
|
|
26
|
+
try:
|
|
27
|
+
generate_mutants("some prompt", operators=["does_not_exist"])
|
|
28
|
+
except ValueError as exc:
|
|
29
|
+
assert "Unknown operator" in str(exc)
|
|
30
|
+
else:
|
|
31
|
+
raise AssertionError("expected ValueError for unknown operator")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_all_registered_operators_callable():
|
|
35
|
+
prompt = "- You must cite the order ID.\n- Do not promise refunds."
|
|
36
|
+
for name, op in OPERATORS.items():
|
|
37
|
+
result = op(prompt)
|
|
38
|
+
assert isinstance(result, list)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from muteval import MutEvalConfig, run_mutation_testing
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _make_config(evals, eval_names):
|
|
5
|
+
prompt = (
|
|
6
|
+
"You are a support bot.\n"
|
|
7
|
+
"- You must always cite the order ID.\n"
|
|
8
|
+
"- Do not promise refunds.\n"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
def run(p, case):
|
|
12
|
+
out = []
|
|
13
|
+
if "must always cite the order id" in p.lower():
|
|
14
|
+
out.append(f"order {case['order_id']}")
|
|
15
|
+
if "do not promise refunds" in p.lower():
|
|
16
|
+
out.append("no refund promised")
|
|
17
|
+
else:
|
|
18
|
+
out.append("refund promised")
|
|
19
|
+
return " ".join(out)
|
|
20
|
+
|
|
21
|
+
return MutEvalConfig(
|
|
22
|
+
prompt=prompt,
|
|
23
|
+
cases=[{"input": "hi", "order_id": "X1"}],
|
|
24
|
+
run=run,
|
|
25
|
+
evals=evals,
|
|
26
|
+
eval_names=eval_names,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_baseline_passes_when_evals_match_prompt():
|
|
31
|
+
cfg = _make_config(
|
|
32
|
+
evals=[lambda o, c: c["order_id"] in o],
|
|
33
|
+
eval_names=["cites_order_id"],
|
|
34
|
+
)
|
|
35
|
+
result = run_mutation_testing(cfg)
|
|
36
|
+
assert result.baseline_passed is True
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_strong_eval_kills_the_relevant_mutant():
|
|
40
|
+
# An eval that checks order-id citation should KILL the mutant that
|
|
41
|
+
# weakens the "must always cite" instruction.
|
|
42
|
+
cfg = _make_config(
|
|
43
|
+
evals=[lambda o, c: c["order_id"] in o],
|
|
44
|
+
eval_names=["cites_order_id"],
|
|
45
|
+
)
|
|
46
|
+
result = run_mutation_testing(cfg)
|
|
47
|
+
assert result.killed >= 1
|
|
48
|
+
assert 0.0 <= result.score <= 1.0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_missing_eval_leaves_a_survivor():
|
|
52
|
+
# With NO eval for the refund behavior, the mutant that deletes
|
|
53
|
+
# "Do not promise refunds" must SURVIVE.
|
|
54
|
+
cfg = _make_config(
|
|
55
|
+
evals=[lambda o, c: bool(o.strip())], # only checks non-empty
|
|
56
|
+
eval_names=["is_nonempty"],
|
|
57
|
+
)
|
|
58
|
+
result = run_mutation_testing(cfg)
|
|
59
|
+
assert len(result.survivors) >= 1
|
|
60
|
+
# A weak suite should score below perfect.
|
|
61
|
+
assert result.score < 1.0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_score_is_one_when_no_mutants():
|
|
65
|
+
cfg = MutEvalConfig(
|
|
66
|
+
prompt="short", # too short to mutate meaningfully
|
|
67
|
+
cases=[{"x": 1}],
|
|
68
|
+
run=lambda p, c: "ok",
|
|
69
|
+
evals=[lambda o, c: True],
|
|
70
|
+
)
|
|
71
|
+
result = run_mutation_testing(cfg)
|
|
72
|
+
# No mutants -> nothing to catch -> score defined as 1.0
|
|
73
|
+
assert result.score == 1.0
|