scikitplot.cleanprompt#
Redact sensitive values from a prompt, then restore them from the reply.
scikitplot.cleanprompt replaces personal data in a text with stable
placeholders before that text is sent to a language model, and puts the values
back afterwards. The base tier is pure standard library.
Notes
User notes.
from scikitplot.cleanprompt import Redactor, restore
redactor = Redactor()
result = redactor.redact(
"Mail ada@example.com about the Acme deal", extra_terms=["Acme"]
)
result.text
# 'Mail [EMAIL-1] about the [CUSTOM-1] deal'
# ... send result.text to a model, get a reply ...
restore(reply, result.vault).text
result.text is safe to transmit. result.vault is not: it holds the
values that were removed. Keep it on this machine and call vault.clear()
when you are finished.
The optional tiers add named-entity detection, a local web interface, and
authenticated vault encryption. capabilities reports which are usable:
python -m scikitplot.cleanprompt capabilities
Developer notes — the import contract.
Importing this module imports no third-party package. Not spacy, not
flask, not cryptography, not numpy. This submodule can therefore be
added to scikitplot without changing the import cost or the failure surface
of any other submodule, and without any other submodule needing to know it
exists. It imports no sibling scikitplot package either.
Optional-tier names are resolved lazily through PEP 562:
__all__lists base-tier names only.__all__is the star-import surface, andfrom … import *resolves every entry; listing an optional name there would defeat the lazy tier at exactly the one operation that touches all of them. The optional names remain reachable by attribute access, which is how a consumer of that tier reaches them anyway.__getattr__imports the owning module on first access, and raisesCapabilityErrorwith an install command when the tier is unavailable — raised before the missing dependency is imported, so the message is actually reachable.__dir__unions the module globals with the optional names as strings and never resolves them, so tab completion, Sphinx andhasattrstay base-safe.
import scikitplot.cleanprompt, dir(scikitplot.cleanprompt) and
from scikitplot.cleanprompt import * all succeed on a base installation.
Each is a checked-in regression test, not a claim.
See also
scikitplot.cleanprompt._engineThe pipeline.
scikitplot.cleanprompt._policyDeclarative configuration.
scikitplot.cleanprompt._patternsThe curated pattern library.
!! processed by numpydoc !!
User guide. See the CleanPrompt User Guide section for further details.
API Encode Prompt#
APP Session Store#
Bounded, expiring, server-side store of vaults. |
|
Build the Flask application. |
Capability#
Outcome of probing one tier. |
|
Seven-state usability vocabulary for an optional dependency tier. |
|
Probe every optional tier. |
|
Report whether one optional tier is usable. |
|
Return the report for |
Custom Domain and Point#
Load user definitions from one or more files into a catalog of their own. |
|
Return the built-in catalog with custom definitions merged in. |
Detector Registry#
Base class for detectors. |
|
An ordered, immutable-by-convention collection of detectors. |
|
Detector for exact strings the caller names. |
|
Detector backed by one entry of the pattern library. |
|
Build a registry from the pattern library, plus optional literal terms. |
Diagnosis#
A category of sensitive information nothing currently detects. |
|
What a given configuration can and cannot detect. |
|
A candidate the active detectors did not claim. |
|
Explain a redaction outcome, especially an empty one. |
|
Report what a configuration can and cannot detect. |
|
Offer candidate terms the active detectors did not claim. |
Redactor#
Reusable, stateless redactor. |
|
Find substrings of |
|
Reduce possibly overlapping spans to a disjoint, ascending sequence. |
|
Replace placeholders in |
Engines Named-entity#
Built-in immutable sequence. |
|
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
Built-in immutable sequence. |
|
Static description of one named-entity engine. |
|
Construct the detectors for an engine mode. |
|
Map an engine's entity label onto the canonical vocabulary. |
|
Report every engine's readiness, and what |
|
Resolve an engine mode into the engines that will actually run. |
|
Shrink an entity span until it carries no unmatched bracket. |
Format Spec#
One validated file format. |
Guard Spec#
Encode what goes to a model, check it, and decode what comes back. |
|
Decode a model's reply as it streams in, never splitting a label. |
Language Spec#
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
Built-in immutable sequence. |
|
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
One language spaCy publishes models for. |
|
Return the spaCy models installed here, mapped to their versions. |
|
Resolve a language and size into a spaCy model name. |
|
Return every language code with a dedicated model. |
Mcp Server#
Answer MCP requests with cleanprompt tools. |
Ner Detector#
frozenset() -> empty frozenset object frozenset(iterable) -> frozenset object |
|
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
Detect named entities with a spaCy pipeline. |
|
Build a |
Nltk Detector#
Detect named entities with NLTK's maximum-entropy chunker. |
|
Build an |
Pack Pattern Detector#
Pattern Spec#
One named structural pattern. |
|
Return the patterns enabled when a policy does not name |
|
Return one pattern specification by kind. |
|
Return whether |
Plan Spec#
Everything a cleaner needs to know, and nothing it discovers. |
|
Build a |
Policy Spec#
Hard bounds on one redaction pass. |
|
Complete, declarative configuration for a redaction pass. |
|
The placeholder grammar. |
|
Hard bounds on one redaction pass. |
|
How to arbitrate two detections that share characters. |
|
Complete, declarative configuration for a redaction pass. |
|
The placeholder grammar. |
Render Helper#
Terminal escape sequences used by |
|
Return a copy of |
|
Return a one-line, secret-free description of a restoration. |
|
Decide whether to emit terminal colour. |
|
Render a table of what was redacted. |
Runtime Helper#
Vault#
A closed mapping from placeholder label to original secret. |
Vault Encryption#
Decrypt a mapping produced by |
|
Encrypt every value of |