Comfy-Org/ComfyUI · error · ValueError

Aspect ratio must contain integers separated by ':', got '{a

Error message

Aspect ratio must contain integers separated by ':', got '{ar_str}'.

What it means

Raised by _parse_aspect_ratio_string() in comfy_api_nodes/util/validation_utils.py when the 'X:Y' string has the right shape but either part is not an integer (after whitespace stripping). int() raises ValueError internally and this message re-raises with provider-friendly context, chaining the original via 'from exc'.

Source

Thrown at comfy_api_nodes/util/validation_utils.py:242

        if (ar <= lo) if strict else (ar < lo):
            op = "<" if strict else "≤"
            raise ValueError(f"Aspect ratio `{ar:.2g}` must be {op} {lo:.2g}.")
    if hi is not None:
        if (ar >= hi) if strict else (ar > hi):
            op = "<" if strict else "≤"
            raise ValueError(f"Aspect ratio `{ar:.2g}` must be {op} {hi:.2g}.")


def _parse_aspect_ratio_string(ar_str: str) -> float:
    """Parse 'X:Y' with integer parts into a positive float ratio X/Y."""
    parts = ar_str.split(":")
    if len(parts) != 2:
        raise ValueError(f"Aspect ratio must be 'X:Y' (e.g., 16:9), got '{ar_str}'.")
    try:
        a = int(parts[0].strip())
        b = int(parts[1].strip())
    except ValueError as exc:
        raise ValueError(f"Aspect ratio must contain integers separated by ':', got '{ar_str}'.") from exc
    if a <= 0 or b <= 0:
        raise ValueError(f"Aspect ratio parts must be positive integers, got {a}:{b}.")
    return a / b

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Use whole-number components: '47:20' instead of '2.35:1', '16:9' instead of '1.78:1'.
  2. When converting from a decimal, compute an integer approximation (e.g. Fraction(1.78).limit_denominator(50) -> '89:50').
  3. Fill in both sides of the colon; ':9' and '16:' are invalid.
  4. Prefer preset combo values when available.

Example fix

# before
_parse_aspect_ratio_string('2.35:1')  # ValueError: must contain integers separated by ':'

# after
from fractions import Fraction
f = Fraction(2.35).limit_denominator(20)  # 47/20
ratio_str = f'{f.numerator}:{f.denominator}'  # '47:20'
Defensive patterns

Strategy: type-guard

Validate before calling

from fractions import Fraction

def normalize_ratio(s: str) -> str:
    parts = s.split(':')
    if len(parts) != 2:
        f = Fraction(float(s)).limit_denominator(50)
        return f'{f.numerator}:{f.denominator}'
    return s

Type guard

def is_int_ratio_string(s: str) -> bool:
    parts = s.split(':')
    if len(parts) != 2: return False
    try:
        int(parts[0].strip()); int(parts[1].strip()); return True
    except ValueError:
        return False

Prevention

When it happens

Trigger: Passing '16.5:9', '1.78:1', ':9', '16:', or 'a:b' to validate_aspect_ratio. Floats, empty parts, and non-numeric text all land here. Only 'int:int' (whitespace around parts tolerated) parses.

Common situations: Users entering decimal ratios ('2.35:1' is actually valid because 2.35 is not an int — this fails); colon left with a missing side after editing; localized keyboards substituting characters; programmatic callers formatting floats directly into the string.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/76b3886685ea563a. Report an issue: GitHub.