Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-llm/src/lexigram/ai/llm/exceptions.py: 100%
38 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
1"""LLM package exceptions."""
3from __future__ import annotations
5from lexigram.contracts.ai.exceptions import (
6 ExtractionError as _ContractsExtractionError,
7)
8from lexigram.contracts.ai.exceptions import LLMError as _ContractsLLMError
10__all__ = [
11 "ExtractionError",
12 "ExtractionMaxRetriesError",
13 "ExtractionParseError",
14 "ExtractionValidationError",
15 "InvalidRequestError",
16 "LLMAuthenticationError",
17 "LLMContentFilterError",
18 "LLMError",
19 "LLMModelNotFoundError",
20 "LLMQuotaExceededError",
21 "LLMRateLimitError",
22 "LLMTimeoutError",
23 "ModelNotFoundError",
24 "ModelRevisionMismatchError",
25 "ProviderConnectionError",
26 "StreamError",
27 "TokenLimitError",
28]
31class LLMError(_ContractsLLMError):
32 """Base exception for all LLM-domain errors in lexigram-ai-llm."""
34 _code: str = "LEX_ERR_LLM_002"
37class LLMAuthenticationError(LLMError):
38 """Invalid API key or credentials — infrastructure error, raised not wrapped.
40 Raised as an exception (NOT wrapped in ``Result``).
41 Indicates a misconfiguration the application cannot route around.
42 """
44 _code: str = "LEX_ERR_LLM_003"
47class InvalidRequestError(LLMError):
48 """Error raised when a request to an LLM provider is invalid."""
50 _code: str = "LEX_ERR_LLM_004"
53class ModelNotFoundError(LLMError):
54 """Model unavailable or not found — recoverable via fallback routing."""
56 _code: str = "LEX_ERR_LLM_005"
59class LLMModelNotFoundError(ModelNotFoundError):
60 """Model unavailable or not found — recoverable via fallback routing.
62 Returned as ``Err`` from ``LLMClientProtocol.complete()`` / ``stream_chat()``.
63 The caller should route to a different model or provider.
64 """
66 _code: str = "LEX_ERR_LLM_006"
69class LLMRateLimitError(LLMError):
70 """Rate limit exceeded — recoverable via backoff/retry.
72 Returned as ``Err`` from ``LLMClientProtocol.complete()`` / ``stream_chat()``.
73 The caller should implement exponential backoff or route to another provider.
74 """
76 _code: str = "LEX_ERR_LLM_007"
79class LLMQuotaExceededError(LLMError):
80 """API quota or billing limit exceeded — recoverable by routing elsewhere.
82 Returned as ``Err`` from ``LLMClientProtocol.complete()`` / ``stream_chat()``.
83 The caller should route the request to a different provider or account.
84 """
86 _code: str = "LEX_ERR_LLM_008"
89class LLMContentFilterError(LLMError):
90 """Content blocked by provider safety filter — recoverable via reformulation.
92 Returned as ``Err`` from ``LLMClientProtocol.complete()`` / ``stream_chat()``.
93 The caller should reformulate the prompt or inform the user.
94 """
96 _code: str = "LEX_ERR_LLM_009"
99class TokenLimitError(LLMError):
100 """Error raised when the token limit for a request is exceeded."""
102 _code: str = "LEX_ERR_LLM_010"
105class ProviderConnectionError(LLMError):
106 """Error raised when connection to an LLM provider fails."""
108 _code: str = "LEX_ERR_LLM_011"
111class StreamError(LLMError):
112 """Error raised during LLM response streaming."""
114 _code: str = "LEX_ERR_LLM_012"
117class ExtractionError(_ContractsExtractionError):
118 """Base class for structured extraction errors in lexigram-ai-llm."""
120 _code: str = "LEX_ERR_LLM_013"
123class ExtractionParseError(ExtractionError):
124 """Error raised when extraction response cannot be parsed as JSON."""
126 _code: str = "LEX_ERR_LLM_014"
129class ExtractionValidationError(ExtractionError):
130 """Error raised when parsed extraction response fails schema validation."""
132 _code: str = "LEX_ERR_LLM_015"
135class ExtractionMaxRetriesError(ExtractionError):
136 """Error raised when extraction max retries are exhausted."""
138 _code: str = "LEX_ERR_LLM_016"
141class ModelRevisionMismatchError(LLMError):
142 """Raised when the provider returns a model revision that violates the pin policy."""
144 _code: str = "LEX_ERR_LLM_017"
147class LLMTimeoutError(LLMError):
148 """Request exceeded the client timeout — recoverable by routing elsewhere.
150 Returned as ``Err`` from ``LLMClientProtocol.complete()`` / ``stream_chat()``.
151 Not retried in place: the request already consumed a full timeout window,
152 so the caller (router cascade) should advance to another provider.
153 """
155 _code: str = "LEX_ERR_LLM_018"