restore#
- scikitplot.cleanprompt.restore(text, vault, policy=None, strict=False, lenient=True)[source]#
Replace placeholders in
textwith the values held invault.- Parameters:
- textstr
Text containing placeholders, typically a language model’s reply.
- vaultVault
The vault produced by the matching redaction.
- policyRedactionPolicy, optional
Supplies the placeholder grammar. Defaults to
DEFAULT_POLICY. Its fingerprint is checked against the vault’s.- strictbool, default=False
When
True, a placeholder that is not in the vault raises.- lenientbool, default=True
Also match placeholders the model rewrote — a different case, a different separator, escaped brackets, a line break inside the label. Each one acted on is listed in
repaired. SetFalseto match only labels spelled exactly as they were issued.
- Returns:
- RestorationResult
The restored text plus which labels were restored, unknown and unused.
- Raises:
- TypeError
If
textis not a string.- PolicyError
If the vault is closed, or was issued under a different placeholder grammar.
- RestorationError
Under
strictwhen a placeholder is not in the vault.
- Parameters:
text (str)
vault (Vault)
policy (RedactionPolicy | None)
strict (bool)
lenient (bool)
- Return type:
RestorationResult
Notes
User notes.
strict=Falseis the default because a reply may legitimately contain placeholder-shaped text the vault never issued — for instance if your original text already contained one. Unknown labels are left exactly as they are and reported inunknown; check that field rather than assuming completeness.Developer notes. One compiled scan, one dictionary lookup per hit, one join. Replacing each known label in turn would be O(entries × length) and would let a restored value containing a placeholder be re-matched on a later iteration.
The fingerprint checked here is the grammar digest (
fingerprint), not the full policy digest. Only the grammar can change how a label is spelled, so narrowingkindsor raising a limit between redaction and restoration is legitimate and must not be rejected.Examples
>>> result = Redactor().redact("call +1 555 010 4477") >>> restore(result.text, result.vault).text 'call +1 555 010 4477' >>> restore("[EMAIL-9] unknown", result.vault).unknown ('[EMAIL-9]',)
Gallery examples#
Cleanprompt Advanced: Invariants, Encryption, and the Lossy Model Hop
Cleanprompt Moderate: Policies, Entities, and the Vault’s Lifecycle
Cleanprompt from Python: Single Calls and Edge Cases