{"record":{"id":"6b126b78d5fdd789","repo":"abi/screenshot-to-code","slug":"inference-errored-out-error-message","errorCode":null,"errorMessage":"Inference errored out: {error_message}","messagePattern":"Inference errored out: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/image_generation/replicate.py","lineNumber":69,"sourceCode":"    client: httpx.AsyncClient, prediction_id: str, headers: dict[str, str]\n) -> dict[str, Any]:\n    status_check_url = f\"{REPLICATE_API_BASE_URL}/predictions/{prediction_id}\"\n\n    for _ in range(MAX_POLLS):\n        await asyncio.sleep(POLL_INTERVAL_SECONDS)\n        status_response = await client.get(status_check_url, headers=headers)\n        status_response.raise_for_status()\n        status_response_raw: Any = status_response.json()\n        if not isinstance(status_response_raw, dict):\n            raise ValueError(\"Invalid prediction status response.\")\n        status_response_json = cast(dict[str, Any], status_response_raw)\n\n        status = status_response_json.get(\"status\")\n        if status == \"succeeded\":\n            return cast(dict[str, Any], status_response_json)\n        if status == \"error\":\n            error_message = str(status_response_json.get(\"error\", \"Unknown error\"))\n            raise ValueError(f\"Inference errored out: {error_message}\")\n        if status == \"failed\":\n            raise ValueError(\"Inference failed\")\n\n    raise TimeoutError(\"Inference timed out\")\n\n\nasync def _run_prediction(\n    endpoint_url: str, payload: dict[str, Any], api_token: str\n) -> Any:\n    headers = _build_headers(api_token)\n\n    async with httpx.AsyncClient() as client:\n        try:\n            response = await client.post(endpoint_url, headers=headers, json=payload)\n            response.raise_for_status()\n            response_json = response.json()\n            if not isinstance(response_json, dict):\n                raise ValueError(\"Invalid prediction creation response.\")","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/image_generation/replicate.py#L51-L87","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nawait call_replicate_model(\"stability-ai/sdxl\", {\"prompt\": prompt, \"num_outputs\": 5}, token)\n\n// after — match the model's real input schema\nawait call_replicate_model(\"stability-ai/sdxl\", {\"prompt\": prompt, \"num_outputs\": 1}, token)","handlingStrategy":"validation","validationCode":"EXPECTED_INPUT_KEYS = {\"prompt\", \"image\", \"mask\", \"num_outputs\"}\n\ndef validate_model_input(model: str, input: dict) -> list[str]:\n    problems = []\n    if model.startswith(\"stability-ai\") and int(input.get(\"num_outputs\", 1)) > 1:\n        problems.append(\"num_outputs must be 1\")\n    if not str(input.get(\"prompt\", \"\")).strip():\n        problems.append(\"prompt must be non-empty\")\n    return problems","typeGuard":null,"tryCatchPattern":"try:\n    output = await call_replicate_model(model, input, token)\nexcept ValueError as e:\n    if str(e).startswith(\"Inference errored out:\"):\n        # e carries Replicate's own error text — surface it to the user verbatim\n        return error_response(str(e))\n    raise","preventionTips":["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"],"tags":["replicate","image-generation","inference-failure","api"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}