Skip to content

Redaction

Reusable redaction for diagnostic text, log messages, and structured data.

Use redact_text before displaying untrusted text in logs or diagnostics. Use redact_sensitive_data for mappings that have an explicit safe-key list. Both functions return a redacted copy and leave their input unchanged.

redact_sensitive_data(data, safe_keys=None)

Return a copy of structured data with non-whitelisted fields masked.

Parameters:

Name Type Description Default
data Any

Mapping, list, tuple, or scalar to redact.

required
safe_keys Container[str] | None

Case-insensitive allowlist of mapping keys. Defaults to SAFE_KEYS.

None

Returns:

Type Description
Any

A redacted copy of data; scalar values retain their original type.

Example

Keep a model identifier while masking a credential.

from gllm_multimodal.utils.redaction import redact_sensitive_data

print(redact_sensitive_data({"model_id": "vision", "api_key": "secret"}))
Output:
{'model_id': 'vision', 'api_key': 'REDACTED'}

redact_text(value, *, limit=None)

Redact common secrets, URLs, and local paths from a text value.

This is suitable for lower-level error messages, tracebacks, and strings written to logs. A length limit is optional so callers can set their own storage boundary without changing the redaction rules.

Parameters:

Name Type Description Default
value str

Text to redact.

required
limit int | None

Maximum output characters before a truncation marker. Defaults to no length limit.

None

Returns:

Type Description
str

The redacted text, optionally bounded to limit characters.

Example

Redact a log message before emitting it.

from gllm_multimodal.utils.redaction import redact_text

print(redact_text("api_key=secret-value"))
Output:
api_key=[REDACTED]