HKUDS/Vibe-Trading · error · ValueError

flows[{index}]: {exc}

Error message

flows[{index}]: {exc}

What it means

Raised while converting each element of the `flows` argument into a CashFlow record: the per-flow dict either lacks a required key (KeyError wrapped as "flows[i] is missing 'field'") or one of its values fails conversion (e.g. a bad date or non-numeric amount), and the inner ValueError is re-raised prefixed with the flow's index. It is a tool-input schema validation error surfaced by the `execute` method.

Source

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

        row_currency = item.get("currency") or currency
        if not row_currency:
            raise ValueError(
                f"flows[{index}] has no currency and no top-level currency was "
                "given; currency is never defaulted"
            )
        try:
            records.append(
                CashFlow(
                    date=item["date"],
                    amount=item["amount"],
                    kind=item["kind"],
                    currency=row_currency,
                )
            )
        except KeyError as exc:
            raise ValueError(f"flows[{index}] is missing {exc.args[0]!r}") from exc
        except ValueError as exc:
            raise ValueError(f"flows[{index}]: {exc}") from exc
    return CashFlowSeries(tuple(records))


def _coerce_flow_timing(raw: Any) -> str:
    """Validate the flow-timing token.

    Args:
        raw: Value supplied for ``flow_timing``; ``None`` selects the default.

    Returns:
        Either :data:`~src.quantlib.performance.FLOW_TIMING_END` or
        :data:`~src.quantlib.performance.FLOW_TIMING_START`.

    Raises:
        ValueError: If the token is not one of the two recognised values.
    """
    if raw is None or raw == "":
        return FLOW_TIMING_END

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Inspect the error suffix: 'is missing X' names the absent key, otherwise the inner message names the bad value — fix flows[index] accordingly
  2. Log/pretty-print the offending flows[index] payload before retrying
  3. Add a pre-flight schema check that every flow dict contains the required keys with valid types before calling the tool

Example fix

// before
tool.execute(flows=[{"amount": 100.0}])  # missing date -> flows[0] is missing 'date'
// after
tool.execute(flows=[{"date": "2024-01-15", "amount": 100.0, "currency": "USD"}])
Defensive patterns

Strategy: validation

Validate before calling

REQUIRED = {"date", "amount", "currency"}
def valid_flows(flows):
    for i, f in enumerate(flows):
        missing = REQUIRED - set(f)
        if missing:
            return False, f"flows[{i}] missing {missing}"
        if not isinstance(f["amount"], (int, float)) or isinstance(f["amount"], bool):
            return False, f"flows[{i}].amount must be numeric"
    return True, ""

Type guard

from typing import Any, TypedDict

class Flow(TypedDict, total=False):
    date: str
    amount: float
    currency: str

def is_flow(x: Any) -> bool:
    return (
        isinstance(x, dict)
        and isinstance(x.get("date"), str)
        and isinstance(x.get("amount"), (int, float))
        and not isinstance(x.get("amount"), bool)
    )

Try / catch

try:
    result = tool.execute(flows=flows)
except ValueError as exc:
    if exc.args[0].startswith("flows["):
        idx = int(exc.args[0].split("[")[1].split("]")[0])
        log.warning("bad flow %d: %r -> %r", idx, exc.args[0], flows[idx])
        flows.pop(idx)  # or repair
        result = tool.execute(flows=flows)
    else:
        raise

Prevention

When it happens

Trigger: Calling the cashflow analytics tool with flows=[{...}] where a dict is missing a required key (e.g. no 'date' or 'amount'), or has a malformed value that raises ValueError inside the record constructor/coercion helpers.

Common situations: LLM/agent generates a flow dict with a typo'd or omitted field; callers build flows from pandas rows with NaN or missing columns; upstream data source drops optional-looking fields.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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