Evaluating With Leakage Gates logo

Evaluating With Leakage Gates

CommunityPopular
maziyarpanahi
evaluating-with-leakage-gates

Evaluate an OpenMed de-identification or clinical NER model against the leakage-first release gates G1a through G8, which gate releases on residual PHI leakage rather than on F1. Use when the user wants to run the OpenMed eval harness on a synthetic golden set, decide whether a de-id model is RELEASABLE or QUARANTINED, enforce direct-identifier recall floors, require zero critical leakage, fit calibration thresholds, or produce a signed gate report. Trigger on "release gate", "leakage", "is this model safe to ship", "G1a", "G3", "quarantine", "recall floor", or "calibration thresholds" in an OpenMed de-id context.

Overview

Publishermaziyarpanahi
Repositoryopenmed
Skill nameevaluating-with-leakage-gates
Stars
5.3K
Forks
677
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by maziyarpanahi on GitHub. Read the source before you install it.

Installation

Install the Evaluating With Leakage Gates AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/maziyarpanahi/openmed.git /tmp/openmed
mkdir -p .claude/skills
cp -r /tmp/openmed/skills/evaluating-with-leakage-gates .claude/skills/evaluating-with-leakage-gates
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Evaluating With Leakage Gates in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Evaluating With Leakage Gates on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Evaluating With Leakage Gates is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Evaluating with Leakage Gates

OpenMed's release gates answer one question: did any PHI leak? A de-id model with a beautiful F1 can still leak a single SSN — and that one leak is a HIPAA breach. So openmed.eval gates on residual leakage and per-label recall floors, not on aggregate F1. The candidate is either RELEASABLE or QUARANTINED; there is no partial credit.

When to use this skill

  • You have a candidate de-id or PII model and need a ship / no-ship decision.
  • You want to run the benchmark harness over a synthetic golden suite.
  • You need to enforce direct-identifier recall floors and critical_leakage == 0.
  • You need calibration thresholds (thresholds.json) before the gate will pass.
  • You want a signed, reproducible gate report for governance.

This is the flagship eval skill. For a pure NER scorecard see benchmarking-clinical-ner; for CI wiring see gating-deid-leakage.

The gates (G1a–G8)

GateChecksFloor / rule
G1aDirect & quasi identifiers (PERSON, EMAIL, PHONE, SSN, ID_NUM, DATE_OF_BIRTH, ...)recall ≥ 0.990 (v1.6) / 0.995 (v2.0); strict-no-leak policies raise the floor
G1bStructured secrets (API_KEY, ACCOUNT_NUMBER, CREDIT_CARD, IBAN)recall ≥ 0.995
G2Free-text names/locations/datesrecall ≥ 0.980 (v1.6) / 0.990 (v2.0)
G3Critical leakage (SSN, CREDIT_CARD, CVV, API_KEY, PIN, IBAN, ...)count must be exactly 0
G4Quantized recall delta vs fp parentwithin INT8 / INT4 limits
G5Latency & RAM vs device tier budgetp50/p95/RAM under tier budget
G6p50/p95 latency documentedmust be present and finite
G7Baseline regressionrecall drop ≤ 0.002/label; leakage ≤ soft ceiling 0.005 and ≤ steward target; no leakage regression vs last-green
G8Span integritypredicted spans validate (no overlaps/out-of-range)

Constants live in openmed.eval.release_gates (G1A_V16_RECALL_FLOOR, G1B_RECALL_FLOOR, G7_RECALL_DROP_LIMIT, RESIDUAL_LEAKAGE_SOFT_CEILING, ...). Confirm them there rather than hardcoding — they move per milestone.

Quick start

Run a candidate benchmark over a synthetic golden suite, then gate it:

python
from openmed.eval import run_suite, ReleaseGate, RELEASABLE

# 1) Produce a candidate BenchmarkReport from a SYNTHETIC fixtures file.
#    Each fixture carries gold PHI spans; no real patient text is committed.
report = run_suite(
    "eval/golden/phi_synthetic.json",     # user-supplied synthetic fixtures
    suite="golden",
    model_name="OpenMed/Privacy-PII-Detection",
    device="cpu",
    metadata={
        "family": "PII",
        "tier": "base",
        "policy": "hipaa_safe_harbor",
        # calibration artifacts are required for mask/replace policies (see below)
        "thresholds_path": "eval/artifacts/thresholds.json",
        "calibration_report_path": "eval/artifacts/calibration_report.json",
    },
)

# 2) Gate it. The gate reads the last-green baseline store read-only and
#    returns a signed GateReport.
gate = ReleaseGate(milestone="v1.6", policy="hipaa_safe_harbor")
decision = gate.evaluate(report)

print(decision.decision)                  # "RELEASABLE" or "QUARANTINED"
for check in decision.gate_results:
    if not check.passed:
        print(check.gate, "->", check.reason, check.details)

assert decision.decision == RELEASABLE, "do not ship a quarantined model"

CLI equivalent (fails closed, exit code 1 on quarantine):

bash
python -m openmed.eval.release_gates \
  --candidate eval/out/candidate_report.json \
  --milestone v1.6 --policy hipaa_safe_harbor \
  --output release-gate-report.json

Workflow

  1. Build a synthetic golden suite. Fixtures are JSON with text and gold_spans (offsets + labels). Use building-gold-corpus to scaffold one. Committed gold must be synthetic; DUA corpora (i2b2/n2c2) are eval-only and never committed.

  2. Fit calibration thresholds for any policy that masks or replaces:

    python
    from openmed.eval import write_calibration_artifacts
    
    paths = write_calibration_artifacts(
        calibration_samples,                 # held-out score/target samples
        artifact_dir="eval/artifacts",
        model_id="OpenMed/Privacy-PII-Detection",
        suite="golden",
        target_leakage=0.0,                   # leakage-first: drive leakage to 0
    )
    # writes thresholds.json + calibration_report.json the gate looks for

    The gate's calibration_present check fails the build if these are missing for a mask/replace policy.

  3. Run the suite (run_suite / run_benchmark) to get a BenchmarkReport.

  4. Evaluate with ReleaseGate(...).evaluate(report).

  5. Read the per-gate results. Each GateCheck carries gate, passed, reason, and details (e.g. which labels fell below the recall floor).

  6. Fail closed. Treat anything other than RELEASABLE as a hard stop.

  7. Audit subgroups with fairness_report (see auditing-subgroup-fairness) so an aggregate pass doesn't hide an under-protected group.

Hand-off to / from OpenMed

  • From building-with-openmed and the de-id pipeline: you evaluate the model produced by openmed.deidentify / openmed.extract_pii.
  • To gating-deid-leakage: wrap ReleaseGate.evaluate(...) in a pytest/CLI gate so CI fails closed on regression.
  • To authoring-model-cards: feed GateReport, fairness_report, and error_report outputs into the model card's metrics and limitations sections.
  • Pairs with auditing-subgroup-fairness (fairness_report) and benchmarking-clinical-ner (error_report).

Edge cases & gotchas

  • F1 is not a gate. A model can have higher F1 and still be quarantined if it leaks one critical identifier (G3) or drops a label below its floor (G1a/G1b).
  • Calibration is mandatory for mask/replace policies. No thresholds.jsoncalibration_present fails → QUARANTINED.
  • Baselines are read, never written, by the gate. The gate compares against the last-green baseline store without mutating it (G7). Promote baselines in a separate, deliberate step.
  • Strict-no-leak policies raise the G1a floor and force the leakage target to 0. Don't assume the default floor.
  • Reports must carry identity metadata (family, tier, format, eval_set_hash, leakage_fixture_hash); manifest_coherence fails without it.
  • Reports are signed (HMAC-SHA256). Set OPENMED_RELEASE_GATE_KEY for a real signing key; GateReport.verify(key) checks the repro hash and signature.
  • No raw PHI in the report. Gate evidence is offsets, hashes, and labels — never plaintext identifiers. Keep it that way in any wrapper you write.

Standards & references

Frequently asked questions

What does the Evaluating With Leakage Gates AI skill do?

Evaluate an OpenMed de-identification or clinical NER model against the leakage-first release gates G1a through G8, which gate releases on residual PHI leakage rather than on F1. Use when the user wants to run the OpenMed eval harness on a synthetic golden set, decide whether a de-id model is RELEASABLE or QUARANTINED, enforce direct-identifier recall floors, require zero critical leakage, fit calibration thresholds, or produce a signed gate report. Trigger on "release gate", "leakage", "is this model safe to ship", "G1a", "G3", "quarantine", "recall floor", or "calibration thresholds" in a...

Why use Evaluating With Leakage Gates on TypingMind?

Because you install it once and use it with any model. Evaluating With Leakage Gates is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Evaluating With Leakage Gates in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/maziyarpanahi/openmed/tree/master/skills/evaluating-with-leakage-gates. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Evaluating With Leakage Gates?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Evaluating With Leakage Gates?

As many as you like. As long as a model supports skills, you can use Evaluating With Leakage Gates with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Evaluating With Leakage Gates AI skill free?

Yes. It is published on GitHub by maziyarpanahi under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇