{"record":{"id":"b5118eb963f2353d","repo":"Significant-Gravitas/AutoGPT","slug":"unexpected-output-format-from-the-model","errorCode":null,"errorMessage":"Unexpected output format from the model.","messagePattern":"Unexpected output format from the model\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/image_gen.py","lineNumber":167,"sourceCode":"\n            # Depending on the model output, extract the image URL or bytes\n            # If the output is a list of FileOutput or URLs\n            if isinstance(output, list) and output:\n                if isinstance(output[0], FileOutput):\n                    image_bytes = output[0].read()\n                else:\n                    # If it's a URL string, fetch the image bytes\n                    result_url = output[0]\n                    response = await Requests().get(result_url)\n                    image_bytes = response.content\n            elif isinstance(output, FileOutput):\n                image_bytes = output.read()\n            elif isinstance(output, str):\n                # Output is a URL\n                response = await Requests().get(output)\n                image_bytes = response.content\n            else:\n                raise RuntimeError(\"Unexpected output format from the model.\")\n\n            return io.BytesIO(image_bytes)\n\n        except ReplicateError as e:\n            if e.status == 401:\n                raise RuntimeError(\"Invalid Replicate API token\") from e\n            raise RuntimeError(f\"Replicate API error: {str(e)}\") from e\n\n    except Exception as e:\n        logger.exception(\"Failed to generate agent image\")\n        raise RuntimeError(f\"Image generation failed: {str(e)}\")\n","sourceCodeStart":149,"sourceCodeEnd":179,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/image_gen.py#L149-L179","documentation":"RuntimeError inside generate_agent_image_v1() after the Replicate model returns: the prediction output matched none of the handled shapes (list of URLs, FileOutput, plain URL string). It means the Flux model's output contract changed or returned an unexpected type (None, dict, generator, empty stream), so the code cannot extract image bytes.","triggerScenarios":"Replicate deploys a new version of the referenced Flux model whose output schema differs (e.g. returns a dict or null on partial failure), or the model returns None because generation failed without raising a ReplicateError.","commonSituations":"Replicate model version pinning was loosened so 'latest' picked up a breaking change; model returned an error payload instead of an image; new output wrapper type introduced by the replicate-python client upgrade.","solutions":["Log/inspect the actual `output` value (type and repr) to learn the new shape.","Pin the Replicate model to a specific version known to return URLs/FileOutput instead of a floating tag.","Extend the dispatch chain to handle the observed type (e.g. dict with 'url', or iterate a generator of chunks and concatenate)."],"exampleFix":"// before\n            else:\n                raise RuntimeError(\"Unexpected output format from the model.\")\n\n// after\n            elif isinstance(output, dict) and \"url\" in output:\n                response = await Requests().get(output[\"url\"])\n                image_bytes = response.content\n            else:\n                raise RuntimeError(\n                    f\"Unexpected output format from the model: {type(output)}\"\n                )","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_supported_replicate_output(output: object) -> bool:\n    if output is None:\n        return False\n    if isinstance(output, str):\n        return output.startswith(\"http\")\n    if isinstance(output, (list, tuple)):\n        return len(output) > 0 and isinstance(output[0], str)\n    return type(output).__name__ == \"FileOutput\"  # replicate.client output wrapper","tryCatchPattern":"try:\n    image = await generate_agent_image_v1(agent)\nexcept RuntimeError as e:\n    if \"Unexpected output format\" in str(e):\n        pin_model_version(); alert_oncall(f\"Replicate output contract changed: {e}\")\n    raise","preventionTips":["Pin Replicate model versions instead of using floating latest.","Log output type on every generation failure to detect contract drift early."],"tags":["store","replicate","image-generation","api-contract"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}