Source code for aeat.adapters.outbound.llm._errors

"""Error hierarchy for the LLM subpackage.

All public LLM exceptions inherit from
:class:`~adapters.outbound.llm.LLMError`, which extends
:class:`~core.errors.AeatError`. Provider adapters surface
:exc:`~adapters.outbound.llm.LLMProviderError` and
:exc:`~adapters.outbound.llm.LLMRateLimitError`, cache and usage storage
surface :exc:`~adapters.outbound.llm.LLMCacheError`, and strict model
validators surface :exc:`~adapters.outbound.llm.LLMValidationError`.
"""

from __future__ import annotations

from ....core.errors import AeatError


[docs] class LLMError(AeatError): """Base exception for public LLM package failures."""
[docs] class LLMProviderError(LLMError): """Raised when a provider adapter cannot return a completion."""
[docs] class LLMPdfRasterisationError(LLMError): """Raised when :func:`~adapters.outbound.llm.rasterise_pdf_pages_to_base64_png` fails."""
[docs] class LLMCacheError(LLMError): """Raised when :class:`~adapters.outbound.llm.LLMCache` storage fails."""
[docs] class LLMRateLimitError(LLMProviderError): """Raised when a provider rejects a request because of rate limits. Inherits from :exc:`~adapters.outbound.llm.LLMProviderError` so callers can catch all provider-boundary failures together. Args: message: Human-readable error message. retry_after_seconds: Optional server-provided retry delay in seconds. """ def __init__(self, message: str, retry_after_seconds: float | None = None) -> None: super().__init__(message) self.retry_after_seconds = retry_after_seconds
[docs] class LLMConfigError(LLMError): """Raised when :class:`~adapters.outbound.llm.LLMClient` configuration is invalid."""
[docs] class LLMValidationError(LLMError, ValueError): """Raised when an LLM-related object fails validation. Inherits from both :class:`~adapters.outbound.llm.LLMError` and :class:`ValueError` to remain compatible with Pydantic's validator-failure contract while allowing catch-all :class:`~adapters.outbound.llm.LLMError` handlers to detect integrity failures. """