मुख्य सामग्री पर जाएँ
Skillpedia
सिक्योरिटी5.8k · #14693

enforcing-nophi-logging

यह क्या करती है

यह स्किल एक सुरक्षा फ़िल्टर जोड़ती है, जो लिखे या भेजे जाने से पहले लॉग, ट्रेस और एरर रिपोर्ट से प्रोटेक्टेड हेल्थ इन्फ़ॉर्मेशन हटा देता है। यह उन टीमों के लिए है जिनकी क्लिनिकल टेक्स्ट प्रोसेसिंग से मरीज़ का विवरण लॉग में लीक हो सकता है।

कब इस्तेमाल करें

  • ✓जब OpenMed सेवा अनुरोध का टेक्स्ट, मॉडल आउटपुट या एरर संदेश लॉग करती है जिनमें मरीज़ का विवरण हो सकता है।
  • ✓जब लॉग या एरर ट्रैकर डी-आइडेंटिफ़िकेशन सीमा के बाहर किसी केंद्रीय सेवा पर भेजे जाते हैं।
  • ✓जब आपको कच्चे टेक्स्ट की जगह गिनती या हैश वाले संरचित लॉग फ़ील्ड चाहिए।

Skill का लिंक

https://github.com/maziyarpanahi/openmed/blob/master/skills/enforcing-nophi-logging/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/maziyarpanahi/openmed/blob/master/skills/enforcing-nophi-logging/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“हमारी OpenMed API अनुरोध का टेक्स्ट लॉग करती है और कभी-कभी स्टैक ट्रेस एक एरर ट्रैकर को भेजती है। एक फ़िल्टर जोड़िए ताकि कोई मरीज़ का विवरण सेव न हो।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट लॉगिंग सेटअप में एक तेज़ पैटर्न फ़िल्टर और मॉडल फ़ॉलबैक जोड़ता है, ताकि रिकॉर्ड उत्सर्जित होने से पहले साफ़ हों, और जिन रिकॉर्ड की जाँच न हो सके उन्हें रोक देता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Enforcing No-PHI Logging

Logs are a top breach vector: a clinical string lands in a log line, gets shipped to a centralized log store and an error tracker, and is now PHI sitting outside the de-id boundary. OpenMed's local-first stance says no raw PHI in logs, caches, or error reports — this skill enforces it with a redaction guard that runs before any record is emitted.

When to use this skill

  • An OpenMed service logs request text, model output, or exception messages.
  • You ship logs/traces to a centralized store or error tracker (Sentry, ELK).
  • You need a logging.Filter (or OTel processor) that redacts PHI pre-emit.
  • You want structured, no-PHI log fields (offsets, hashes, counts) for debugging.

Quick start — a redacting logging.Filter

import logging
import re
import openmed

# Cheap regex pre-filter for the highest-risk structured identifiers. This runs
# on every record, so keep it fast; the model is the fallback for free-text PHI.
_FAST_PATTERNS = [
    (re.compile(r"\b\d{3}-\d{2}-\d{4}\b"), "[SSN]"),
    (re.compile(r"\b\d{16}\b"), "[CARD]"),
    (re.compile(r"\b[\w.+-]+@[\w-]+\.[\w.-]+\b"), "[EMAIL]"),
    (re.compile(r"\b(?:\+?\d[\d().\-\s]{7,}\d)\b"), "[PHONE]"),
]

class NoPHIFilter(logging.Filter):
    """Redact PHI from a log record before it is emitted. Fail closed."""

    def __init__(self, model_name: str | None = None, use_model: bool = True):
        super().__init__()
        self.model_name = model_name
        self.use_model = use_model

    def filter(self, record: logging.LogRecord) -> bool:
        try:
            message = record.getMessage()
            record.msg = self._scrub(message)
            record.args = ()                 # message already rendered & scrubbed
        except Exception:
            # Never let the logger leak on error — drop the message, keep the level.
            record.msg = "[REDACTED: scrub error]"
            record.args = ()
        return True                          # keep the (now-clean) record

    def _scrub(self, text: str) -> str:
        for pattern, tag in _FAST_PATTERNS:
            text = pattern.sub(tag, text)
        if not self.use_model:
            return text
        # Model fallback for free-text PHI (names, locations, dates). Replace by
        # offset, right-to-left, so earlier offsets stay valid.
        spans = openmed.extract_pii(text, model_name=self.model_name) \
            if self.model_name else openmed.extract_pii(text)
        for e in sorted(spans.entities, key=lambda s: s.start, reverse=True):
            text = text[:e.start] + f"[{e.label}]" + text[e.end:]
        return text

# Attach to every handler that might emit clinical text.
handler = logging.StreamHandler()
handler.addFilter(NoPHIFilter(model_name="OpenMed/Privacy-PII-Detection"))
logging.getLogger("openmed.service").addHandler(handler)

Prefer structured, no-PHI fields

Don't log the note and scrub it — log about it without the text in the first place:

logger.info(
    "deidentified note",
    extra={
        "doc_id": doc_id,                       # opaque id, not the text
        "phi_entity_count": len(result.entities),
        "phi_labels": sorted({e.label for e in result.entities}),
        "char_len": len(text),
        # offsets/hashes for debugging; never the plaintext span
        "phi_offsets": [(e.start, e.end) for e in result.entities],
    },
)

Redaction is the safety net; not logging PHI is the actual fix.

OpenTelemetry / error trackers

  • Spans: add a SpanProcessor.on_end (or attribute hook) that runs the same _scrub over string span attributes and events before export.
  • Error trackers: register a before_send hook (e.g. Sentry) that scrubs exception messages, breadcrumbs, and request bodies. Stack traces often embed the offending input — scrub the message, not just the frames.

Workflow

  1. Inventory sinks. List every place a clinical string can reach: app logs, access logs, OTel spans, error tracker, crash reports, request/response dumps.
  2. Install the regex pre-filter for structured identifiers (SSN, card, email, phone) — fast, runs on every record.
  3. Add the model fallback (openmed.extract_pii) for free-text PHI on the sinks that carry clinical narrative; skip it on hot paths where regex suffices.
  4. Switch to structured fields. Replace "log the text" with "log counts, labels, offsets, ids".
  5. Fail closed. On any scrub error,
अक्सर पूछे जाने वाले सवाल

क्या यह हर लॉग लाइन फ़िल्टर करती है?

यह हर रिकॉर्ड पर चलती है, आम पहचानकर्ताओं के लिए तेज़ पैटर्न फ़िल्टर और फ़्री-टेक्स्ट विवरण के लिए मॉडल का इस्तेमाल करते हुए।

अगर फ़िल्टर फ़ेल हो जाए तो क्या होगा?

इसे फ़ेल-क्लोज़्ड बनाया गया है, यानी असुरक्षित रिकॉर्ड उत्सर्जित करने के बजाय रोक दिए जाते हैं।

क्या यह ट्रेस और एरर रिपोर्ट कवर करती है?

हाँ। यह सामान्य लॉग के साथ OpenTelemetry स्पैन और एरर ट्रैकर भी कवर करती है।

जानकारी

लेखक का मूल विवरण

Add a logging and telemetry guard that scrubs or blocks PHI from logs, traces, and error reports around an OpenMed deployment. Use when the user wants a Python logging.Filter that redacts protected health information before records are emitted, wants to keep PHI out of OpenTelemetry spans or error trackers, needs structured no-PHI log fields, or is worried that logs and stack traces are leaking patient data. Trigger on \"scrub logs\", \"redact PHI from logs\", \"no-PHI logging\", \"logging filter\", \"telemetry redaction\", \"logs leaking patient data\", or \"OpenTelemetry redaction\" in an Op

repo: maziyarpanahi/openmed

लोकप्रियता

GitHub स्टार
5.8k
रैंकिंग में स्थान
#14693
लाइसेंस
Apache-2.0
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

annotating-variants

5.8k

आपके एजेंट को मुफ़्त सार्वजनिक एनोटेटर से जेनेटिक वेरिएंट का असर बताने, HGVS नामों को जीनोम पोज़िशन में बदलने और जनसंख्या आवृत्ति जोड़ने में मदद करती है।

डेटाएनालिसिस और स्प्रेडशीट

ask-openmed

5.8k

आपके एजेंट को क्लिनिकल टेक्स्ट अनुरोध के लिए सही OpenMed वर्कफ़्लो चुनने में मदद करती है, जहाँ मरीज़ का डेटा हो सकता है वहाँ पहले गोपनीयता जाँच से शुरू करके।

अन्यविविध

assembling-fhir-bundles

5.8k

कई FHIR स्वास्थ्य रिकॉर्ड को एक ट्रांज़ैक्शन Bundle में पैक करती है, जो EHR को भेजने के लिए तैयार हो और आंतरिक संदर्भ सही जुड़े हों।

डेटाडेटाबेस

auditing-deid-leakage

5.8k

डी-आइडेंटिफ़ाइड क्लिनिकल टेक्स्ट में बचे पहचानकर्ता जैसे SSN, कार्ड नंबर, ईमेल और तारीखें खोजती है, और कुछ बचा हो तो रिलीज़ रोक देती है।

कोडिंगसिक्योरिटी

मिलती-जुलती skills