Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Usage validation

Enforce count relationships, null handling, and checked arithmetic at the usage boundary.

developer

Usage normalization rejects unrepresentable provider values before a response or terminal stream result is published.

Rules

usagenorm.Count accepts bounded nonnegative integer values and distinguishes missing/null fields from zero. Normalization rejects negative, fractional, and out-of-range values. Cache-read and cache-creation subsets must not exceed gross input. content.Usage.Validate is deprecated and no decoder calls it: the reasoning-within-output relationship is now the predicate content.Usage.ReasoningWithinOutput, and nothing gates on it. ContextTokens, TotalTokens, and Add use checked addition.

Errors

var err error // set by a codec decoder
var normalizeErr *inferenceusage.UsageNormalizationError
if errors.As(err, &normalizeErr) {
	fmt.Println(normalizeErr.Field, normalizeErr.Reason)
}

No raw provider body or model output is stored in these errors. A decoder returns the error and does not publish a partially normalized value.

Source and proof

Run go test ./internal/usagenorm ./usage and go test in the core module for domain validation.

← back to documentation