abi/screenshot-to-code · error · ValueError
Inference errored out: {error_message}
Error message
Inference errored out: {error_message} What it means
Raised in _poll_prediction when a polled prediction reports status == "error": Replicate itself flagged the prediction as errored. The message embeds the provider's error text (or "Unknown error" if the payload has no `error` field). This is a server-side inference failure, distinct from "failed" (status == "failed") — "error" usually means the model threw during execution (bad input params, NSFW filter, model crash).
Source
Thrown at backend/image_generation/replicate.py:69
client: httpx.AsyncClient, prediction_id: str, headers: dict[str, str]
) -> dict[str, Any]:
status_check_url = f"{REPLICATE_API_BASE_URL}/predictions/{prediction_id}"
for _ in range(MAX_POLLS):
await asyncio.sleep(POLL_INTERVAL_SECONDS)
status_response = await client.get(status_check_url, headers=headers)
status_response.raise_for_status()
status_response_raw: Any = status_response.json()
if not isinstance(status_response_raw, dict):
raise ValueError("Invalid prediction status response.")
status_response_json = cast(dict[str, Any], status_response_raw)
status = status_response_json.get("status")
if status == "succeeded":
return cast(dict[str, Any], status_response_json)
if status == "error":
error_message = str(status_response_json.get("error", "Unknown error"))
raise ValueError(f"Inference errored out: {error_message}")
if status == "failed":
raise ValueError("Inference failed")
raise TimeoutError("Inference timed out")
async def _run_prediction(
endpoint_url: str, payload: dict[str, Any], api_token: str
) -> Any:
headers = _build_headers(api_token)
async with httpx.AsyncClient() as client:
try:
response = await client.post(endpoint_url, headers=headers, json=payload)
response.raise_for_status()
response_json = response.json()
if not isinstance(response_json, dict):
raise ValueError("Invalid prediction creation response.")View on GitHub (pinned to d026163f58)
Solutions
- Read the embedded error_message — it is Replicate's own explanation of the failure.
- Validate the `input` dict against the model's documented input schema (GET /models/{path} or the model page) before calling.
- Pin a known-good model version (owner/name:version) instead of the rolling latest.
- If the error is a content filter, adjust the prompt/image, not the code.
Example fix
# before
await call_replicate_model("stability-ai/sdxl", {"prompt": prompt, "num_outputs": 5}, token)
// after — match the model's real input schema
await call_replicate_model("stability-ai/sdxl", {"prompt": prompt, "num_outputs": 1}, token) Defensive patterns
Strategy: validation
Validate before calling
EXPECTED_INPUT_KEYS = {"prompt", "image", "mask", "num_outputs"}
def validate_model_input(model: str, input: dict) -> list[str]:
problems = []
if model.startswith("stability-ai") and int(input.get("num_outputs", 1)) > 1:
problems.append("num_outputs must be 1")
if not str(input.get("prompt", "")).strip():
problems.append("prompt must be non-empty")
return problems Try / catch
try:
output = await call_replicate_model(model, input, token)
except ValueError as e:
if str(e).startswith("Inference errored out:"):
# e carries Replicate's own error text — surface it to the user verbatim
return error_response(str(e))
raise Prevention
- Validate the input dict against the model's schema (GET /models/{path}) before calling
- Pin exact model versions so input contracts can't drift
- Surface the embedded error_message to users — it names the real cause
When it happens
Trigger: Calling call_replicate_model with invalid input parameters for the model (wrong image size, malformed prompt, unsupported values); the model version crashing; Replicate's safety filters rejecting the input. The error_message string from the payload says which.
Common situations: Wrong input schema for a specific model version (e.g. missing required param, out-of-range values); using an outdated model version whose input contract changed; content-policy rejections on image-to-image edits.
Related errors
- Prediction ID not found in initial response.
- Invalid prediction status response.
- Inference failed
- Invalid prediction creation response.
- HTTP error occurred: {exc}
AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14).
Data as JSON: /api/errors/6b126b78d5fdd789.
Report an issue: GitHub.