Skip to main content

SwapGate

The open-source model-swap eval gate: production traces become evals, and a candidate model must pass before you swap. Move from rented frontier APIs to self-hosted open-weight models (Sarvam, Llama, Qwen) without silent regressions.

traces → capture → build-evals → compare → swap receipt (pass/fail)
  • Capture real traffic: LiteLLM callbacks, OpenTelemetry GenAI spans, sec-MCP logs.
  • Redact before storage: deterministic pseudonymisation, DPDP-aware profiles.
  • Build evals by clustering traces; a human approves rubrics before they run.
  • Compare baseline vs candidate with deterministic, LLM, or typed-decision judges.
  • Ship the receipt: signed JSON verdict + Markdown/HTML report; the GitHub Action fails the PR on regression.

Zero-dependency Python core (stdlib only). Apache-2.0.

Install

pip install swapgate
# or from source:
git clone https://github.com/nitishagar/swapgate.git
cd swapgate
uv venv && uv pip install -e '.[dev]'

60-second demo (fully offline)

swapgate capture --from litellm --in fixtures/traces-litellm.jsonl --out /tmp/events.jsonl
swapgate build-evals --in /tmp/events.jsonl --out /tmp/suite.json --name demo
swapgate build-evals --in /tmp/events.jsonl --out /tmp/suite.json --approve
swapgate compare --suite /tmp/suite.json --baseline mock:parity --candidate mock:regress \
  --fail-under 0.5 --out /tmp/receipt.json --report /tmp/report.md
# exit 2: candidate regressed. Inspect /tmp/report.md, then:
swapgate verify --receipt /tmp/receipt.json --key /tmp/demo.key  # if signed with --key

CLI

Command Purpose
capture --from litellm|otel|secmcp --in --out [--redact profile] Ingest raw traces
build-evals --in --out [--name] [--clusters] [--india-pack] [--approve] Cluster → suite (approval-gated)
compare --suite --baseline --candidate [--judge] [--fail-under] [--max-regression] [--out] [--report] [--key/--sign] Replay + gate (exit 2 on regression)
report --receipt --format md|html [--out] Render a receipt
verify --receipt --key Verify a signed receipt
serve-mcp stdio MCP server (compare_models, list_evals)

Providers: mock:parity|regress|seed-N (offline), openai-compat:<base-url>|<model> (live, key from SWAPGATE_API_KEY). Exit codes: 0 pass, 2 gate fail, 1 error.

GitHub Action

- uses: nitishagar/swapgate@v0
  with:
    suite: evals/suite.json
    baseline: openai-compat:https://api.example.com/v1|baseline-model
    candidate: openai-compat:https://api.example.com/v1|candidate-model
    fail-under: '0.95'
    max-regression: '0.02'

Gates (automated tests)

Every gate runs offline in CI (pytest, no keys/network):

  • G0 unit — ingest ×3, redact, cluster, evals, judges ×3, compare, receipt, report, India pack
  • G1 CLI end-to-end — capture→build-evals→compare on fixtures, golden receipt
  • G2 regression behaviour — injected regression fails (exit 2), parity passes (exit 0)
  • G3 judge reliability — deterministic fixtures + recorded LLM-judge fixtures
  • G4 receipt integrity — genuine verifies, tampered/unsigned/wrong-key rejected
  • G5 site + packaging — docs links, sdist install, Action metadata, TS SDK tests
  • L live (opt-in) — SWAPGATE_LIVE=1 pytest -m live vs a real endpoint
pytest            # G0–G5 offline

India pack (--india-pack)

Hinglish eval templates, DPDP redaction profiles (india, dpdp-strict: PAN, Aadhaar, UPI, +91 phones), 30-day retention guidance, and a FREE-AI control annex for fintech audit packets. See docs/india-pack.html.

Layout

src/swapgate/ core · tests/ gates · fixtures/ sample traces · action/ GitHub Action · packages/swapgate-js/ thin TS SDK · docs/ GitHub Pages site · examples/sarvam-swap/ mock swap demo.

Limits

  • Heuristic rubrics need human review (the approval gate enforces this); LLM rubric synthesis is live-only and not in v0.1.
  • Mock providers prove gate mechanics, not model quality.
  • HMAC receipts are tamper-evident, not third-party-verifiable (Ed25519 is the documented upgrade path).

License

Apache-2.0. See LICENSE.

Metadata

Release files for swapgate 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swapgate 0.2.0
File Size Uploaded Provenance Actions
swapgate-0.2.0.tar.gz 129.8 kB Without provenance Details for swapgate-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swapgate 0.2.0
File Interpreter ABI Platform Actions
swapgate-0.2.0-py3-none-any.whl Python 3 none any Details for swapgate-0.2.0-py3-none-any.whl

Total release size: 179.5 kB

Release files / swapgate-0.2.0.tar.gz

Download URL swapgate-0.2.0.tar.gz
Size 129.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5077e4f4e3924e034964a62079386890fd5599014cb643317a565c3722f6223
BLAKE2b-256 checksum
How to use checksums
cd843adc01ed84f007c22ef3ab4196b947185adfa59932f0d6e2cc7087d20b84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / swapgate-0.2.0-py3-none-any.whl

Download URL swapgate-0.2.0-py3-none-any.whl
Size 49.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2fd7ff86297db8b03c67028b4a9c19acf9ae9064fad07dacdb061993a8eaceb
BLAKE2b-256 checksum
How to use checksums
f9cecd4b5485618800c8a68375e679831e31f909673310c2918ccf4ec5075ade
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for swapgate 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page