Skip to content

Api Utils

API utilities for sensitive data handling.

redact_sensitive_data(data, safe_keys=None)

Return a copy of data with non-whitelisted entries masked for safe logging.

Recursively walks dicts, lists, and tuples, replacing the value of any key not in the whitelist with a redaction placeholder. Scalars and other non-collection types are returned as-is. The original input is not mutated.

Parameters:

Name Type Description Default
data Any

The data to redact, typically a config dict.

required
safe_keys Container[str] | None

The whitelist of (lowercased) keys to preserve. Defaults to None, in which case the process-global SAFE_KEYS is used. Pass a custom set to scope the whitelist to a single caller.

None

Returns:

Name Type Description
Any Any

A redacted copy safe to log.