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. |
|
What covers one detection kind, and what happens to its values. |
|
Return one row per detection kind, derived from the live registries. |
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. |
|
Whether one engine can run here, now, and if not, the one step that fixes it. |
|
Decide whether one engine can run for a language, and how to fix it if not. |
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 |
|
Report whether NLTK's data packages are present. |
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 |
|
A pack pattern has a shape that can backtrack catastrophically. |
|
Report the shapes in |
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. |
|
Built-in immutable sequence. |
|
What happens to a value of one kind once it is detected. |
|
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 |
|
Generate a fresh vault key. |
Results and Types#
One resolved detection and the placeholder label assigned to it. |
|
Output of a redaction pass. |
|
Output of a restoration pass. |
|
A half-open |
|
Counters describing one redaction pass. |
|
Return a JSON-safe, secret-free dictionary for a result object. |
Errors and Warnings#
Class inheritance

Base class for every error raised by |
|
The text holds a value of a kind whose action is |
|
An optional tier is not usable in this environment. |
|
A detector raised while scanning. |
|
Outgoing text still holds a value the vault removed; it was not sent. |
|
A policy limit was exceeded. |
|
Two detections overlap under |
|
A detection pattern is uncompilable or structurally unsafe. |
|
A custom pack pattern ran past the pattern time limit on one document. |
|
A |
|
A placeholder in the text cannot be restored from the supplied vault. |
Logging and Audit#
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
Format a record as one JSON object per line. |
|
Replace known secret surfaces in a record with |
|
Keep a vault's values out of every log record for as long as it holds them. |
|
Emit one structured audit event on |
|
Attach a handler to this submodule's logger. |
|
Return a logger under this submodule's namespace. |
|
Return the log level named by the environment, or |
|
Scrub known secrets from log records for the duration of a block. |
Pattern Catalog and Surrogate Sets#
An immutable set of packs and formats. |
|
Return the built-in catalog, read from the compiled JSON. |
|
A validated set of invented names. |
|
Read and validate a surrogate set from a |
Corpus Integration#
Return corpus documents with every text field redacted by one cleaner. |
|
Let corpus read |