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
textwith placeholders.- Parameters:
- textstr
The prompt to make safe.
- policyRedactionPolicy, optional
Full policy. Overrides
profileand 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
languageandsize.- sizestr, default=’sm’
Preferred spaCy model size.
- registryDetectorRegistry, optional
Detectors to use, bypassing
nerand the engine keywords.- word_boundarybool, default=False
Whether
hideterms match only at word boundaries.- suggestbool, default=True
Include candidate terms in the report.
- Returns:
- EncodedPrompt
Unpacks as
(text, handle).
- Raises:
- TypeError
If
textis not a string.- CapabilityError
If
nerwas asked for and the chosen engine is unavailable.- CleanPromptError
For any other configuration or limit failure.
- Parameters:
- Return type:
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'
Gallery examples#
Cleanprompt Advanced: Invariants, Encryption, and the Lossy Model Hop
Cleanprompt Basics: Hide a Value, Then Get It Back
Cleanprompt Moderate: Policies, Entities, and the Vault’s Lifecycle
Cleanprompt Packs and Formats: Records, Configs and Whole Folders
Cleanprompt from Python: Single Calls and Edge Cases