JuliusBrussee/caveman · error · CatalogError

: pricing. must be finite and nonnegative

Error message

{label}: pricing.{field} must be finite and nonnegative

What it means

After type-checking, each numeric pricing field must be a finite (not NaN/Infinity) nonnegative number. math.isfinite rejects NaN, +inf and -inf; negative values are rejected because prices cannot be negative.

Solutions

  1. Replace NaN/Infinity with a concrete finite number
  2. Remove any minus sign / make the value nonnegative (use 0 if free)
  3. Fix the upstream calculation that produced the non-finite or negative value

Example fix

// before
pricing:
  output_per_million: -0.5
// after
pricing:
  output_per_million: 0.5
Defensive patterns

Strategy: validation

Validate before calling

import math
for k, v in pricing.items():
    if isinstance(v, (int, float)) and not isinstance(v, bool):
        assert math.isfinite(v) and v >= 0, k

Type guard

def is_finite_nonneg(v):
    return isinstance(v, (int, float)) and not isinstance(v, bool) and math.isfinite(v) and v >= 0

Try / catch

try:
    validate_catalog(rows)
except CatalogError as e:
    if "finite and nonnegative" in str(e):
        sanitize_pricing_values(rows)
    raise

Prevention

When it happens

Trigger: A pricing field is -1, NaN, Infinity/-Infinity, or the result of a computation that overflowed to inf.

Common situations: Hand-entering NaN or Infinity in JSON (invalid JSON anyway) or YAML (.nan/.inf are valid); a discount calculation going negative; float division by zero upstream producing inf.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/ecd660351a1b12af. Report an issue: GitHub.

Appendix: source

Thrown at shared/provider-catalog/validate_catalog.py:150

    pricing = row["pricing"]
    if not isinstance(pricing, dict):
        raise CatalogError(f"{label}: pricing must be an object")
    pricing_unknown = set(pricing) - PRICING_KEYS
    if pricing_unknown:
        raise CatalogError(f"{label}: unknown pricing field(s): {', '.join(sorted(pricing_unknown))}")
    for required in ("input_per_million", "output_per_million"):
        if required not in pricing:
            raise CatalogError(f"{label}: pricing.{required} is required")
    for field, value in pricing.items():
        if value is None or field == "long_context_threshold_inclusive":
            if field == "long_context_threshold_inclusive" and value is not None and not isinstance(value, bool):
                raise CatalogError(f"{label}: pricing.{field} must be boolean or null")
            continue
        if isinstance(value, bool) or not isinstance(value, (int, float)):
            raise CatalogError(f"{label}: pricing.{field} must be numeric or null")
        if not math.isfinite(value) or value < 0:
            raise CatalogError(f"{label}: pricing.{field} must be finite and nonnegative")
        if field == "batch_discount_fraction" and value > 1:
            raise CatalogError(f"{label}: pricing.batch_discount_fraction must be <= 1")

    if not isinstance(row["capabilities"], dict):
        raise CatalogError(f"{label}: capabilities must be an object")
    sources = row["sources"]
    if not isinstance(sources, list) or not sources:
        raise CatalogError(f"{label}: sources must be a non-empty list")
    if any(not isinstance(source, str) or not source.startswith("https://") for source in sources):
        raise CatalogError(f"{label}: every source must be HTTPS")

    verified_at = parsed_time(row["verified_at"], label)
    if verified_at > now:
        raise CatalogError(f"{label}: verified_at is in the future")
    if verified_at < now - timedelta(days=120):
        raise CatalogError(f"{label}: verified_at is older than 120 days")
    return identity[0], identity[1], identity[2]

View on GitHub (pinned to 3ee70a1026)