deepset-ai/haystack · error · ValueError

Invalid image type: {params['type']}. Valid options are: {va

Error message

Invalid image type: {params['type']}. Valid options are: {valid_img_types}.

What it means

When format is 'img', mermaid.ink accepts only certain raster image types. Haystack raises this if params['type'] is not in that list. It validates before making the network request so failures happen locally.

Source

Thrown at haystack/core/pipeline/draw.py:142

            - paper: Paper size for PDFs (e.g., 'a4', 'a3'). Ignored if 'fit' is true.
            - landscape: Landscape orientation for PDFs (boolean). Ignored if 'fit' is true.

    :raises ValueError:
        If any parameter is invalid or does not match the expected format.
    """
    valid_img_types = {"jpeg", "png", "webp"}
    valid_themes = {"default", "neutral", "dark", "forest"}
    valid_formats = {"img", "svg", "pdf"}

    params.setdefault("format", "img")
    params.setdefault("type", "png")
    params.setdefault("theme", "neutral")

    if params["format"] not in valid_formats:
        raise ValueError(f"Invalid image format: {params['format']}. Valid options are: {valid_formats}.")

    if params["format"] == "img" and params["type"] not in valid_img_types:
        raise ValueError(f"Invalid image type: {params['type']}. Valid options are: {valid_img_types}.")

    if params["theme"] not in valid_themes:
        raise ValueError(f"Invalid theme: {params['theme']}. Valid options are: {valid_themes}.")

    if "width" in params and not isinstance(params["width"], int):
        raise ValueError("Width must be an integer.")
    if "height" in params and not isinstance(params["height"], int):
        raise ValueError("Height must be an integer.")

    if "scale" in params and not 1 <= params["scale"] <= 3:
        raise ValueError("Scale must be a number between 1 and 3.")
    if "scale" in params and not ("width" in params or "height" in params):
        raise ValueError("Scale is only allowed when width or height is set.")

    if "bgColor" in params and not isinstance(params["bgColor"], str):
        raise ValueError("Background color must be a string.")

    # PDF specific parameters

View on GitHub (pinned to e318778c9b)

Solutions

  1. Set type to one of the listed valid_img_types (e.g. 'png', 'jpeg')
  2. For vector output use params={'format': 'svg'} instead of format='img' with type='svg'
  3. Omit 'type' to use the default 'png'

Example fix

// before
pipeline.draw(path="g", params={"format": "img", "type": "svg"})  # ValueError
// after
pipeline.draw(path="g", params={"format": "svg"})
Defensive patterns

Strategy: validation

Validate before calling

if params.get("format", "img") == "img" and params.get("type", "png") not in {"png", "jpeg"}:
    raise ValueError("for format=img use type png or jpeg")

Type guard

def valid_img_type(params: dict) -> bool:
    return params.get("format", "img") != "img" or params.get("type", "png") in {"png", "jpeg"}

Try / catch

try:
    pipeline.draw(path, params=params)
except ValueError as e:
    if "image type" in str(e):
        params["type"] = "png"
        pipeline.draw(path, params=params)

Prevention

When it happens

Trigger: Passing params={'format': 'img', 'type': 'svg'} or 'jpg'/'webp'; only raster types accepted for 'img' (e.g. 'png', 'jpeg').

Common situations: Users want a vector image and set type='svg' but forgot format must be 'svg'; confusion between the two params.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/8393901036c0609b. Report an issue: GitHub.