This release is a pre-release and may not be stable for production use.
gepa-guard
gepa-guard is a non-regression acceptance criterion for GEPA reflective prompt optimization. It rejects a candidate prompt that fails a protected check that its parent or the seed passed.
GEPA improves a prompt against one scalar score. A candidate prompt with a higher score can lose a rare behavior that must not break, such as the escalation of a crisis message. GEPA accepts that candidate because its minibatch score went up. gepa-guard keeps the GEPA objective and wraps its acceptance criterion with protected checks.
Why it matters
In health AI, one wrong answer on a rare case can outweigh a small gain on average. A triage prompt that stops escalating a crisis message is not an improvement, even when its score goes up. A prompt optimizer must not trade that case for a higher average.
gepa-guard was developed at League Labs and funded by League Inc. It comes from the component that gates prompt revisions for an internal health agent at League. gepa-guard turns a silent regression into a rejected proposal with a named cause and a record for audit, before a revised prompt reaches deployment.
Features
With gepa-guard you can:
- Reject a candidate that loses a protected pass of its parent in the minibatch.
- Check candidates against a fixed set of protected rows (the floor).
- Reject a proposal whose protected scores cannot be read, instead of guessing.
- Read the failed check and row in the gepa log for each protected rejection.
- Count every decision in a run record that matches the guarded proposal outcomes in the paper.
- Keep your base criterion, for example
StrictImprovementAcceptance.
Installation
gepa-guard is available via pip:
pip install gepa-guard
gepa-guard supports Python 3.11 to 3.15 and gepa 0.1.4 or later.
Basic usage
Your gepa adapter must return objective_scores in its EvaluationBatch.
This is a list with one mapping per row. Give each protected check a score of
1.0 (pass) or 0.0 (fail) on the rows that test it. Rows that do not test a
check can leave it out.
The following example protects an emergency check in the minibatch.
seed, trainset, valset, adapter and reflection_lm are your usual
gepa inputs:
import gepa
from gepa.strategies.acceptance import StrictImprovementAcceptance
from gepa_guard import GuardedAcceptance
guard = GuardedAcceptance(StrictImprovementAcceptance(), protected=["emergency"])
result = gepa.optimize(
seed_candidate=seed,
trainset=trainset,
valset=valset,
adapter=adapter,
reflection_lm=reflection_lm,
acceptance_criterion=guard,
max_metric_calls=500,
)
print(guard.stats.as_dict())
gepa logs the reason for each rejection, for example:
Iteration 3: rejected: protected regression in the minibatch on emergency at row 1 (data id 11)
Add a protected floor
The minibatch holds only a few rows. A floor checks each candidate that passes the minibatch check and the base criterion against a fixed set of protected rows. Measure the floor with the seed first. The seed defines which checks each row must keep.
protected_rows is a list of rows in the form your adapter takes. Do not use
rows from your test set.
from gepa.strategies.acceptance import StrictImprovementAcceptance
from gepa_guard import FloorConfig, GuardedAcceptance, ProtectedFloor
floor = ProtectedFloor.from_adapter(
adapter, protected_rows, protected=["emergency"], config=FloorConfig(batch_size=8)
)
floor.measure(seed)
guard = GuardedAcceptance(
StrictImprovementAcceptance(), protected=["emergency"], floor=floor
)
To score the floor without an adapter, use
ProtectedFloor(evaluate, rows, protected=[...]). evaluate takes a sequence
of rows and a candidate, and returns one objective mapping per row.
How it works
For each proposal, the guard runs these checks in order. The first check that fails rejects the proposal.
- Read: the minibatch objective scores of the parent and the candidate must exist and align row by row. Each protected score must be 0 or 1. If not, the proposal is unverifiable and is rejected.
- Minibatch: the candidate must keep every protected pass of its parent.
- Base: the base criterion, for example
StrictImprovementAcceptance, must accept. - Floor: the candidate must keep every protected pass of the seed on the floor rows, when a floor is given.
After a minibatch rejection, the guard still asks the base criterion. The answer does not change the decision. It only counts the rejections that override GEPA.
Requirements
- Binary protected scores. A protected score must be 0 or 1. Only 1 is a
pass. Any other value makes a minibatch proposal unverifiable. On the floor,
it raises
ValueError. - Deterministic scores. A check that passes and fails at random on the same prompt causes false rejections. Make the task model as deterministic as you can, for example with temperature 0.
- A seed that passes. The guard protects only what the parent or the seed
passed.
ProtectedFloor.measureraisesValueErrorwhen the seed passes no row of a protected check. - No merges. gepa accepts merged candidates without the acceptance
criterion. Keep
use_merge=False, the default ofgepa.optimize. Withoptimize_anything, leaveGEPAConfig.mergeunset. If the gepa state holds a merged candidate, the guard raisesUnguardedMergeErrorat its next decision. - One guard per run. The guard keeps state for one run. Calls from several threads run one at a time.
Reading the run record
guard.stats is a VetoStats. Its counts match the columns of the guarded
proposal outcomes table in the paper.
| Field | Meaning |
|---|---|
proposals, accepted |
Proposals decided and accepted |
vetoed_unverifiable |
Rejected because the protected scores could not be read |
vetoed_subsample |
Rejected for a protected regression in the minibatch |
vetoed_by_base |
Rejected by the base criterion |
vetoed_floor |
Rejected for a protected regression in the floor |
vetoed_by_guard |
vetoed_subsample plus vetoed_floor |
vetoed_subsample_base_accepted |
Minibatch rejections of proposals that the base criterion accepts. These are the counts in parentheses in the paper |
overrode_base |
vetoed_subsample_base_accepted plus vetoed_floor. This is the "Overrode GEPA" column |
checked |
Protected passes of the parent compared in the minibatch, per check |
regressed |
Protected regressions found in the minibatch or the floor, per check |
as_dict() returns every count as a plain dictionary for logs and reports.
Compatibility
- gepa 0.1.4 or later. CI tests the oldest supported and the latest release
with
gepa.optimize. optimize_anythingalso takes the guard, asEngineConfig(acceptance_criterion=guard)fromgepa.optimize_anything. Return the protected scores inside_info["scores"].- Any base criterion with a
should_accept(proposal, state)method. gepa's own criteria match theBaseCriterionprotocol.
Citation
If you use gepa-guard in your research, please cite the paper:
@inproceedings{barreto-ojeda2026demo,
title = {Demo: Blocking Silent Safety Regressions in Prompt Optimization for Health {AI}},
author = {Estefania Barreto-Ojeda and Aiden Arnold},
booktitle = {The Third Workshop on GenAI for Health: Agentic Systems, Clinical Trust, and Future Potential - Demonstration Paper Track},
year = {2026},
}
Contributing
Contributions are very welcome!
Please read the Contributing guide before you open a pull request. It describes the development setup with uv, the checks, the code style and the AI assistance policy.
To set up a development environment, fork the repository, clone your fork and run the tests:
git clone https://github.com/<your-username>/gepa-guard.git
cd gepa-guard
uv sync
uv run pytest
To report a vulnerability, please see the Security policy.
License
Source code included in this project is available in the GitHub repository https://github.com/LeagueLabs/gepa-guard under the MIT License (see LICENSE). The project is linked to a Code of Conduct.
Metadata
Release files for gepa-guard 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gepa_guard-0.1.0a1.tar.gz | 27.0 kB | With provenance | Details for gepa_guard-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gepa_guard-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for gepa_guard-0.1.0a1-py3-none-any.whl |
Total release size: 44.7 kB
Release files / gepa_guard-0.1.0a1.tar.gz
| Download URL | gepa_guard-0.1.0a1.tar.gz |
|---|---|
| Size | 27.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa8115df8eb15889c5cf4dde1ee0b94ed5674c441344e3c83039006ea197e43c
|
|
BLAKE2b-256 checksum How to use checksums |
de411134ed068d1bbc2750e1e9c3cc0f0c310a7da61b08e39c38ae991675c5d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / gepa_guard-0.1.0a1-py3-none-any.whl
| Download URL | gepa_guard-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87f9918c5b96682d1372e521a15c3f59252138deb077a27ee4d042ab0743909b
|
|
BLAKE2b-256 checksum How to use checksums |
02c516adf6892e9006191a71bc175491db82bf65be343113d1bdd87a4a63ecf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for gepa-guard 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for gepa_guard-0.1.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.