{"record":{"id":"ecd660351a1b12af","repo":"JuliusBrussee/caveman","slug":"label-pricing-field-must-be-finite-and-nonneg","errorCode":null,"errorMessage":"{label}: pricing.{field} must be finite and nonnegative","messagePattern":"(.+?): pricing\\.(.+?) must be finite and nonnegative","errorType":"validation","errorClass":"CatalogError","httpStatus":null,"severity":"error","filePath":"shared/provider-catalog/validate_catalog.py","lineNumber":150,"sourceCode":"\n    pricing = row[\"pricing\"]\n    if not isinstance(pricing, dict):\n        raise CatalogError(f\"{label}: pricing must be an object\")\n    pricing_unknown = set(pricing) - PRICING_KEYS\n    if pricing_unknown:\n        raise CatalogError(f\"{label}: unknown pricing field(s): {', '.join(sorted(pricing_unknown))}\")\n    for required in (\"input_per_million\", \"output_per_million\"):\n        if required not in pricing:\n            raise CatalogError(f\"{label}: pricing.{required} is required\")\n    for field, value in pricing.items():\n        if value is None or field == \"long_context_threshold_inclusive\":\n            if field == \"long_context_threshold_inclusive\" and value is not None and not isinstance(value, bool):\n                raise CatalogError(f\"{label}: pricing.{field} must be boolean or null\")\n            continue\n        if isinstance(value, bool) or not isinstance(value, (int, float)):\n            raise CatalogError(f\"{label}: pricing.{field} must be numeric or null\")\n        if not math.isfinite(value) or value < 0:\n            raise CatalogError(f\"{label}: pricing.{field} must be finite and nonnegative\")\n        if field == \"batch_discount_fraction\" and value > 1:\n            raise CatalogError(f\"{label}: pricing.batch_discount_fraction must be <= 1\")\n\n    if not isinstance(row[\"capabilities\"], dict):\n        raise CatalogError(f\"{label}: capabilities must be an object\")\n    sources = row[\"sources\"]\n    if not isinstance(sources, list) or not sources:\n        raise CatalogError(f\"{label}: sources must be a non-empty list\")\n    if any(not isinstance(source, str) or not source.startswith(\"https://\") for source in sources):\n        raise CatalogError(f\"{label}: every source must be HTTPS\")\n\n    verified_at = parsed_time(row[\"verified_at\"], label)\n    if verified_at > now:\n        raise CatalogError(f\"{label}: verified_at is in the future\")\n    if verified_at < now - timedelta(days=120):\n        raise CatalogError(f\"{label}: verified_at is older than 120 days\")\n    return identity[0], identity[1], identity[2]\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/provider-catalog/validate_catalog.py#L132-L168","documentation":"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.","triggerScenarios":"A pricing field is -1, NaN, Infinity/-Infinity, or the result of a computation that overflowed to inf.","commonSituations":"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.","solutions":["Replace NaN/Infinity with a concrete finite number","Remove any minus sign / make the value nonnegative (use 0 if free)","Fix the upstream calculation that produced the non-finite or negative value"],"exampleFix":"// before\npricing:\n  output_per_million: -0.5\n// after\npricing:\n  output_per_million: 0.5","handlingStrategy":"validation","validationCode":"import math\nfor k, v in pricing.items():\n    if isinstance(v, (int, float)) and not isinstance(v, bool):\n        assert math.isfinite(v) and v >= 0, k","typeGuard":"def is_finite_nonneg(v):\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and math.isfinite(v) and v >= 0","tryCatchPattern":"try:\n    validate_catalog(rows)\nexcept CatalogError as e:\n    if \"finite and nonnegative\" in str(e):\n        sanitize_pricing_values(rows)\n    raise","preventionTips":["Sanitize NaN/inf before writing the catalog","Clamp or reject negative computed prices","Add schema minimum: 0 constraints"],"tags":["validation","pricing","numeric","range"],"backgroundTag":"value-out-of-range","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}