redacting#
- class scikitplot.cleanprompt.redacting(secrets=None, logger=None)[source]#
Scrub known secrets from log records for the duration of a block.
- Parameters:
- secretsiterable of str, optional
Surfaces to scrub.
- loggerlogging.Logger, optional
Logger to attach to. Defaults to this submodule’s root logger.
- Parameters:
secrets (Iterable[str] | None)
logger (logging.Logger | None)
Notes
User notes. Wrap anything that logs while holding personal data:
with redacting(vault.export().values()): do_work()
Developer notes. The filter is attached to every logger in this namespace, not to a handler, so it applies however the application has configured its output. Attaching it to the namespace root alone looked equivalent and was not: a logger’s filters see only that logger’s own records, never its children’s (
CP-059). It is removed on exit, including when the block raises, so a long-lived process does not accumulate filters holding the secrets of every request it has ever served — which would be the very leak this is meant to prevent.Examples
>>> with redacting(["topsecret@example.com"]): ... pass
Gallery examples#
Cleanprompt from Python: Single Calls and Edge Cases
Cleanprompt Recipes: CI Gates, Notebooks, Pipelines and Agents