Skip to content

Error Utils

Utility functions for mapping errors to the multimodal error taxonomy.

gllm-inference 0.6.175 and later raise invoker errors that inherit BaseError, so converters re-raise them unchanged. Earlier releases raise invoker errors that do not inherit it. The helpers here map those legacy errors to multimodal errors with a message composed from the operation wording. The message never includes the invoker text, as older releases may include raw provider text in it. wrap_non_gllm_errors keeps any other error inside the GLLM error taxonomy. This module also builds safe audio transcription diagnostics.

InvokerErrorWording(task, component, media, inputs) dataclass

Wording of the multimodal errors mapped from the invoker errors of one LM-based operation.

Attributes:

Name Type Description
task str

The operation named in operation and result errors, such as video caption.

component str

The component named in configuration errors, such as Video captioning.

media str

The input media the model must accept, such as video.

inputs str

The inputs to reduce when the model input limit is exceeded, such as the prompt or the audio.

audio_config_error(component, parameter, next_step, error=None)

Build a safe component configuration error for an audio transcription converter.

Parameters:

Name Type Description Default
component str

Component named in the error message.

required
parameter str

Invalid or missing setting named in the error message.

required
next_step str

Action the caller can take to correct the setting.

required
error Exception | None

Optional original error whose type is retained in diagnostics.

None

Returns:

Name Type Description
ComponentConfigError ComponentConfigError

Configuration error with safe diagnostics.

audio_debug_info(stage, source_kind='unknown', error=None, *, provider_error=None, **details)

Build safe diagnostic context for an audio transcription error.

Only exception class names are copied from errors. Exception text, source values, audio bytes, prompts, and credentials are never added to the diagnostics.

Parameters:

Name Type Description Default
stage str

Where the failure occurred, such as validate or provider_call.

required
source_kind str

Kind of input involved, such as bytes or string.

'unknown'
error Exception | None

Local exception whose type should be recorded.

None
provider_error Exception | None

Provider exception whose type should be recorded.

None
**details str | int | float

Additional diagnostic fields, such as size_bytes or status_code.

{}

Returns:

Type Description
dict[str, str | int | float]

Candidate diagnostics for sanitization by the error class.

build_configuration_error(parameter, next_step, *, modality='unknown', cause=None)

Create a safe configuration error with component setup context.

Parameters:

Name Type Description Default
parameter str

The setting or argument that needs correction.

required
next_step str

The action the caller can take to correct it.

required
modality str

Source modality for diagnostics.

'unknown'
cause Exception | None

Optional lower-level cause whose class is retained in diagnostics.

None

Returns:

Name Type Description
ComponentConfigError ComponentConfigError

Configuration error with sanitized diagnostics.

config_error_from_validation_error(error, *, component, subject, default_parameter, debug_info=None)

Translate a pydantic validation failure of a config model into a component configuration error.

A model whose __init__ already raises ComponentConfigError has that error wrapped by pydantic when validation runs through model_validate. The wrapped error is returned as is, so the message is not doubled.

Parameters:

Name Type Description Default
error ValidationError

The pydantic validation failure.

required
component str

Name of the component with invalid configuration.

required
subject str

What the caller should check, named in the next step.

required
default_parameter str

Parameter to report when the failure is not tied to one field.

required
debug_info dict[str, str] | None

Diagnostic context. Defaults to None.

None

Returns:

Name Type Description
ComponentConfigError ComponentConfigError

The error raised inside the model when pydantic wrapped it, otherwise a new error built from error.

configuration_errors(parameter, next_step, *, modality='unknown')

Translate non-GLLM configuration errors and preserve GLLM errors with context.

Parameters:

Name Type Description Default
parameter str

The setting or argument to name when translating an error.

required
next_step str

The action the caller can take to correct it.

required
modality str

Source modality for diagnostics.

'unknown'

Yields:

Name Type Description
None None

Control to the guarded configuration work.

Raises:

Type Description
ComponentConfigError

If configuration preparation raises a non-GLLM exception.

BaseError

If configuration preparation raises a GLLM error, preserved with additional safe context.

describe_validation_error(error, *, default_parameter)

Name the offending parameter of a validation failure and the reason it was rejected.

Only the first reported problem is described, so the caller can fix one option at a time. An unknown option is reported against default_parameter, since the option itself is not a valid parameter. A validator's own message is reported without pydantic's Value error, prefix.

Parameters:

Name Type Description Default
error ValidationError

The pydantic validation failure.

required
default_parameter str

Parameter name to report when the failure is not tied to a single valid field, for example an unknown option or a value of the wrong type for the whole model.

required

Returns:

Type Description
tuple[str, str]

tuple[str, str]: (parameter, reason) where parameter is the dotted path of the offending field (or default_parameter) and reason explains why it was rejected.

is_legacy_invoker_error(error)

Check whether an error is an invoker error from gllm-inference before 0.6.175.

The check matches class names in the MRO of the error, not the gllm-inference classes, because the legacy classes are not the classes of the installed release and some do not exist in every release. A GLLM error from gllm-inference 0.6.175 or later is not a legacy invoker error, even though its MRO has the same names.

Parameters:

Name Type Description Default
error BaseException

The error to check.

required

Returns:

Name Type Description
bool bool

True if BaseInvokerError is in the MRO of the error and the error is not a GLLM error.

legacy_invoker_error(error, *, wording, debug_info)

Map an invoker error from gllm-inference before 0.6.175 raised by an LM request to a multimodal error.

The message of the multimodal error is composed from the wording and the class of the invoker error. The message of the invoker error is not used. An error whose cause is the builtin TimeoutError is a timeout.

Parameters:

Name Type Description Default
error BaseException

The error raised by the LM request.

required
wording InvokerErrorWording

The wording of the operation that made the request.

required
debug_info dict[str, str]

Diagnostic context, such as the operation, stage, modality, and source kind.

required

Returns:

Type Description
MultimodalError | None

MultimodalError | None: MediaOperationTimeoutError for a timeout, MediaOperationConfigError for an error the caller can correct, MediaResultOperationError for a missing output item, or MediaOperationFailedError for any other legacy invoker error. None if the error is not a legacy invoker error.

preset_config_error(error, *, component, wording, next_action, debug_info)

Map an error raised while an LM-based component is built to a component configuration error.

The error is a legacy invoker error from gllm-inference before 0.6.175, a google-auth DefaultCredentialsError for Google service account credentials that cannot be loaded, or a builtin ValueError or TypeError that is not a GLLM error. The message names the setting to correct when the error gives one, and the LM invoker configuration otherwise. The message of the original error is not used.

Parameters:

Name Type Description Default
error BaseException

The error raised while the component is built.

required
component str

The component named in the message, such as Video caption preset.

required
wording InvokerErrorWording

The wording of the operation the component performs.

required
next_action str

What the caller does after correcting the setting, such as create the captioner again.

required
debug_info dict[str, str]

Diagnostic context, such as the operation, stage, modality, and component.

required

Returns:

Type Description
ComponentConfigError | None

ComponentConfigError | None: The configuration error. None if the error is not a legacy invoker error, a DefaultCredentialsError, or a builtin ValueError or TypeError that is not a GLLM error.

wrap_non_gllm_errors(to_gllm_error, error_classes=Exception)

Re-raise GLLM errors unchanged and convert any other exception of error_classes with to_gllm_error.

The converted error is chained to the original exception, so the original stays available as its __cause__. The caller decides which GLLM error class to raise and what it records about the original.

Example
with wrap_non_gllm_errors(lambda e: MediaOperationFailedError(task="frame sampling")):
    run_pipeline()

Parameters:

Name Type Description Default
to_gllm_error Callable[[Exception], BaseError]

Builds the GLLM error to raise for an exception outside the taxonomy.

required
error_classes type[Exception] | tuple[type[Exception], ...]

The exception classes to convert. Exceptions of other classes pass through unchanged. Defaults to Exception.

Exception

Yields:

Name Type Description
None None

Control to the guarded block.

Raises:

Type Description
BaseError

A GLLM taxonomy error raised by the block, preserved unchanged, or the error built by to_gllm_error for an exception of error_classes.

Exception

Any exception outside error_classes, unchanged.