Documentation / guides
Counting errors
Inspect typed count, model, encoding, capability, and compatibility failures.
Count failures preserve bounded classifications without retaining request bytes.
Inspect them with errors.As and errors.Is.
Types
| Error | Meaning |
|---|---|
EstimatorStateError | nil estimator or nil context |
ModelIdentityError | invalid model key or identity |
UnsupportedAPIFormatError | no bundled estimator encoder |
RequestEncodingError | selected codec rejected the request |
ContextCountError | callback missing, canceled, model/quality mismatch, or wrapped cause |
CapabilityValidationError | malformed capability metadata |
CounterCompatibilityError | counter weakens inference trust posture |
ContextCountError.Unwrap exposes the safe cause. The errors do not include
raw request bodies or provider response content.
Inspection
var unsupported *contextcount.UnsupportedAPIFormatError
var encoding *contextcount.RequestEncodingError
switch {
case errors.As(err, &unsupported):
// choose an exact provider counter or reject admission
case errors.As(err, &encoding):
// fix the request or use a dialect that represents it
}
Source and proof
Run go test ./contextcount.