HKUDS/Vibe-Trading · error · ValueError
valuations[{index}].value must be finite
Error message
valuations[{index}].value must be finite What it means
Raised when a valuation's value coerces to a float that is not finite (NaN, +inf, -inf, per math.isfinite). Infinite or NaN results poison every downstream statistic, so the tool rejects them upfront.
Source
Thrown at agent/src/tools/cashflow_analytics_tool.py:332
or an entry lacks a usable date or value.
"""
if not isinstance(raw, list) or len(raw) < 2:
raise ValueError("valuations must be an array of at least two {date, value} objects")
if len(raw) > _MAX_VALUATIONS:
raise ValueError(f"valuations may contain at most {_MAX_VALUATIONS} entries")
pairs: list[tuple[date, float]] = []
for index, item in enumerate(raw):
if not isinstance(item, dict):
raise ValueError(f"valuations[{index}] must be an object with date and value")
if "date" not in item or "value" not in item:
raise ValueError(f"valuations[{index}] needs both 'date' and 'value'")
try:
value = float(item["value"])
except (TypeError, ValueError) as exc:
raise ValueError(f"valuations[{index}].value must be numeric") from exc
if not math.isfinite(value):
raise ValueError(f"valuations[{index}].value must be finite")
pairs.append((item["date"], value))
return pairs
def _resolve_flows(kwargs: dict[str, Any]) -> CashFlowSeries | None:
"""Build the cash-flow series from inline records or from a file.
Args:
kwargs: The tool's raw inputs.
Returns:
A ``CashFlowSeries``, or ``None`` when no flows were supplied.
Raises:
ValueError: If both sources were given, an inline record is malformed,
or a currency is missing. File problems surface as
``CashFlowIngestError``, which is a ``ValueError``.
"""View on GitHub (pinned to 80ffdda44c)
Solutions
- Filter out non-finite values before calling the tool (e.g. filter out NaN from pandas series with .dropna())
- Fix the upstream division-by-zero or overflow producing inf/NaN
- Use json.dumps(..., allow_nan=False) upstream to catch these at serialization time
Example fix
# before
valuations = series.to_dict() # may include NaN
# after
valuations = [{"date": d, "value": float(v)} for d, v in series.dropna().items()] Defensive patterns
Strategy: validation
Validate before calling
import math valuations = [v for v in valuations if math.isfinite(float(v["value"]))]
Type guard
import math
def is_finite_value(item: dict) -> bool:
try:
return math.isfinite(float(item["value"]))
except (TypeError, ValueError):
return False Prevention
- dropna() pandas series before serialization
- Use allow_nan=False in json.dumps upstream to fail early
- Guard upstream divisions against zero
When it happens
Trigger: valuations=[{"date": "2024-01-01", "value": "NaN"}] or value="Infinity" (float() accepts these strings in Python), or a computed value that overflowed to inf before being passed in.
Common situations: Aggregations that divided by zero upstream, pandas/NumPy pipelines emitting NaN for missing data then serializing to JSON, or literal 'NaN'/'Infinity' tokens in JSON payloads (Python json.loads accepts them).
Related errors
- valuations[{index}] needs both 'date' and 'value'
- valuations[{index}].value must be numeric
- pass either flows or flows_path, not both
- flows_columns must be an object mapping field to column name
- flows must be an array of {date, amount, kind} objects
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/089cbe31abafca0d.
Report an issue: GitHub.