HKUDS/Vibe-Trading · error · ValueError
{name} must be finite
Error message
{name} must be finite What it means
Thrown by _required_float when a required parameter converts to float but is NaN or ±Infinity (math.isfinite fails). JSON cannot legally carry these, but Python float('nan'), parsed 'NaN' strings, or division artifacts can reach the tool. Payoff math over infinite spots is meaningless, so it's rejected.
Source
Thrown at agent/src/tools/options_payoff_tool.py:267
raw_premium = item.get("premium")
try:
premium = None if raw_premium is None else float(raw_premium)
except (TypeError, ValueError, OverflowError) as exc:
raise ValueError(f"legs[{index}].premium must be numeric or null") from exc
legs.append(OptionLeg(option_type, strike, qty, premium))
return legs
def _required_float(kwargs: dict[str, Any], name: str) -> float:
"""Read a required finite float."""
if name not in kwargs or kwargs[name] is None or kwargs[name] == "":
raise ValueError(f"{name} is required")
try:
value = float(kwargs[name])
except (TypeError, ValueError, OverflowError) as exc:
raise ValueError(f"{name} must be numeric") from exc
if not math.isfinite(value):
raise ValueError(f"{name} must be finite")
return value
def _optional_float(kwargs: dict[str, Any], name: str, default: float) -> float:
"""Read an optional finite float, treating null and empty text as omitted."""
raw = kwargs.get(name)
if raw is None or raw == "":
return default
try:
value = float(raw)
except (TypeError, ValueError, OverflowError) as exc:
raise ValueError(f"{name} must be numeric") from exc
if not math.isfinite(value):
raise ValueError(f"{name} must be finite")
return value
def _spot_points(raw: Any) -> int:View on GitHub (pinned to 80ffdda44c)
Solutions
- Check math.isfinite upstream and substitute a real value or abort with a clear error
- Avoid json.dumps(..., allow_nan=True) round-trips; use null for missing
- Log which parameter was non-finite before calling the tool
Example fix
// before
spot = compute_spot() # may be nan
execute({"legs": legs, "entry_spot": spot})
// after
spot = compute_spot()
if spot is None or not math.isfinite(spot):
raise ValueError("upstream spot missing")
execute({"legs": legs, "entry_spot": spot}) Defensive patterns
Strategy: validation
Validate before calling
import math
for k, v in kwargs.items():
if isinstance(v, float) and not math.isfinite(v):
raise ValueError(f"{k} is not finite") Type guard
def all_numeric_kwargs_finite(kwargs: dict) -> bool:
return all(math.isfinite(v) for v in kwargs.values() if isinstance(v, float)) Try / catch
try:
execute(kwargs)
except ValueError as e:
if "must be finite" in str(e):
substitute_or_refetch_parameter(e) Prevention
- Use json.dumps default (allow_nan=False) to catch NaN early
- Treat missing data as None, never NaN
- Assert finiteness after risky arithmetic upstream
When it happens
Trigger: entry_spot=float('nan') from a failed upstream computation; parsing 'Infinity' via json.loads with default settings; 0/0 ratios forwarded as volatility input.
Common situations: Data pipelines where upstream math produced NaN silently; permissive JSON parsers accepting NaN/Infinity literals; missing data encoded as NaN instead of null.
Related errors
- amount must be a finite number, got {self.amount!r}; a missi
- {alpha_id}: output >95% NaN (nan_ratio={nan_ratio:.3f})
- portfolio_weights contains non-finite values
- exposures contains non-finite values
- T must be > 0 to imply a volatility, got {T}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/5936dd03712c059a.
Report an issue: GitHub.