Agent Skillsmaziyarpanahi/openmed › gating-deid-leakage

gating-deid-leakage

GitHub

在CI中集成OpenMed去标识化模型的门控检查,确保PHI召回率不低于阈值且关键信息零泄露。通过pytest或CLI实现构建失败机制,阻止弱化隐私保护的合并。

skills/gating-deid-leakage/SKILL.md maziyarpanahi/openmed

Trigger Scenarios

CI gate fail the build regression test de-id recall threshold block the merge exit nonzero leakage check in CI

Install

npx skills add maziyarpanahi/openmed --skill gating-deid-leakage -g -y
More Options

Use without installing

npx skills use maziyarpanahi/openmed@gating-deid-leakage

指定 Agent (Claude Code)

npx skills add maziyarpanahi/openmed --skill gating-deid-leakage -a claude-code -g -y

安装 repo 全部 skill

npx skills add maziyarpanahi/openmed --all -g -y

预览 repo 内 skill

npx skills add maziyarpanahi/openmed --list

SKILL.md

Frontmatter
{
    "name": "gating-deid-leakage",
    "license": "Apache-2.0",
    "metadata": {
        "pairs": "adjacent",
        "project": "OpenMed",
        "version": "1.0",
        "category": "evaluation-quality"
    },
    "description": "Add a CI gate that fails the build when an OpenMed de-identification model's recall on a held-out PHI set drops below threshold or any critical identifier leaks. Use when the user wants a pytest test or CLI step that exits nonzero on de-id regression, wants to wire OpenMed's leakage-first release gates into GitHub Actions \/ CI, needs a recall floor plus zero-leakage assertion against a synthetic held-out set, or wants to block merges that weaken de-identification. Trigger on \"CI gate\", \"fail the build\", \"regression test\", \"de-id recall threshold\", \"block the merge\", \"exit nonzero\", or \"leakage check in CI\" for OpenMed."
}

Gating De-id Leakage in CI

Logs, baselines, and models drift. The only durable defense is a gate that runs on every change and fails closed when de-identification regresses. This skill operationalizes OpenMed's leakage-first ethos into a CI check: recall must stay above the floor and critical leakage must be exactly zero, or the build goes red.

When to use this skill

  • You want a pytest test or CLI step that exits nonzero on de-id regression.
  • You need to block PRs that drop PHI recall or introduce a leak.
  • You want OpenMed's release gates (ReleaseGate, G1a–G8) enforced in CI.
  • You maintain a synthetic held-out PHI set and want it checked automatically.

For the full gate semantics see evaluating-with-leakage-gates; this skill is about wiring it into CI so it fails the build.

Quick start — a pytest gate

# tests/eval/test_deid_leakage_gate.py
import pytest
from openmed.eval import run_suite, ReleaseGate, RELEASABLE

RECALL_FLOOR = 0.99          # direct-identifier recall floor
HELD_OUT = "eval/heldout/phi_synthetic.json"   # SYNTHETIC, committed

@pytest.fixture(scope="module")
def gate_report():
    report = run_suite(
        HELD_OUT,
        suite="golden",
        model_name="OpenMed/Privacy-PII-Detection",
        device="cpu",
        metadata={"family": "PII", "tier": "base", "policy": "hipaa_safe_harbor"},
    )
    return ReleaseGate(milestone="v1.6", policy="hipaa_safe_harbor").evaluate(report)

def test_no_critical_leakage(gate_report):
    # Hard zero: one leaked SSN/credit-card is a breach, full stop.
    assert gate_report.critical_leakage_count == 0, "critical PHI leaked"

def test_recall_floor(gate_report):
    low = {
        label: r
        for label, r in gate_report.per_label_recall.items()
        if r < RECALL_FLOOR
    }
    assert not low, f"recall below floor: {low}"

def test_releasable(gate_report):
    # The structural decision: any failed gate -> QUARANTINED -> red build.
    failed = [c.gate for c in gate_report.gate_results if not c.passed]
    assert gate_report.decision == RELEASABLE, f"quarantined; failed gates: {failed}"

pytest exits nonzero on any failure, so CI turns red automatically.

Quick start — a CLI gate

The harness ships a main() that fails closed (exit 1 on quarantine):

# Produce a candidate report, then gate it. Nonzero exit blocks the job.
python -m openmed.eval.release_gates \
  --candidate eval/out/candidate_report.json \
  --baseline-store eval/baselines/last_green.json \
  --milestone v1.6 --policy hipaa_safe_harbor \
  --output release-gate-report.json

Exit codes: 0 RELEASABLE, 1 QUARANTINED, 2 evaluation error before a report. CI should treat 1 and 2 as failures.

Wire it into GitHub Actions

# .github/workflows/deid-gate.yml
name: de-id leakage gate
on: [pull_request]
jobs:
  gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v5
      - run: uv pip install --system -e ".[hf]"
      - name: Run de-id leakage gate
        run: uv run pytest tests/eval/test_deid_leakage_gate.py -q
      # The job fails (red) automatically if pytest exits nonzero.

Workflow

  1. Curate a synthetic held-out PHI set and commit it (offsets + labels, no real patient text). Use building-gold-corpus. It must be disjoint from any calibration/training data.
  2. Pick the floor from policy. Don't hardcode a magic number you invented — align to the gate's published floors (G1A_V16_RECALL_FLOOR etc. in openmed.eval.release_gates) and the active policy profile.
  3. Run the suite → gate the report (pytest fixture above).
  4. Assert two invariants: critical_leakage_count == 0 and per-label recall ≥ floor. Optionally assert decision == RELEASABLE for the full G1a–G8 check.
  5. Make it required. Mark the job a required status check so a red gate blocks merge — a passing-but-not-required gate protects nothing.
  6. On failure, the harness CLI can open/refresh a tracking issue (--issue-on-failure) so the regression is visible, not silently retried.

Hand-off to / from OpenMed

  • From evaluating-with-leakage-gates: this skill is the CI wrapper around the same ReleaseGate.evaluate(...) call — reuse its gate semantics.
  • From building-gold-corpus: supplies the synthetic held-out fixtures the gate runs against.
  • To authoring-model-cards: a green gate's GateReport is the evidence the model card cites under "evaluation".
  • Pairs with enforcing-nophi-logging: the gate proves the model doesn't leak; the logging guard proves your runtime doesn't leak.

Edge cases & gotchas

  • Fail closed, never open. If the candidate report is missing or the eval errors, treat it as a failure. Don't || true the step.
  • A passing F1 is not a passing gate. Recall floor + zero critical leakage are the load-bearing assertions; assert them explicitly even if you also check decision.
  • Held-out must stay held-out. If the gate set leaks into calibration or training, the gate measures memorization, not generalization. Keep splits disjoint (see building-gold-corpus).
  • Pin the model and milestone. Floors change per milestone (v1.6 vs v2.0); pin both so a "passing" gate doesn't silently weaken.
  • No real PHI in CI artifacts or logs. The gate report is offsets/hashes only; don't print fixture text in CI output.
  • Baselines are inputs, not outputs of the gate. Promote last-green baselines in a separate, reviewed step — never auto-write them from the gate job.

Standards & references

Version History

  • f213557 Current 2026-07-23 00:44

Same Skill Collection

skills/building-with-openmed/SKILL.md
skills/loading-openmed-models/SKILL.md
skills/annotating-variants/SKILL.md
skills/assembling-fhir-bundles/SKILL.md
skills/auditing-deid-leakage/SKILL.md
skills/auditing-deidentification-runs/SKILL.md
skills/auditing-part11-trails/SKILL.md
skills/auditing-safe-harbor-checklist/SKILL.md
skills/auditing-subgroup-fairness/SKILL.md
skills/authoring-model-cards/SKILL.md
skills/batch-processing-clinical-text/SKILL.md
skills/benchmarking-clinical-ner/SKILL.md
skills/bridging-presidio-and-spacy/SKILL.md
skills/building-gold-corpus/SKILL.md
skills/building-patient-timelines/SKILL.md
skills/checking-hipaa-compliance/SKILL.md
skills/choosing-openmed-models/SKILL.md
skills/coding-hcc-risk-adjustment/SKILL.md
skills/coding-icd10/SKILL.md
skills/computing-ecqms/SKILL.md
skills/configuring-privacy-policies/SKILL.md
skills/defining-cohort-phenotypes/SKILL.md
skills/deidentifying-clinical-text/SKILL.md
skills/deidentifying-multilingual-text/SKILL.md
skills/deploying-openmed-mcp/SKILL.md
skills/detecting-pv-signals/SKILL.md
skills/enforcing-nophi-logging/SKILL.md
skills/etl-to-omop-cdm/SKILL.md
skills/evaluating-with-leakage-gates/SKILL.md
skills/exporting-bulk-fhir/SKILL.md
skills/exporting-to-fhir/SKILL.md
skills/extracting-clinical-entities/SKILL.md
skills/extracting-dicom-metadata/SKILL.md
skills/extracting-lab-tables/SKILL.md
skills/extracting-pii-entities/SKILL.md
skills/extracting-sdoh/SKILL.md
skills/fetching-fhir-resources/SKILL.md
skills/generating-synthea-data/SKILL.md
skills/generating-synthetic-surrogates/SKILL.md
skills/ingesting-clinical-documents/SKILL.md
skills/linking-umls-concepts/SKILL.md
skills/mapping-loinc/SKILL.md
skills/mapping-to-snomed/SKILL.md
skills/mining-pubmed-literature/SKILL.md
skills/normalizing-rxnorm/SKILL.md
skills/parsing-ccda-documents/SKILL.md
skills/parsing-hl7v2-messages/SKILL.md
skills/parsing-lab-values/SKILL.md
skills/parsing-trial-eligibility/SKILL.md

Metadata

Files
0
Version
f213557
Hash
2d4b37c2
Indexed
2026-07-23 00:44

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-30 06:56
浙ICP备14020137号-1 $Carte des visiteurs$