deepset-ai/haystack · error · ValueError

Height must be an integer.

Error message

Height must be an integer.

What it means

Height for mermaid image rendering must be an integer (pixels). Raised when params['height'] exists but is not an int.

Source

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

    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
    if params["format"] == "pdf":
        if "fit" in params and not isinstance(params["fit"], bool):
            raise ValueError("Fit must be a boolean.")
        if "paper" in params and not isinstance(params["paper"], str):
            raise ValueError("Paper size must be a string (e.g., 'a4', 'a3').")
        if "landscape" in params and not isinstance(params["landscape"], bool):
            raise ValueError("Landscape must be a boolean.")
        if "fit" in params and ("paper" in params or "landscape" in params):

View on GitHub (pinned to e318778c9b)

Solutions

  1. Coerce with int(params['height']) before calling draw
  2. Pass a plain int
  3. Remove 'height' and rely on auto-sizing

Example fix

// before
pipeline.draw(path="g.png", params={"height": 600.5})  # ValueError
// after
pipeline.draw(path="g.png", params={"height": int(600.5)})
Defensive patterns

Strategy: type-guard

Validate before calling

if "height" in params and not isinstance(params["height"], int):
    params["height"] = int(params["height"])

Type guard

def is_int_height(v) -> bool:
    return isinstance(v, int) and not isinstance(v, bool)

Try / catch

try:
    pipeline.draw(path, params=params)
except ValueError as e:
    if "Height must be an integer" in str(e):
        params["height"] = int(params["height"])
        pipeline.draw(path, params=params)

Prevention

When it happens

Trigger: params={'height': '600'}, {'height': 600.5}, or None passed through to draw().

Common situations: Dimensions sourced from strings in env vars/config; computed float values from division.

Related errors


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