abi/screenshot-to-code · error · ValueError
Unexpected response from {context}: {result}
Error message
Unexpected response from {context}: {result} What it means
Raised by _extract_output_url when the prediction's `output` field doesn't contain anything URL-shaped. The function accepts: a plain string, a dict with a non-empty `url` key, or a non-empty list whose first element is a string or a url-bearing mapping. Anything else — None, an empty list, a list of non-strings, a dict without url — raises this ValueError with the offending payload embedded.
Source
Thrown at backend/image_generation/replicate.py:122
def _extract_output_url(result: Any, context: str) -> str:
if isinstance(result, str):
return result
if isinstance(result, dict):
url = cast(Any, result.get("url"))
if isinstance(url, str) and url:
return url
if isinstance(result, list) and len(result) > 0:
first = cast(Any, result[0])
if isinstance(first, str) and first:
return first
if isinstance(first, Mapping):
url = cast(Any, first.get("url"))
if isinstance(url, str) and url:
return url
raise ValueError(f"Unexpected response from {context}: {result}")
async def call_replicate_model(
model_path: str, input: dict[str, Any], api_token: str
) -> Any:
return await _run_prediction(
f"{REPLICATE_API_BASE_URL}/models/{model_path}/predictions",
{"input": input},
api_token,
)
async def call_replicate_version(
version: str, input: dict[str, Any], api_token: str
) -> Any:
return await _run_prediction(
f"{REPLICATE_API_BASE_URL}/predictions",
{"version": version, "input": input},View on GitHub (pinned to d026163f58)
Solutions
- Look at the embedded `result` in the message — it shows exactly what the model returned.
- Check the model's docs on Replicate for its output schema and adapt _extract_output_url if it uses a different key.
- If output is empty/None, treat it as a model-side failure and retry or adjust input.
- Test the model once via the Replicate playground to see its real output shape.
Example fix
# before — model returns {"image": "https://..."}
# _extract_output_url raises because there is no "url" key
# after — extend the dict branch
url = cast(Any, result.get("url") or result.get("image")) Defensive patterns
Strategy: type-guard
Type guard
from typing import Any, Mapping
def output_has_extractable_url(output: Any) -> bool:
if isinstance(output, str) and output:
return True
if isinstance(output, Mapping):
return isinstance(output.get("url"), str) and bool(output["url"])
if isinstance(output, list) and output:
first = output[0]
if isinstance(first, str) and first:
return True
if isinstance(first, Mapping):
return isinstance(first.get("url"), str) and bool(first["url"])
return False Try / catch
try:
url = _extract_output_url(result, context="sdxl")
except ValueError as e:
if "Unexpected response" in str(e):
log.error("Model output schema not URL-shaped: %r", result)
raise Prevention
- Inspect the model's documented output schema before switching models
- Log the raw `output` payload once when integrating a new model
- Extend _extract_output_url for non-"url" keys rather than string-matching error text
When it happens
Trigger: The prediction succeeded but output is null (some models emit output artifacts elsewhere, e.g. only in `data` or `logs`); output is a dict with the image under a different key (e.g. "image" instead of "url"); output is an empty list because the model returned zero images.
Common situations: Switching call_replicate_model to a new model whose output schema differs (e.g. returns a list of dicts without "url", or a nested structure); models that stream results to a different field; output empty because the model produced no image.
Related errors
- Prediction ID not found in initial response.
- Invalid prediction status response.
- Invalid prediction creation response.
- Inference errored out: {error_message}
- Inference failed
AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14).
Data as JSON: /api/errors/047c7748b16f1597.
Report an issue: GitHub.