Metadata-Version: 2.4
Name: gatewayweave
Version: 0.1.0
Summary: Offline gate and approval record for a model, prompt, or router change.
Author: Raja Tarun
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/rajatarun/GatewayWeave
Project-URL: Source, https://github.com/rajatarun/GatewayWeave
Project-URL: Issues, https://github.com/rajatarun/GatewayWeave/issues
Keywords: llm,evaluation,offline-evaluation,regression-testing,model-deployment,prompt-engineering,mlops,llmops,ci,bedrock
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: bedrock
Requires-Dist: boto3>=1.34; extra == "bedrock"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# GatewayWeave

**Offline safety gate for model, prompt, and router changes** — replay a candidate on frozen traffic, fail on regressions, and issue a passport your runtime can enforce before load.

GatewayWeave is the policy-and-approval layer for teams that ship LLM components: platform engineers wiring deployment gates, MLOps running pre-release checks without live traffic, and integrators in the Weave family (DeviceWeave, ToolWeave) who need a record-bound allow at load time.

![Terminal recording of examples/quickstart.sh showing PASS, FAIL, and INCONCLUSIVE verdicts](https://raw.githubusercontent.com/rajatarun/GatewayWeave/main/docs/assets/quickstart-demo.gif)

The method follows Raja Tarun, [*Estimate Before You Deploy: Offline Evaluation as a Safety Gate for Changing Retrieval Routing Policies*](https://doi.org/10.5281/zenodo.22998267) (Zenodo). See [docs/design.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/design.md) and [docs/design/security-notes.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/design/security-notes.md) for scoring, routers, and trust boundaries.

## Local-first

The default path uses the **fixture** replay runner and checked-in traffic — **no cloud account, no API keys, no network**. Optional `bedrock` replay (`pip install gatewayweave[bedrock]`) calls Amazon Bedrock when you supply credentials; tests in this repo use stubs and never contact a provider.

## Install

Python 3.10+.

```bash
python3 -m pip install gatewayweave
```

Development checkout:

```bash
python3 -m pip install -e ".[dev]"
```

## Five-minute quickstart

From the repository root:

```bash
bash examples/quickstart.sh
```

This runs the full gate on synthetic fixtures: a **pass** (candidate fixes errors with no regressions), a **fail** (higher accuracy but negative flips), and **inconclusive** (noise swamps the signal). Output lands in `.gatewayweave/quickstart/` (gitignored). Expect exit code **0** and `quickstart ok` on success.

See [examples/README.md](https://github.com/rajatarun/GatewayWeave/blob/main/examples/README.md) for fixture layout and [docs/BENCHMARK.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/BENCHMARK.md) for reproducing the synthetic evaluation harness.

## Example 1 — Gate a model change (CLI)

Freeze traffic, replay incumbent and candidate, decide, issue a passport, verify at load time:

```bash
OUT=.gatewayweave/demo
mkdir -p "$OUT"
export GATEWAYWEAVE_PASSPORT_KEY=demo-key
INC=anthropic.claude-3-5-sonnet-20240620-v1:0
NEW=anthropic.claude-3-5-sonnet-20241022-v2:0

gatewayweave snapshot --traffic examples/traffic.jsonl --out "$OUT/snapshot.jsonl"
gatewayweave replay --snapshot "$OUT/snapshot.jsonl" --runner fixture \
  --fixture examples/pass_incumbent.json --version "$INC" \
  --prompt-file examples/prompt.txt --config examples/config.json --out "$OUT/old.jsonl"
gatewayweave replay --snapshot "$OUT/snapshot.jsonl" --runner fixture \
  --fixture examples/pass_candidate.json --version "$NEW" \
  --prompt-file examples/prompt.txt --config examples/config.json --out "$OUT/new.jsonl"
gatewayweave replay --snapshot "$OUT/snapshot.jsonl" --runner fixture \
  --fixture examples/pass_noise.json --version "$INC" \
  --prompt-file examples/prompt.txt --config examples/config.json --out "$OUT/noise.jsonl"
gatewayweave compare --snapshot "$OUT/snapshot.jsonl" \
  --baseline "$OUT/old.jsonl" --candidate "$OUT/new.jsonl" --noise "$OUT/noise.jsonl" \
  --judge exact --out "$OUT/comparison.json"
gatewayweave decide --comparison "$OUT/comparison.json" --out "$OUT/decision.json" --report "$OUT/decision.md"
```

Use `decide`'s exit code in CI: **0** pass, **1** fail, **2** inconclusive, **3** usage or infrastructure error.

## Example 2 — Enforce a passport when loading (Python)

```python
from gatewayweave import ComponentDescriptor, require_passport

descriptor = ComponentDescriptor(
    component_kind="model",
    component_id="demo-model",
    model_version_id="anthropic.claude-3-5-sonnet-20241022-v2:0",
    prompt=open("examples/prompt.txt", encoding="utf-8").read(),
    config={"temperature": 0},
    snapshot_path=".gatewayweave/quickstart/snapshot.jsonl",
    passport_path=".gatewayweave/quickstart/passport.json",
)
require_passport(descriptor, now="2026-10-04T00:00:00Z")
```

After a passing offline run, issue the passport with `gatewayweave passport` (see [examples/quickstart.sh](https://github.com/rajatarun/GatewayWeave/blob/main/examples/quickstart.sh)). Set `GATEWAYWEAVE_MODE=audit` to log denials without blocking; `enforce` (default) raises `PassportDenied` when the record does not match.

A runnable script: [examples/load_time_check.py](https://github.com/rajatarun/GatewayWeave/blob/main/examples/load_time_check.py).

## Example 3 — JSON-field judge on structured outputs

When traffic rows carry structured `expected` values and model outputs are JSON strings:

```bash
gatewayweave compare --snapshot "$OUT/snapshot.jsonl" \
  --baseline "$OUT/old.jsonl" --candidate "$OUT/new.jsonl" --noise "$OUT/noise.jsonl" \
  --judge json --judge-fields answer,confidence \
  --out "$OUT/comparison.json"
```

Judges are pluggable (`exact`, `json`, `rule`, `llm` stub). Custom runners and verifiers are documented in [docs/EXTENDING.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/EXTENDING.md).

## Commands

| Command | Role |
| --- | --- |
| `snapshot` | Canonicalize and hash recorded traffic |
| `replay` | Run incumbent, candidate, or noise replay |
| `compare` | Score negative flips against noise baseline |
| `decide` | Pass / fail / inconclusive plus human report |
| `passport` | Write approval record bound to inputs |
| `check` | CLI load-time verification |

Routers use `component_kind=router`, weights in `config`, and `--routed` targets — see [docs/design.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/design.md).

## Documentation

| Doc | Contents |
| --- | --- |
| [docs/design.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/design.md) | Pipeline, scoring, passport binding |
| [docs/INTEGRATIONS.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/INTEGRATIONS.md) | Ecosystem fit (MCP, Bedrock, CI, OTLP, …) |
| [docs/EXTENDING.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/EXTENDING.md) | Judges, runners, verifiers |
| [CONTRIBUTING.md](https://github.com/rajatarun/GatewayWeave/blob/main/CONTRIBUTING.md) | Dev setup and PR flow |
| [SECURITY.md](https://github.com/rajatarun/GatewayWeave/blob/main/SECURITY.md) | Vulnerability reporting |

## Tests

```bash
python3 -m pytest
```

Pull requests run the same suite plus `examples/quickstart.sh` via [.github/workflows/ci.yml](https://github.com/rajatarun/GatewayWeave/blob/main/.github/workflows/ci.yml).

## Releasing

[`.github/workflows/publish.yml`](https://github.com/rajatarun/GatewayWeave/blob/main/.github/workflows/publish.yml) publishes to PyPI with trusted publishing (OIDC). Bump `pyproject.toml` and `src/gatewayweave/__init__.py`, tag `vX.Y.Z`, and push the tag. Manual workflow dispatch targets TestPyPI.

Required CI variables, secrets, PyPI trusted-publisher setup, and optional local Bedrock env vars are listed in [docs/DEPLOY_CONFIG.md](https://github.com/rajatarun/GatewayWeave/blob/main/docs/DEPLOY_CONFIG.md). Copy [`.env.example`](https://github.com/rajatarun/GatewayWeave/blob/main/.env.example) for local development placeholders.

## License

Apache-2.0 — see [LICENSE](https://github.com/rajatarun/GatewayWeave/blob/main/LICENSE).
