encode#

scikitplot.cleanprompt.encode(text, *, policy=None, profile=None, hide=None, allow=None, kinds=None, ignore_case=None, ner=False, engine='auto', language='en', model=None, size='sm', registry=None, word_boundary=False, suggest=True)[source]#

Replace sensitive values in text with placeholders.

Parameters:
textstr

The prompt to make safe.

policyRedactionPolicy, optional

Full policy. Overrides profile and the individual keywords.

profilestr, optional

Named bundle: "minimal", "balanced" or "strict".

hideiterable of str, optional

Extra exact strings to remove.

allowiterable of str, optional

Surfaces that must never be removed.

kindsiterable of str, optional

Detection kinds to enable.

ignore_casebool, optional

Treat values differing only in case as one entity.

nerbool, default=False

Also run named-entity detection.

enginestr, default=’auto’

"auto", "spacy", "nltk", "both" or "none".

languagestr, default=’en’

Language code for the entity engine.

modelstr, optional

Explicit spaCy model, overriding language and size.

sizestr, default=’sm’

Preferred spaCy model size.

registryDetectorRegistry, optional

Detectors to use, bypassing ner and the engine keywords.

word_boundarybool, default=False

Whether hide terms match only at word boundaries.

suggestbool, default=True

Include candidate terms in the report.

Returns:
EncodedPrompt

Unpacks as (text, handle).

Raises:
TypeError

If text is not a string.

CapabilityError

If ner was asked for and the chosen engine is unavailable.

CleanPromptError

For any other configuration or limit failure.

Parameters:
Return type:

EncodedPrompt

Notes

User notes. Send the text; keep the handle. If result.level == "alert", nothing was redacted and something was not looking — read the report before sending.

Examples

>>> safe, handle = encode("Mail ada@example.com")
>>> safe
'Mail [EMAIL-1]'
>>> decode("Reply to [EMAIL-1]", handle)
'Reply to ada@example.com'