HKUDS/Vibe-Trading · error · ValueError
{name} must be numeric
Error message
{name} must be numeric What it means
Thrown by _required_float when a required parameter is present but float() conversion fails — the value is a non-numeric string, a list/dict, or an unparseable type. Distinct from the 'is required' error: the key exists, its value just isn't a number.
Source
Thrown at agent/src/tools/options_payoff_tool.py:265
raise ValueError(f"legs[{index}].qty must be a non-zero integer")
qty = int(qty_number)
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
View on GitHub (pinned to 80ffdda44c)
Solutions
- Convert to a plain float before the call
- Strip non-numeric characters and re-validate: float(re.sub(r'[^0-9.\-eE]', '', str(raw)))
- Use strict numeric input types in the calling form/schema
Example fix
// before
execute({"legs": legs, "entry_spot": "$105.20"})
// after
execute({"legs": legs, "entry_spot": 105.20}) Defensive patterns
Strategy: validation
Validate before calling
try:
kwargs["entry_spot"] = float(kwargs["entry_spot"])
except (TypeError, ValueError, OverflowError):
raise ValueError("entry_spot must be numeric") Type guard
def coercible_to_float(v) -> bool:
try: float(v); return True
except (TypeError, ValueError, OverflowError): return False Try / catch
try:
execute(kwargs)
except ValueError as e:
if "must be numeric" in str(e):
kwargs[name] = parse_number_from_text(kwargs[name]) Prevention
- Coerce numerics at the boundary of your app
- Use number-typed form fields
- Locale-normalize decimal strings before conversion
When it happens
Trigger: entry_spot="100 USD", entry_spot=[100], entry_iv={"value":0.2}, or any object whose __float__ raises.
Common situations: Unparsed strings from chat/UI input; structured wrappers around scalars; locale-formatted numbers ('1.000,5').
Related errors
- legs[{index}] has invalid strike or qty: {exc}
- legs[{index}].premium must be numeric or null
- invalid period: {exc}
- T must be > 0 to imply a volatility, got {T}
- legs must be a non-empty array
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/d73156f4a1fe5780.
Report an issue: GitHub.