Redaction
Secret masking for provider error text before it leaves the code interpreter.
Provider and SDK exceptions can echo credentials (API keys, bearer tokens, credential URLs). Each sink that their text reaches masks it itself, so call sites format exceptions normally:
CodeInterpreterErrormasks its own message.TemplateBuildResultmasks itsdetail.- Code interpreter loggers carry
RedactingFilter, which masks the message and the traceback. - Spans record a masked exception event (
observability._start_span). ExecutionResult.createmasks an exception passed aserror. A string is kept unchanged, because the user program's own errors must reach the model as is; cause-chain renderings useredacted_chain.
Only the secrets are masked; the rest of the message and its cause chain are kept, so the failure stays
diagnosable. The masking engine and most rules come from gllm_core.masking. The raw text is still
available to programmatic callers through the exception's __cause__ chain.
RedactingFilter
Bases: Filter
Mask secrets in a record's message and traceback before any handler sees it.
The traceback is rendered here, masked, into exc_text and exc_info is cleared, so a handler
that reads the live exception cannot reach the raw text.
filter(record)
Mask the record in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The record to mask. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Always True; the record is kept. |
format_error_chain(error)
Render an exception with its cause chain intact.
str(e) alone drops the wrapped cause, which is where the useful detail lives — a
pyqwest TLS EOF reads as "peer closed connection without sending TLS close_notify" only
on the inner exception. That holds however the SDK presents the failure: OpenSandbox's
converter embeds the immediate cause's message in its wrapper, so a one-level chain
survives str() by luck, but anything deeper does not. The result is raw provider text:
pass it through redact (or use redacted_chain) before it leaves the sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
BaseException
|
The exception to render. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The exception and its causes, outermost first, stopping at a context the raiser suppressed. |
get_redacting_logger(name)
Get the module logger with RedactingFilter attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The logger name, usually |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
logging.Logger: The logger, masking every record logged on it. |
qualified_type(error)
Render an exception's fully qualified type name for FailureDetail.exception_type.
Shared so every backend reports the same string for the same exception: consumers branch on this value, so a per-backend spelling would silently break them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
BaseException
|
The exception to name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Dotted module path and qualified class name, e.g. |
redact(text, fallback=REDACTION_FAILED)
Mask registered secret values and credential shapes, keeping the rest of the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Provider text to mask. |
required |
fallback
|
str
|
Returned instead of |
REDACTION_FAILED
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The text with every secret replaced by a placeholder, or |
redacted_chain(error)
Render an exception's cause chain (see format_error_chain) with secrets masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
BaseException
|
The exception to render. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked cause chain, or the qualified type name when masking fails. |
redacted_message(error)
Render str(error) with secrets masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
BaseException
|
The exception to render. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked message, or the qualified type name when masking fails. |
redacted_traceback(error)
Render an exception's full traceback, chained causes included, with secrets masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
BaseException
|
The exception to render. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The masked traceback, or the qualified type name when masking fails. |
register_secret(value)
Mask value by exact match in every later redaction, whatever its shape.
Called where a configured credential enters (sandbox create, template builder __init__), so
paths that never see the key (execution, download, module helpers) still mask it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
The secret, such as the configured API key. |
required |