errorclassify

package
v0.194.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0, MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package errorclassify provides structured error classification for LLM provider failures. It replaces ad-hoc string matching with a taxonomy mirroring hermes-agent's error_classifier.py.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsContextOverflow

func IsContextOverflow(err error, meta ErrorMeta) bool

IsContextOverflow is a convenience wrapper that classifies an error and returns true if the reason is ReasonContextOverflow.

Types

type ClassifiedError

type ClassifiedError struct {
	Reason ErrorReason
	Meta   ErrorMeta

	// Recovery hints
	Retryable                bool // can safely retry after backoff
	ShouldCompress           bool // compress context before retrying
	ShouldRotateCred         bool // switch to a different credential / fallback provider
	ShouldStripReasoning     bool // strip ReasoningContent from all assistant messages and retry
	ShouldDropResponseFormat bool // provider rejects response_format — drop it and retry
	ShouldAbort              bool // surface error to user immediately (no fallback)

	Message string // human-readable classification summary (for logs)
}

ClassifiedError is the result of error classification with concrete recovery hints. The retry loop acts on these hints — it never re-classifies the raw error.

func Classify

func Classify(err error, meta ErrorMeta) ClassifiedError

Classify maps a provider error to a ClassifiedError with recovery hints. Priority order: typed status/code → status code → error-code string → message patterns → transport heuristics → unknown.

func (ClassifiedError) Error

func (c ClassifiedError) Error() string

type ErrorMeta

type ErrorMeta struct {
	StatusCode  int    // HTTP status code (0 if unknown)
	Provider    string // e.g. "openrouter", "anthropic"
	Model       string // e.g. "claude-sonnet-4"
	NumMessages int    // number of messages in the request

	// ProviderSwapped reports that a fallback swap occurred earlier in
	// this run. A thinking-mode endpoint demanding replayed thinking
	// blocks cannot consume history produced by a different provider —
	// reasoning_content-bearing turns from the primary are absent, and on
	// the OpenAI-compatible path signatures are never captured at all —
	// so the classifier must not hand out the config-fix advice for a
	// failure that only a session restart on the swapped-in provider can
	// fix (yaah-31j).
	ProviderSwapped bool
}

ErrorMeta is the context available to the classifier at the call site.

type ErrorReason

type ErrorReason int

ErrorReason identifies the category of a provider failure.

const (
	ReasonUnknown                 ErrorReason = iota // unclassifiable — retry with backoff
	ReasonAuth                                       // 401/403 — refresh/rotate credentials
	ReasonAuthPermanent                              // auth failed after rotation — abort
	ReasonBilling                                    // 402/credit exhaustion — rotate immediately
	ReasonRateLimit                                  // 429/quota — backoff then rotate
	ReasonOverloaded                                 // 503/529 — provider overloaded, backoff
	ReasonServerError                                // 500/502 — internal server error, retry
	ReasonTimeout                                    // connection/read timeout — retry
	ReasonContextOverflow                            // context window exceeded — compress
	ReasonOutputBudget                               // max_tokens exhausted before content — raise cap
	ReasonPayloadTooLarge                            // 413 — compress payload
	ReasonModelNotFound                              // 404/invalid model — fallback to different model
	ReasonContentPolicyBlocked                       // safety filter — do NOT retry unchanged
	ReasonProviderPolicyBlocked                      // aggregator data/privacy block
	ReasonFormatError                                // 400 bad request — abort or strip+retry
	ReasonReasoningContentMissing                    // reasoning_content rejected — strip and retry
	ReasonThinkingModeRequired                       // thinking mode required but reasoning_content omitted — set thinking: true
)

func (ErrorReason) String

func (r ErrorReason) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL