Skip to content

Exceptions

Define the normalized exceptions gllm-privacy raises.

Every concrete error has a stable code (GLLM-PRIV-<NAME>) and a default_message. Each error that replaced a builtin error keeps its builtin ancestry (ValueError, ImportError or RuntimeError), so existing except clauses keep matching. Errors added later, such as MaskingError, have no builtin base.

debug_info contains metadata only, never external messages, URLs, source frames, or payloads.

recovery says whether retrying can succeed. Remote timeout, connection, rate limit and server errors are retryable, and a rate limit or server error carries retry_after_seconds when the service sends Retry-After. Every other error keeps the {"retryable": False} default.

BasePrivacyError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseError

Root of the normalized errors raised by gllm-privacy.

This class is abstract and is never raised directly. Every concrete subclass defines its own code (GLLM-PRIV-<NAME>) and default_message.

Attributes:

Name Type Description
code str | None

Stable error code. Defined by each concrete subclass.

default_message str | None

Message used when no message is given. Defined by each concrete subclass.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

recovery RecoveryInfo

Whether retrying can succeed. Defaults to {"retryable": False}.

BaseRemoteRecognizerError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, RuntimeError

Base class of the errors raised when a remote NER service call fails.

This class is abstract and is never raised directly. Catch it to handle every remote recognizer failure. Raw exception context is suppressed in default traces. Diagnostics retain safe metadata only.

Attributes:

Name Type Description
code str | None

Stable error code. Defined by each concrete subclass.

default_message str | None

Message used when no message is given. Defined by each concrete subclass.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as recognizer and status_code.

InvalidConfigError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ValueError

Raised when a recognizer, chunker or other component receives an invalid configuration.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-INVALID-CONFIG.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as parameter.

InvalidInputError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ValueError

Raised when the input of an analyzer or anonymizer is missing or invalid.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-INVALID-INPUT.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as parameter.

InvalidToolArgumentsError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError

Raised when a PrivacyComponent tool is called with arguments that the wrapped main method does not accept.

Examples are a missing required argument, an unexpected or repeated argument, too many positional arguments, or a value for a *args parameter. The wrapped component is not called. Diagnostics contain no argument names or values from the call.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-INVALID-TOOL-ARGUMENTS.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as reason.

MaskingError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError

Raised when PrivacyComponent fails to mask its inputs. The wrapped component is not called.

Diagnostics retain the original type, not the raw error message or source frames.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-MASKING.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

MissingDependencyError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ImportError

Raised when an optional dependency needed by a component is not installed.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-MISSING-DEPENDENCY.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

ModelInferenceError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, RuntimeError

Raised when the NER model fails while predicting entities in the text.

Diagnostics retain the original type, not the raw error message or source frames.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-MODEL-INFERENCE.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

ModelLoadError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, RuntimeError

Raised when the NER model, tokenizer or pipeline cannot be loaded.

Diagnostics retain the original type, not the raw error message or source frames.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-MODEL-LOAD.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

ModelOutputError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ValueError

Raised when the NER model returns a result that does not match its input.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-MODEL-OUTPUT.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

PrivacyDebugInfo

Bases: DebugInfo

Structured internal detail attached to the errors raised by gllm-privacy.

Extends DebugInfo with the keys specific to privacy errors. This is a type-level contract only.

Attributes:

Name Type Description
class_name str

Name of the exception class. Always present.

error_type str

Type name of the original error, when one was caught.

parameter str

Name of the input or configuration parameter involved, when applicable.

language str

Supported language code, when applicable. Unknown input values are excluded.

recognizer str

Name of the recognizer class involved, when applicable.

status_code int

HTTP status code returned by the remote service, when applicable.

upstream_error_code str

Public error code from the GDP Labs NER API error response, when it is valid.

upstream_request_id str

Request ID from the GDP Labs NER API error response, when it is valid.

reason str

Internal cause of the failure for developers, when no original error was caught.

argument str

Name of the component argument or result field involved, when applicable.

value_type str

Type name of a value that could not be masked or restored, when applicable.

PrivacyRuntimeError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, RuntimeError

Raised when an internal step of gllm-privacy fails unexpectedly.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-RUNTIME.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

RemoteRecognizerAuthError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service rejects the credentials (HTTP 401 or 403). Do not retry as is.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-AUTH.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

RemoteRecognizerConnectionError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service cannot be reached. Callers can retry.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-CONNECTION.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

recovery RecoveryInfo

{"retryable": True}.

RemoteRecognizerInvalidResponseError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service returns a response in an unexpected format.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-INVALID-RESPONSE.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

RemoteRecognizerRateLimitError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service throttles the request (HTTP 429). Retry after a delay.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-RATE-LIMIT.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

recovery RecoveryInfo

{"retryable": True}, plus retry_after_seconds when the service sends Retry-After.

RemoteRecognizerRequestError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER request fails for any other reason, such as another HTTP 4xx status.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-REQUEST.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

RemoteRecognizerServerError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service fails on its side (HTTP 5xx). Callers can retry.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-SERVER.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

recovery RecoveryInfo

{"retryable": True}, plus retry_after_seconds when the service sends Retry-After.

RemoteRecognizerTLSError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the TLS handshake with the remote NER service fails. Do not retry as is.

This covers a rejected or invalid client certificate (mTLS), and a server certificate that cannot be verified.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-TLS.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

RemoteRecognizerTimeoutError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BaseRemoteRecognizerError

Raised when the remote NER service does not respond within the timeout. Callers can retry.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-REMOTE-TIMEOUT.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

recovery RecoveryInfo

{"retryable": True}.

RestorationError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError

Raised when PrivacyComponent fails to restore masked values in the wrapped component's result.

The result is discarded, so the caller never receives a masked or partly restored result. Diagnostics retain the original type, not the raw error message or source frames.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-RESTORATION.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

UnsupportedLanguageError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ValueError

Raised when a component receives a language it does not support.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-UNSUPPORTED-LANGUAGE.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as language.

UnsupportedTokenizerError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError, ValueError

Raised when a tokenizer cannot provide the character offsets needed to chunk text.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-UNSUPPORTED-TOKENIZER.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail about this error.

UnsupportedValueError(message=None, *, debug_info=None, recovery=None, original_error=None)

Bases: BasePrivacyError

Raised when PrivacyComponent meets a value it has no rule to mask or restore.

The wrapper never converts an unknown object to text and never passes it through unmasked. Add a PrivacyValueAdapter for the type to support it.

Attributes:

Name Type Description
code str

Stable error code, GLLM-PRIV-UNSUPPORTED-VALUE.

default_message str

Message used when no message is given.

message str

The message of this error.

debug_info PrivacyDebugInfo

Structured internal detail, such as argument and value_type.