Significant-Gravitas/AutoGPT · error · RuntimeError

Unexpected output format from the model.

Error message

Unexpected output format from the model.

What it means

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.

Source

Thrown at autogpt_platform/backend/backend/api/features/store/image_gen.py:167

            # Depending on the model output, extract the image URL or bytes
            # If the output is a list of FileOutput or URLs
            if isinstance(output, list) and output:
                if isinstance(output[0], FileOutput):
                    image_bytes = output[0].read()
                else:
                    # If it's a URL string, fetch the image bytes
                    result_url = output[0]
                    response = await Requests().get(result_url)
                    image_bytes = response.content
            elif isinstance(output, FileOutput):
                image_bytes = output.read()
            elif isinstance(output, str):
                # Output is a URL
                response = await Requests().get(output)
                image_bytes = response.content
            else:
                raise RuntimeError("Unexpected output format from the model.")

            return io.BytesIO(image_bytes)

        except ReplicateError as e:
            if e.status == 401:
                raise RuntimeError("Invalid Replicate API token") from e
            raise RuntimeError(f"Replicate API error: {str(e)}") from e

    except Exception as e:
        logger.exception("Failed to generate agent image")
        raise RuntimeError(f"Image generation failed: {str(e)}")

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Log/inspect the actual `output` value (type and repr) to learn the new shape.
  2. Pin the Replicate model to a specific version known to return URLs/FileOutput instead of a floating tag.
  3. Extend the dispatch chain to handle the observed type (e.g. dict with 'url', or iterate a generator of chunks and concatenate).

Example fix

// before
            else:
                raise RuntimeError("Unexpected output format from the model.")

// after
            elif isinstance(output, dict) and "url" in output:
                response = await Requests().get(output["url"])
                image_bytes = response.content
            else:
                raise RuntimeError(
                    f"Unexpected output format from the model: {type(output)}"
                )
Defensive patterns

Strategy: type-guard

Type guard

def is_supported_replicate_output(output: object) -> bool:
    if output is None:
        return False
    if isinstance(output, str):
        return output.startswith("http")
    if isinstance(output, (list, tuple)):
        return len(output) > 0 and isinstance(output[0], str)
    return type(output).__name__ == "FileOutput"  # replicate.client output wrapper

Try / catch

try:
    image = await generate_agent_image_v1(agent)
except RuntimeError as e:
    if "Unexpected output format" in str(e):
        pin_model_version(); alert_oncall(f"Replicate output contract changed: {e}")
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/b5118eb963f2353d. Report an issue: GitHub.