{"record":{"id":"3c32f47a37f71fd6","repo":"HKUDS/Vibe-Trading","slug":"unexpected-market-payload-shape","errorCode":null,"errorMessage":"unexpected market payload shape","messagePattern":"unexpected market payload shape","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/prediction_market_tool.py","lineNumber":803,"sourceCode":"\n    Returns:\n        ``(token_id, context)`` where context carries whatever identifying\n        metadata was resolved along the way.\n\n    Raises:\n        ValueError: The id cannot be resolved to an outcome token.\n        requests.RequestException: Propagated from the HTTP layer.\n    \"\"\"\n    if _is_clob_token_id(identifier):\n        return identifier, {\"clob_token_id\": identifier}\n\n    if identifier.lower().startswith(\"0x\"):\n        payload = _get_json(f\"{_CLOB_MARKETS_URL}/{identifier}\", host_key=_CLOB_HOST_KEY)\n        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\"),","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/prediction_market_tool.py#L785-L821","documentation":"Raised by prediction_market_tool._resolve_history_token when a Gamma markets API lookup by identifier returns a non-dict payload (e.g. a list, string, or null). The resolver expects a single market JSON object; anything else means the identifier did not resolve to one market (404 HTML/error body, array response, or empty body) and the shape is unexpected.","triggerScenarios":"Fetching a Gamma market by a non-hex identifier that doesn't exist (API returns an error body or null); passing a slug that resolves to a redirect/list payload; the Gamma endpoint changing its response contract for single-market GETs.","commonSituations":"Wrong or stale market IDs/slug copied from docs; environment pointing at a different Gamma host whose single-market endpoint behaves differently; API contract changes after a Polymarket release.","solutions":["Confirm the identifier is the correct Gamma market slug/UUID (not the CLOB 0x id, which uses the other branch)","Check the raw GET response for that identifier with curl to see the actual payload type","Verify _GAMMA_HOST_KEY host configuration matches the expected Gamma deployment","Handle this as a not-found condition: re-resolve the market slug before retrying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    token, meta = _resolve_history_token(identifier, outcome)\nexcept ValueError as e:\n    if \"unexpected market payload shape\" in str(e):\n        # treat as not-found: re-resolve slug or surface a clean 404 to the user\n        raise MarketNotFound(identifier) from e","preventionTips":["Use identifiers sourced directly from the Gamma API so they're known-valid","Distinguish 0x-prefixed CLOB ids from Gamma slugs/UUIDs before calling","Cache market id → payload mappings and revalidate when this error appears, since it often signals upstream contract drift"],"tags":["prediction-market","api-response","gamma"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}