{"record":{"id":"54542b7e03632ca8","repo":"HKUDS/Vibe-Trading","slug":"outcome-has-no-matching-clob-token","errorCode":null,"errorMessage":"outcome has no matching CLOB token","messagePattern":"outcome has no matching CLOB token","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/prediction_market_tool.py","lineNumber":817,"sourceCode":"        raw = _clob_market_to_gamma_shape(payload) if isinstance(payload, dict) else {}\n    else:\n        raw = _get_json(f\"{_GAMMA_MARKETS_URL}/{identifier}\", host_key=_GAMMA_HOST_KEY)\n        if not isinstance(raw, dict):\n            raise ValueError(\"unexpected market payload shape\")\n\n    names = [str(n) for n in _json_list(raw.get(\"outcomes\"))]\n    tokens = [str(t) for t in _json_list(raw.get(\"clobTokenIds\"))]\n    if not tokens:\n        raise ValueError(\"market exposes no CLOB outcome tokens\")\n\n    index = 0\n    if outcome is not None:\n        matches = [i for i, n in enumerate(names) if n.lower() == outcome.lower()]\n        if not matches:\n            raise ValueError(f\"outcome '{outcome}' not in {names}\")\n        index = matches[0]\n    if index >= len(tokens):\n        raise ValueError(\"outcome has no matching CLOB token\")\n\n    return tokens[index], {\n        \"market_id\": str(raw.get(\"id\")) if raw.get(\"id\") is not None else None,\n        \"question\": raw.get(\"question\"),\n        \"condition_id\": raw.get(\"conditionId\"),\n        \"outcome\": names[index] if index < len(names) else None,\n        \"clob_token_id\": tokens[index],\n    }\n\n\ndef _fetch_history(\n    identifier: str, *, interval: str, outcome: str | None, max_points: int\n) -> dict[str, Any]:\n    \"\"\"Fetch one outcome's implied-probability time series.\n\n    Args:\n        identifier: CLOB token id, condition id, or gamma market id.\n        interval: One of ``1h``, ``6h``, ``1d``, ``1w``, ``1m`` (one month) or","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/prediction_market_tool.py#L799-L835","documentation":"Raised by prediction_market_tool._resolve_history_token when the selected outcome index has no corresponding entry in the market's clobTokenIds list — the outcomes and clobTokenIds arrays are misaligned in length. Even a valid outcome name fails if the token array is shorter than the outcomes array.","triggerScenarios":"A market whose outcomes list has more entries than clobTokenIds (e.g. 3 outcomes but 2 tokens), selecting any outcome at or beyond len(tokens); the default index 0 with a completely empty token list is caught earlier by the 'no CLOB outcome tokens' check, so this fires for partial misalignment.","commonSituations":"Markets mid-deployment where tokens are only partially created; Gamma payloads with optional/cleared token entries for some outcomes; schema drift between the two arrays.","solutions":["Select an earlier outcome (index < len(tokens)), typically 'Yes'/index 0, which is usually tokenized first","Inspect both outcomes and clobTokenIds arrays for the market to see the misalignment","Retry later if the market is still deploying tokens","Report/skip the market — a misaligned payload is upstream data corruption, not caller error"],"exampleFix":"# before\noutcome='No'  # market has 2 outcomes but only 1 clobTokenId\n\n# after\noutcome='Yes'  # index 0 always within token range when any token exists","handlingStrategy":"fallback","validationCode":null,"typeGuard":"def outcome_has_token(index: int, tokens: list[str]) -> bool:\n    return 0 <= index < len(tokens)","tryCatchPattern":"try:\n    token, meta = _resolve_history_token(identifier, outcome)\nexcept ValueError as e:\n    if \"no matching CLOB token\" in str(e):\n        token, meta = _resolve_history_token(identifier, None)  # fall back to index 0","preventionTips":["Prefer index-0 outcomes ('Yes') which are almost always tokenized","Check len(clobTokenIds) >= len(outcomes) before selecting a later outcome","Treat misaligned markets as bad upstream data: skip and report rather than retry"],"tags":["prediction-market","clob","data-integrity"],"backgroundTag":"index-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}