Persönlich identifizierbare Informationen (PII) unkenntlich machen

PII includes names, addresses, phone numbers, email addresses, tax identification numbers, and other data that can be used (alone or with other information) to identify an individual. Most organizations have regulatory and compliance requirements around handling PII data. AI_REDACT is a fully-managed Cortex AI Function that helps you help redact PII from unstructured text data, using a large language model (LLM) hosted by Snowflake to identify PII and replace it with placeholder values.

AI_REDACT kann Ihnen dabei helfen, Text für Call-Center-Trainings, Stimmungsanalysen, versicherungsbezogene und medizinische Analysen sowie ML-Modelltraining (neben anderen Anwendungsfällen) vorzubereiten.

Tipp

Verwenden Sie AI_PARSE_DOCUMENT oder AI_TRANSCRIBE, um Dokument- oder Sprechdaten vor der Anwendung von AI_REDACT in Text umzuwandeln.

AI_REDACT

Die Funktion AI_REDACT ersetzt persönlich identifizierbare Informationen (PII) im Eingabetext durch Platzhalterwerte.

Wichtig

AI_REDACT führt die Maskierung auf bestmögliche Weise unter Verwendung von AI-Modellen aus. Überprüfen Sie stets das Ergebnis (bzw. die Ausgabe), um sicherzustellen, dass die Datenschutzrichtlinien Ihrer Organisation eingehalten werden. Informieren Sie Snowflake, wenn es AI_REDACT nicht gelingt, PII in Ihren Daten unkenntlich zu machen.

Regionale Verfügbarkeit

Siehe Regionale Verfügbarkeit.

Einschränkungen

  • Die Maskierung erfolgt anhand von AI-Modellen. Möglicherweise werden nicht alle persönlich identifizierbaren Informationen gefunden. Überprüfen Sie stets die Ausgabe, um sicherzustellen, dass die Datenschutzrichtlinien Ihrer Organisation eingehalten werden. Wenden Sie sich an den Snowflake-Support, wenn AI_REDACT bestimmte PII nicht maskieren kann.

  • Die Funktionen COUNT_TOKENS und AI_COUNT_TOKENS unterstützen AI_REDACT noch nicht.

  • Zum jetzigen Zeitpunkt funktioniert AI_REDACT am besten mit wohlgeformtem englischen Text. Die Leistung kann bei anderen Sprachen oder bei Text mit vielen Rechtschreib-, Interpunktions- oder Grammatikfehlern variieren.

  • AI_REDACT currently redacts only US PII and some UK and Canadian PII, where noted in Erkannte PII-Kategorien.

  • AI_REDACT is currently limited in the number of tokens it can input and output. Input and output together can be up to 4,096 tokens. Output is limited to 1,024 tokens. If the input text is longer, split it into smaller chunks and redact each chunk separately, perhaps using SPLIT_TEXT_RECURSIVE_CHARACTER. See Chunking example for an example of redacting text that exceeds token limits.

    Bemerkung

    Ein Token ist die kleinste Dateneinheit, die vom AI-Modell verarbeitet wird. Bei englischen Texten gilt gemäß den Branchenrichtlinien ein Token als etwa vier Zeichen oder 0,75 Wörter.

Erkannte PII-Kategorien

AI_REDACT supports redacting the following categorise of PII. The values in the Category column are the strings supported in the optional categories argument.

Kategorie

Anmerkungen

NAME

Recognizes full name, first name, middle name, and last name

EMAIL

PHONE_NUMBER

DATE_OF_BIRTH

GENDER

Recognizes male, female, and nonbinary

AGE

ADDRESS

Identifies:

  • complete postal address (US, UK, CA)

  • street address (US, UK, CA)

  • postal code (US, UK, CA)

  • city (US, UK, CA)

  • Bundesstaat (US) oder Provinz (CA)

  • county, borough, or township (US)

NATIONAL_ID

Identifies Social Security numbers (US)

PASSPORT

Identifies passport numbers (US, UK, CA)

TAX_IDENTIFIER

Identifiziert Individual Taxpayer Numbers (ITNs)

PAYMENT_CARD_DATA

Identifies complete card information, card number, expiration date, and CVV

DRIVERS_LICENSE

Supported US, UK, CA

IP_ADDRESS

Bemerkung

AI_REDACT unterstützt teilweise Übereinstimmungen für einige PII-Kategorien. So reicht beispielsweise ein Vorname allein aus, um eine Redaktion mit dem [NAME]-Platzhalter auszulösen.

Error handling

Ordinarily, AI_REDACT raises an error if it cannot process the input text. When a query redacts multiple rows, an error causes the entire query to fail. To allow processing to continue with other rows, you can set the session parameter AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR to FALSE. Errors then return NULL instead of stopping the query.

ALTER SESSION SET AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR=FALSE;
Copy

With this parameter set to FALSE, you can also pass TRUE as the final argument to AI_REDACT, which causes the return value to be an OBJECT that contains separate fields for the redacted text and any error message. One of these fields is NULL depending on whether the AI_REDACT call processed successfully.

Hinweise zu Kosten

AI_REDACT incurs costs based on the number of input and output tokens processed, as with other Cortex AI Functions. See the Snowflake Pricing Guide for details.

Beispiele

Grundlegende Beispiele

Bei folgendem Beispiel werden ein Name und eine Adresse aus dem Eingabetext maskiert.

SELECT AI_REDACT(
    input => 'My name is John Smith and I live at twenty third street, San Francisco.'
);
Copy

Ausgabe:

My name is [NAME] and I live at [ADDRESS]

The following example redacts only names and email addresses from the input text. Note that the text only contains a first name, which is recognized and redacted as [NAME]. The input text does not contain an email address, so no email placeholder appears in the output.

SELECT AI_REDACT(
    input => 'My name is John and I live at twenty third street, San Francisco.',
    categories => ['NAME', 'EMAIL']
);
Copy

Ausgabe:

My name is [NAME] and I live at twenty third street, San Francisco.

End-to-End-Beispiel

Im folgenden Beispiel werden Zeilen aus einer Tabelle verarbeitet und die maskierte Ausgabe in eine andere Tabelle eingefügt. Sie könnten ähnlich vorgehen, um die maskierten Daten in einer Spalte einer bestehenden Tabelle zu speichern.

Nach der Maskierung wird der Text an AI_SENTIMENT übergeben, um Informationen zur allgemeinen Stimmung zu extrahieren.

-- Create a table with unredacted text
CREATE OR REPLACE TABLE raw_table AS
  SELECT 'My previous manager, Washington, used to live in Kirkland. His first name was Mike.' AS my_column
  UNION ALL
  SELECT 'My name is William and I live in San Francisco. You can reach me at (415).450.0973';

-- view unredacted data
SELECT * FROM raw_table;

-- Create a redaction table
CREATE OR REPLACE TABLE redaction_table (
  value VARCHAR
);

-- Redact PII from raw_table and insert into redaction_table
INSERT INTO redaction_table
SELECT AI_REDACT(my_column) AS value FROM raw_table;

-- view redacted results
SELECT * FROM redaction_table;

-- Run AI_SENTIMENT on redacted text
SELECT
    value AS redacted_text,
    AI_SENTIMENT(value) AS summary_sentiment
FROM redaction_table;
Copy

Beispiel für die Fehlerbehandlung

Dieses Beispiel, das auf dem vorangegangenen Beispiel basiert, zeigt, wie Fehler bei der Verarbeitung mehrerer Zeilen mit AI_REDACT behandelt werden. Es legt den Sitzungsparameter AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR fest und übergibt TRUE als letztes Argument an AI_REDACT. Dies führt dazu, dass die Funktion ein OBJECT mit separaten Feldern für den redigierten Text und eine Fehlermeldung zurückgibt, von der eine NULL ist, je nachdem, ob die Funktion erfolgreich war oder fehlgeschlagen ist.

ALTER SESSION SET AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR=FALSE;

-- Create a redaction table with columns for value and error message
CREATE OR REPLACE TABLE redaction_table (
  value VARCHAR,
  error VARCHAR
);

-- Redact PII from raw_table and insert into redaction_table
-- Both the redacted text and any error message are stored
INSERT INTO redaction_table
SELECT
  result:value::STRING AS value,
  result:error::STRING AS error
  FROM (SELECT AI_REDACT(my_column, TRUE) AS result FROM raw_table);
Copy

Chunking example

Dieses Beispiel veranschaulicht, wie Sie PII in umfangreichem Text redigieren können, indem der Text in kleinere Blöcke aufgeteilt, jeder Block separat ausgeblendet wird und dann die ausgeblendeten Blöcke in der endgültigen Ausgabe wieder kombiniert werden. Dieser Ansatz funktioniert im Rahmen der Token-Beschränkungen von AI_REDACT.

CREATE OR REPLACE TABLE patients (
    patient_id INT PRIMARY KEY,
    patient_notes text
);

CREATE OR REPLACE TABLE final_temp_table AS
WITH chunked_data AS (
    -- Step 1: Split text into chunks
    SELECT
        patient_id,
        chunk.value AS chunk_text,
        chunk.index AS chunk_index
    FROM
        patients,
        LATERAL FLATTEN(
            input => SNOWFLAKE.CORTEX.SPLIT_TEXT_RECURSIVE_CHARACTER(
                patient_notes,
                'none',
                1000
            )
        ) AS chunk
    WHERE
        patient_notes IS NOT NULL
        AND LENGTH(patient_notes) > 0
),
redacted_chunks AS (
    -- Step 2: Apply AI_REDACT to each chunk
  SELECT
  patient_id,
        chunk_index,
        chunk_text,
        TO_VARIANT(results:value) AS redacted_chunk,
        TO_VARIANT(results:error) AS error_string
        from (
    SELECT
        patient_id,
        chunk_index,
        chunk_text,
        AI_REDACT(chunk_text,TRUE) AS results
    FROM
        chunked_data
)
),

-- Step 3: Concatenate redacted chunks
final AS (
SELECT
chunk_text as original,
IFF(error_string IS NOT NULL, chunk_text, redacted_chunk) AS redacted_text,
patient_id,
chunk_index
FROM
    redacted_chunks
)
SELECT * FROM final;

SELECT
  patient_id,
  LISTAGG(redacted_text, '') WITHIN GROUP (ORDER BY chunk_index) AS full_output
  FROM final_temp_table
  GROUP BY patient_id;
Copy