llm-error-class 0.1.0

Classify LLM provider error responses (rate-limit, auth, server, context-window, content-policy, malformed). Anthropic, OpenAI, Google, AWS Bedrock. Zero deps.
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented1 out of 4 items with examples
  • Size
  • Source code size: 26.48 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 336.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • MukundaKatta/llm-error-class
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MukundaKatta

llm-error-class

crates.io docs.rs

Classify LLM provider error responses into a small enum of retriable vs. terminal kinds. Covers Anthropic, OpenAI, Google Gemini, and AWS Bedrock. Zero deps.

Why

Every retry-wrapper you write needs the same logic: is this a 5xx I should back off on, a 429 I should slow down for, or a 400 that means "don't try this again"? Provider error shapes are inconsistent. classify(status, body) gives you one answer.

Usage

use llm_error_class::{classify, ErrorClass};

let body = r#"{"error":{"type":"rate_limit_error","message":"slow down"}}"#;
let kind = classify(429, body);
assert_eq!(kind, ErrorClass::RateLimit);

if kind.is_retriable() {
    // back off and retry
}

Classes

Class Retriable Examples
RateLimit yes HTTP 429, rate_limit_error, ThrottlingException
Overloaded yes Anthropic overloaded_error, ServiceUnavailableException
Server yes 5xx with no specific body
Timeout yes 408, body contains "timed out"
Auth no 401, 403, "invalid api key"
ContextWindow no context_length_exceeded, "maximum context length"
ContentPolicy no content_filter, "safety"
Malformed no 400 + validation / bad request
NotFound no 404, "model not found"
BillingQuota no 402, insufficient_quota, "billing"
Unknown no anything we don't recognize

Features

  • serde — derive Serialize/Deserialize on ErrorClass (useful for logging).

License

MIT or Apache-2.0.