HKUDS/Vibe-Trading · error · ValueError
unexpected market payload shape
Error message
unexpected market payload shape
What it means
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.
Source
Thrown at agent/src/tools/prediction_market_tool.py:803
Returns:
``(token_id, context)`` where context carries whatever identifying
metadata was resolved along the way.
Raises:
ValueError: The id cannot be resolved to an outcome token.
requests.RequestException: Propagated from the HTTP layer.
"""
if _is_clob_token_id(identifier):
return identifier, {"clob_token_id": identifier}
if identifier.lower().startswith("0x"):
payload = _get_json(f"{_CLOB_MARKETS_URL}/{identifier}", host_key=_CLOB_HOST_KEY)
raw = _clob_market_to_gamma_shape(payload) if isinstance(payload, dict) else {}
else:
raw = _get_json(f"{_GAMMA_MARKETS_URL}/{identifier}", host_key=_GAMMA_HOST_KEY)
if not isinstance(raw, dict):
raise ValueError("unexpected market payload shape")
names = [str(n) for n in _json_list(raw.get("outcomes"))]
tokens = [str(t) for t in _json_list(raw.get("clobTokenIds"))]
if not tokens:
raise ValueError("market exposes no CLOB outcome tokens")
index = 0
if outcome is not None:
matches = [i for i, n in enumerate(names) if n.lower() == outcome.lower()]
if not matches:
raise ValueError(f"outcome '{outcome}' not in {names}")
index = matches[0]
if index >= len(tokens):
raise ValueError("outcome has no matching CLOB token")
return tokens[index], {
"market_id": str(raw.get("id")) if raw.get("id") is not None else None,
"question": raw.get("question"),View on GitHub (pinned to 80ffdda44c)
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
Defensive patterns
Strategy: try-catch
Try / catch
try:
token, meta = _resolve_history_token(identifier, outcome)
except ValueError as e:
if "unexpected market payload shape" in str(e):
# treat as not-found: re-resolve slug or surface a clean 404 to the user
raise MarketNotFound(identifier) from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- market exposes no CLOB outcome tokens
- outcome '{outcome}' not in {names}
- outcome has no matching CLOB token
- invalid JSON response: {exc}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/3c32f47a37f71fd6.
Report an issue: GitHub.