Skip to main content

LlmError

Enum LlmError 

Source
#[non_exhaustive]
pub enum LlmError {
Show 20 variants Http(Error), Json(Error), Io(Error), RateLimited, Unavailable, EmptyResponse { provider: String, }, SseParse(String), EmbedUnsupported { provider: String, }, ModelLoad(String), Inference(String), NoRoute, NoProviders, StructuredParse(String), TranscriptionFailed(String), ContextLengthExceeded, Timeout, BetaHeaderRejected { header: String, }, InvalidInput { provider: String, message: String, }, ApiError { provider: String, status: u16, }, Other(String),
}
Expand description

Errors that can occur in any crate::provider::LlmProvider operation.

Use the predicate methods (is_rate_limited, is_context_length_error, is_invalid_input, is_beta_header_rejected) to classify errors before deciding whether to retry, fall back, or propagate.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Http(Error)

Underlying HTTP transport error (connection refused, TLS failure, etc.).

§

Json(Error)

The API returned a response that could not be decoded as valid JSON.

§

Io(Error)

An I/O error occurred (e.g. reading or writing a cache file).

§

RateLimited

The provider returned HTTP 429 (too many requests). Callers should back off and retry.

§

Unavailable

The provider is temporarily unavailable (HTTP 5xx or connection error).

§

EmptyResponse

The provider returned a successful HTTP status but no content in the response body.

Fields

§provider: String
§

SseParse(String)

A Server-Sent Events frame could not be parsed.

§

EmbedUnsupported

crate::provider::LlmProvider::embed was called on a provider that does not support embedding generation.

Fields

§provider: String
§

ModelLoad(String)

Candle model weights or tokenizer could not be loaded from disk or HuggingFace Hub.

§

Inference(String)

The Candle inference worker returned an error or timed out.

§

NoRoute

The crate::router::RouterProvider has no providers configured.

§

NoProviders

All providers in a router have been exhausted without a successful response.

§

StructuredParse(String)

crate::provider::LlmProvider::chat_typed could not parse the model’s response as the requested type, even after a retry.

§

TranscriptionFailed(String)

The speech-to-text backend rejected the audio or returned an error.

§

ContextLengthExceeded

The prompt exceeds the model’s maximum context window. Do not retry with the same input on another provider — the same input will fail there too. Summarize or truncate first.

§

Timeout

The request exceeded the configured per-call timeout.

§

BetaHeaderRejected

A beta header sent in the request was rejected by the API (e.g. compact-2026-01-12 deprecated or not yet available). The provider has already disabled the feature internally; the caller should retry without it.

Fields

§header: String
§

InvalidInput

The input itself is invalid (HTTP 400). Retrying with the same input on another provider will not help — the router should break the fallback loop immediately.

Fields

§provider: String
§message: String
§

ApiError

A provider returned a non-success HTTP status that does not map to any more specific variant.

This covers non-retriable API failures such as authentication errors (401/403), server errors (500/503), and unexpected 4xx responses that are not InvalidInput, RateLimited, or ContextLengthExceeded. Callers should not retry on this error.

Fields

§provider: String
§status: u16
§

Other(String)

Catch-all for provider-specific errors that do not yet have a typed variant.

§Deprecation

Prefer adding a typed variant or propagating a specific source error. This variant exists for backward compatibility and will be removed once all callsites are migrated.

Implementations§

Source§

impl LlmError

Source

pub fn is_context_length_error(&self) -> bool

Returns true if this error indicates the context/prompt is too long for the model.

Providers must return LlmError::ContextLengthExceeded directly; this predicate does not inspect error message strings.

Source

pub fn is_beta_header_rejected(&self) -> bool

Returns true if this error indicates that a beta header was rejected by the API.

Source

pub fn is_invalid_input(&self) -> bool

Returns true if this error indicates that the input itself is invalid (HTTP 400).

Callers (e.g. the router fallback loop) should not retry with a different provider when this is true — the same input will fail there too.

Source

pub fn is_rate_limited(&self) -> bool

Trait Implementations§

Source§

impl Debug for LlmError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LlmError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for LlmError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for LlmError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for LlmError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for LlmError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more