HKUDS/Vibe-Trading · error · ValueError

valuations[{index}] needs both 'date' and 'value'

Error message

valuations[{index}] needs both 'date' and 'value'

What it means

Raised by _coerce_valuations when an entry in the valuations array passed to the cashflow analytics tool is missing the 'date' key or the 'value' key. Every valuation must be an object carrying both fields so the tool can build (date, value) pairs for time-series calculations like TWR/XIRR. Anything else is rejected before any math runs.

Source

Thrown at agent/src/tools/cashflow_analytics_tool.py:326

    Returns:
        Pairs in the order supplied; the library sorts and validates them.

    Raises:
        ValueError: If the array is missing, wrongly shaped, over the size cap,
            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.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Ensure every element of valuations is an object with both 'date' and 'value' keys, e.g. {"date": "2024-01-01", "value": 1000.0}
  2. Check for misspelled or differently-cased keys in the payload
  3. If a valuation is genuinely unknown, drop that entry rather than sending a partial object

Example fix

// before
valuations=[{"date": "2024-01-01"}, {"value": 500}]
// after
valuations=[{"date": "2024-01-01", "value": 500}]
Defensive patterns

Strategy: validation

Validate before calling

required = {"date", "value"}
if not all(isinstance(v, dict) and required <= v.keys() for v in valuations):
    raise ValueError("each valuation needs date and value")

Type guard

from typing import TypeGuard

def is_valuation(item: object) -> TypeGuard[dict]:
    return isinstance(item, dict) and "date" in item and "value" in item

Prevention

When it happens

Trigger: Calling the tool's execute with valuations=[{"value": 100}] or [{"date": "2024-01-01"}], or a valuation dict built dynamically where a key is misspelled ('Date', 'valuation', 'val') or omitted.

Common situations: LLM/agent-generated argument payloads that omit optional-looking fields; JSON payload keys differing in case; partial data from an upstream API where some rows lack a valuation.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/9c485fbb6179e159. Report an issue: GitHub.