HKUDS/Vibe-Trading · error · ValueError
flows[{index}] is missing {exc.args[0]!r}
Error message
flows[{index}] is missing {exc.args[0]!r} What it means
While constructing a CashFlow from a flow dict, a required key ('date', 'amount', or 'kind') was absent and raised KeyError, which is re-raised with the flow's index and the missing key name. This is a per-row field-level validation failure, distinct from shape/type errors.
Source
Thrown at agent/src/tools/cashflow_analytics_tool.py:397
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))
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.
"""View on GitHub (pinned to 80ffdda44c)
Solutions
- Add the missing key named in the error message (the !r in the message shows exactly which key is absent)
- Normalize keys to lowercase {date, amount, kind} before calling
Example fix
# before
{"date": "2024-01-01", "amount": 100, "currency": "USD"}
# after
{"date": "2024-01-01", "amount": 100, "kind": "inflow", "currency": "USD"} Defensive patterns
Strategy: validation
Validate before calling
required = {"date", "amount", "kind"}
missing = [i for i, f in enumerate(flows) if not required <= f.keys()]
if missing:
raise ValueError(f"flows missing required keys at indices {missing}") Type guard
from typing import TypeGuard
def is_complete_flow(item: dict) -> TypeGuard[dict]:
return {"date", "amount", "kind"} <= item.keys() Try / catch
try:
result = tool.execute(**kwargs)
except ValueError as exc:
if "is missing" in str(exc):
key = exc.args[0].split("'")[1] # patch payload and retry
raise Prevention
- Normalize key casing to lowercase snake_case before calling
- Test payload builders against the required-key set
When it happens
Trigger: flows=[{"date": "2024-01-01", "amount": 100}] missing 'kind'; misspelled keys like "amt" or "Date" so item["amount"]/item["date"] misses.
Common situations: Key casing mismatches between the data source and the tool schema; optional-looking fields omitted in sparse records; LLM tool calls trimming fields it deemed optional.
Related errors
- flows must be an array of {date, amount, kind} objects
- flows may contain at most {_MAX_INLINE_FLOWS} entries
- flows[{index}] must be an object
- flows[{index}] has no currency and no top-level currency was
- valuations[{index}] needs both 'date' and 'value'
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/937d2bf5679e7910.
Report an issue: GitHub.