{"record":{"id":"9c485fbb6179e159","repo":"HKUDS/Vibe-Trading","slug":"valuations-index-needs-both-date-and-value","errorCode":null,"errorMessage":"valuations[{index}] needs both 'date' and 'value'","messagePattern":"valuations\\[(.+?)\\] needs both 'date' and 'value'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/cashflow_analytics_tool.py","lineNumber":326,"sourceCode":"\n    Returns:\n        Pairs in the order supplied; the library sorts and validates them.\n\n    Raises:\n        ValueError: If the array is missing, wrongly shaped, over the size cap,\n            or an entry lacks a usable date or value.\n    \"\"\"\n    if not isinstance(raw, list) or len(raw) < 2:\n        raise ValueError(\"valuations must be an array of at least two {date, value} objects\")\n    if len(raw) > _MAX_VALUATIONS:\n        raise ValueError(f\"valuations may contain at most {_MAX_VALUATIONS} entries\")\n\n    pairs: list[tuple[date, float]] = []\n    for index, item in enumerate(raw):\n        if not isinstance(item, dict):\n            raise ValueError(f\"valuations[{index}] must be an object with date and value\")\n        if \"date\" not in item or \"value\" not in item:\n            raise ValueError(f\"valuations[{index}] needs both 'date' and 'value'\")\n        try:\n            value = float(item[\"value\"])\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"valuations[{index}].value must be numeric\") from exc\n        if not math.isfinite(value):\n            raise ValueError(f\"valuations[{index}].value must be finite\")\n        pairs.append((item[\"date\"], value))\n    return pairs\n\n\ndef _resolve_flows(kwargs: dict[str, Any]) -> CashFlowSeries | None:\n    \"\"\"Build the cash-flow series from inline records or from a file.\n\n    Args:\n        kwargs: The tool's raw inputs.\n\n    Returns:\n        A ``CashFlowSeries``, or ``None`` when no flows were supplied.","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/cashflow_analytics_tool.py#L308-L344","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure every element of valuations is an object with both 'date' and 'value' keys, e.g. {\"date\": \"2024-01-01\", \"value\": 1000.0}","Check for misspelled or differently-cased keys in the payload","If a valuation is genuinely unknown, drop that entry rather than sending a partial object"],"exampleFix":"// before\nvaluations=[{\"date\": \"2024-01-01\"}, {\"value\": 500}]\n// after\nvaluations=[{\"date\": \"2024-01-01\", \"value\": 500}]","handlingStrategy":"validation","validationCode":"required = {\"date\", \"value\"}\nif not all(isinstance(v, dict) and required <= v.keys() for v in valuations):\n    raise ValueError(\"each valuation needs date and value\")","typeGuard":"from typing import TypeGuard\n\ndef is_valuation(item: object) -> TypeGuard[dict]:\n    return isinstance(item, dict) and \"date\" in item and \"value\" in item","tryCatchPattern":null,"preventionTips":["Validate valuation objects before assembling the tool call","Use consistent lowercase key names","Add a schema check in tests that build valuations payloads"],"tags":["cashflow-analytics","valuations","input-validation","python"],"backgroundTag":"required-field-missing","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}