Skip to main content

enterprise_ai.dlp

Source: sdks/python/src/enterprise_ai/dlp/__init__.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model Finding​

One local DLP match.

Fields:

NameTypeRequiredDescription
typestryesKind of data found: email, iban, credit_card, fr_nir, phone, ipv4 or secret.
startintyesStart the services once installed. Default true.
endintyesEnd offset of the match in the text (exclusive).
valuestryesMatched text, in clear.

Finding.to_dict​

to_dict(reveal: bool = False) -> dict[str, Any]

The finding as a {type, start, end, value} dict, value masked unless reveal.

NameTypeDefaultRequiredDescription
revealboolFalsenoKeep the matched value in clear (default False: masked by mask_value).

Returns: dict[str, Any]. Dict {type, start, end, value}.

Class DlpClient​

/v1/dlp.

Resource

DlpClient.create_rule​

create_rule(name: str, pattern: str, action: str = 'mask', **extra: Any) -> Any

Create or update a DLP rule. Creates the rule, or replaces the rule of the same name. A rule needs an entity_type or a pattern (a valid regular expression); errors answer 400 invalid_request (unknown action, invalid pattern or classification). Needs tenant_admin or security_officer. Writes the audit event dlp.rule.upsert. Answers 201 with the rule.

Route: /v1/dlp/rules (POST).

NameTypeDefaultRequiredDescription
namestryesUnique name of the rule, 1 to 120 characters.
patternstryesRegular expression of a custom entity, at most 500 characters.
actionstr'mask'noAction on a finding: allow, detect, mask (default), tokenize or block; it overrides the mode of the request.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Create or update a DLP rule".

Raises: the typed errors of the transport (Errors).

DlpClient.inspect​

inspect(text: str, **extra: Any) -> Any

Inspect a text for sensitive data. Runs DLP on the text with the tenant rules, in mode detect unless mode says otherwise. The answer gives text, findings (type, position, score, classification, short preview, action, rule), action (strongest action applied), classification, mode, engine (builtin or presidio), blocked and count. An unknown mode answers 400. Open to any member of the tenant. Writes the audit event dlp.inspect (counts and types only).

Route: /v1/dlp/inspect (POST).

NameTypeDefaultRequiredDescription
textstryesText to inspect or redact.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Inspect a text for sensitive data".

Raises: the typed errors of the transport (Errors).

DlpClient.list_rules​

list_rules() -> Any

List the DLP rules. Lists the DLP rules of the tenant ordered by name. Open to any member of the tenant. next_cursor is always null.

Route: /v1/dlp/rules (GET).

This element takes no parameter.

Returns: Any. Decoded JSON answer of the operation "List the DLP rules".

Raises: the typed errors of the transport (Errors).

DlpClient.prescan​

prescan(text: str) -> list[dict[str, Any]]

Local regex pre-scan, values masked.

NameTypeDefaultRequiredDescription
textstryesText to scan locally before it leaves the process.

Returns: list[dict[str, Any]]. One {type, start, end, value} dict per finding, value masked by mask_value.

DlpClient.redact​

redact(text: str, mode: str = 'mask', **extra: Any) -> Any

Redact sensitive data from a text. Same as inspect, in mode mask by default: each finding is replaced by [TYPE] (for example [EMAIL]), or tokenized or blocked when a tenant rule or mode says so; a blocked text comes back empty with blocked: true. Open to any member of the tenant. Writes the audit event dlp.redact.

Route: /v1/dlp/redact (POST).

NameTypeDefaultRequiredDescription
textstryesText to inspect or redact.
modestr'mask'nodetect, mask, tokenize or block. Default: detect for inspect, mask for redact.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Redact sensitive data from a text".

Raises: ValueError, the typed errors of the transport (Errors).

Class TokenizationClient​

/v1/tokenization (policy checked and audited server side).

Resource

TokenizationClient.detokenize​

detokenize(tokens: list[str], purpose: str, **extra: Any) -> Any

Detokenize values. Returns the original values of tokens given in tokens or found in text.

Route: /v1/tokenization/detokenize (POST).

NameTypeDefaultRequiredDescription
tokenslist[str]yesTokens to resolve, tok_<type>_<hex>.
purposestryesWhy the values are needed, passed to the policy as context.purpose and written to the audit trail.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Detokenize values".

Raises: the typed errors of the transport (Errors).

TokenizationClient.tokenize​

tokenize(values: list[dict[str, str]] | None = None, text: str | None = None, **extra: Any) -> Any

Tokenize values. Replaces sensitive values by deterministic tokens tok_<type>_<hex> of the tenant (the same value always gives the same token), the values being stored encrypted in the vault. With values, returns tokens; with text, detects the entities and returns the tokenized text, findings and classification. One of the two is required (400 invalid_request). Open to any member of the tenant. Writes the audit event tokenization.tokenize (count only).

Route: /v1/tokenization/tokenize (POST).

NameTypeDefaultRequiredDescription
valueslist[dict[str, str]] | NoneNonenoValues to tokenize, each with its type.
textstr | NoneNonenoText whose detected entities are replaced by tokens.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Tokenize values".

Raises: the typed errors of the transport (Errors).

Functions​

luhn_ok​

luhn_ok(number: str) -> bool

Luhn checksum of a digit string.

NameTypeDefaultRequiredDescription
numberstryesCard number; characters other than digits are ignored.

Returns: bool. True when the number has at least 13 digits and passes the Luhn check.

mask_value​

mask_value(value: str) -> str

Keep the last 2 characters, mask the rest.

NameTypeDefaultRequiredDescription
valuestryesValue to mask.

Returns: str. The value with * in place of every character but the last 2; fully masked when 4 characters or fewer.

scan​

scan(text: str, types: list[str] | None = None) -> list[Finding]

Find personal data and secrets in text (overlaps resolved by first, longest match).

NameTypeDefaultRequiredDescription
textstryesText to scan.
typeslist[str] | NoneNonenoKinds of data to look for (email, iban, credit_card, fr_nir, phone, ipv4, secret); default all.

Returns: list[Finding]. A Finding: One local DLP match.

classify_text​

classify_text(text: str) -> str

Highest classification implied by local findings (internal when nothing is found).

NameTypeDefaultRequiredDescription
textstryesText to scan and classify.

Returns: str. internal, confidential or restricted (secrets, cards and NIR are restricted; email, phone and IBAN confidential).

redact​

redact(text: str, mode: str = 'mask', types: list[str] | None = None) -> str

Replace findings with [TYPE] placeholders (mask) or raise on block.

NameTypeDefaultRequiredDescription
textstryesText to redact.
modestr'mask'nodetect (text unchanged), mask or tokenize (findings replaced by [TYPE]), block (raises PolicyDenied dlp_blocked); default mask.
typeslist[str] | NoneNonenoKinds of data to look for (email, iban, ...); default all.

Returns: str. The redacted text, or the text unchanged when nothing is found.

Raises: PolicyDenied, ValueError.