#[non_exhaustive]pub enum LlmError {
Http {
status: Option<StatusCode>,
message: String,
retryable: bool,
},
Auth(String),
InvalidRequest(String),
Provider {
code: String,
message: String,
retryable: bool,
},
ResponseFormat {
message: String,
raw: String,
},
SchemaValidation {
message: String,
schema: Value,
actual: Value,
},
ToolExecution {
tool_name: String,
source: Box<dyn Error + Send + Sync>,
},
RetryExhausted {
attempts: u32,
last_error: Box<LlmError>,
},
Timeout {
elapsed_ms: u64,
},
MaxDepthExceeded {
current: u32,
limit: u32,
},
}Expand description
The unified error type returned by all provider operations.
Variants are #[non_exhaustive] — new error kinds may be added in
minor releases without breaking downstream matches (always include a
wildcard arm).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Http
An HTTP-level failure (transport error, unexpected status code).
status is None when the request never received a response
(e.g. DNS failure, connection reset).
Fields
status: Option<StatusCode>The HTTP status code, if one was received.
Auth(String)
The API key or token was rejected.
InvalidRequest(String)
The request was malformed (missing fields, invalid parameters).
Provider
A provider-specific error that doesn’t map to another variant.
Fields
ResponseFormat
The response body could not be parsed.
Fields
SchemaValidation
A structured-output response failed JSON Schema validation.
Fields
ToolExecution
A tool invocation raised an error.
Fields
RetryExhausted
A retry policy exhausted its budget without a successful response.
Fields
Timeout
The operation exceeded its deadline.
MaxDepthExceeded
A nested tool loop exceeded the maximum allowed depth.
This occurs when tool_loop is called recursively (e.g., a tool
spawning a sub-agent) and the nesting depth exceeds max_depth
in ToolLoopConfig.
Implementations§
Source§impl LlmError
impl LlmError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Returns true if the error is transient and the request may succeed on retry.
Useful for retry interceptors. This checks the retryable flag
on applicable variants and treats timeouts as always retryable.
§Example
use llm_stack::LlmError;
let err = LlmError::Timeout { elapsed_ms: 5000 };
assert!(err.is_retryable());
let err = LlmError::Auth("bad key".into());
assert!(!err.is_retryable());Trait Implementations§
Source§impl Error for LlmError
impl Error for LlmError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl Freeze for LlmError
impl !RefUnwindSafe for LlmError
impl Send for LlmError
impl Sync for LlmError
impl Unpin for LlmError
impl !UnwindSafe for LlmError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.