HKUDS/Vibe-Trading · error · ValueError

flows[{index}] has no currency and no top-level currency was

Error message

flows[{index}] has no currency and no top-level currency was given; currency is never defaulted

What it means

Currency is required per cash flow and is never defaulted. A flow must carry a non-empty 'currency' field, or a top-level currency argument must be supplied; if both are absent this indexed error is raised. This prevents silently mixing or inventing currencies in financial calculations.

Source

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

            default_kind=kwargs.get("flows_default_kind"),
            date_format=kwargs.get("flows_date_format"),
            invert_sign=bool(kwargs.get("flows_invert_sign", False)),
        )

    if not inline:
        return None
    if not isinstance(inline, list):
        raise ValueError("flows must be an array of {date, amount, kind} objects")
    if len(inline) > _MAX_INLINE_FLOWS:
        raise ValueError(f"flows may contain at most {_MAX_INLINE_FLOWS} entries")

    records: list[CashFlow] = []
    for index, item in enumerate(inline):
        if not isinstance(item, dict):
            raise ValueError(f"flows[{index}] must be an object")
        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))

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pass a top-level currency (e.g. execute(..., currency="USD")) when all flows share one currency
  2. Add 'currency' to each flow dict for mixed-currency data
  3. Ensure env-var lookups have a real fallback value, not None

Example fix

# before
execute(flows=flows)
# after
execute(flows=flows, currency="EUR")
Defensive patterns

Strategy: validation

Validate before calling

currency = kwargs.get("currency") or "USD"  # explicit choice
for f in flows:
    f.setdefault("currency", currency)
if not all(f.get("currency") for f in flows):
    raise ValueError("currency required per flow")

Type guard

def has_currency(item: dict, top_currency: str | None) -> bool:
    return bool(item.get("currency") or top_currency)

Prevention

When it happens

Trigger: flows=[{"date": ..., "amount": ..., "kind": ...}] with no per-item currency and no kwargs['currency']; currency=None or currency="" at top level.

Common situations: Assuming a default like USD exists; configs where currency is only conditionally set (currency=os.getenv("CURRENCY") returning None); mixed-currency datasets where only some rows carry currency.

Related errors


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