xai-org/x-algorithm · error · TypeError

Tuple {ty} has different number of arguments from given valu

Error message

Tuple {ty} has different number of arguments from given value {vals}

What it means

For tuple-typed fields, cast_type splits the string on ',' and requires the number of parts to equal the number of type args in the Tuple annotation. A mismatch raises this TypeError.

Source

Thrown at phoenix/python/common/xai-configlib/src/xai_configlib/__init__.py:425

        raise ValueError(f"Expected bool [True, true, False, false], got {val!r}")
    elif is_optional(ty) and val == "None":
        return None
    elif is_union(ty):
        subtys = [subty for subty in get_args(ty) if subty is not type(None)]
        for subty in subtys:
            try:
                return cast_type(subty, val)
            except ValueError:
                if subty is subtys[-1]:
                    raise
        raise TypeError(f"Got {val} for union type {ty}")
    elif is_tuple(ty):
        if not val:
            return ()
        vals = val.split(",")
        tys = get_args(ty)
        if len(vals) != len(tys):
            raise TypeError(f"Tuple {ty} has different number of arguments from given value {vals}")
        return tuple(cast_type(a_ty, v) for a_ty, v in zip(tys, vals))
    elif is_list(ty):
        if not val:
            return []
        vals = val.split(",")
        tys = get_args(ty)
        return [cast_type(tys[0], x) for x in vals]
    elif is_dict(ty):
        kty, vty = get_args(ty)
        result = {}
        for item in val.split(","):
            k, v = item.split(":", 1)
            result[cast_type(kty, k.strip())] = cast_type(vty, v.strip())
        return result
    elif is_path(ty):
        return Path(val)
    elif is_bytes(ty):
        return base64.b64decode(val.encode("utf-8"))

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Count the Tuple type args and supply exactly that many comma-separated values
  2. Update the override after changing the field's tuple arity in the dataclass

Example fix

# before
replace_cli_subs(cfg, ["image_size=256"])  # field: Tuple[int, int]
# after
replace_cli_subs(cfg, ["image_size=256,256"])
Defensive patterns

Strategy: validation

Validate before calling

from typing import get_args, get_origin

def tuple_arity_ok(ty, val: str) -> bool:
    if get_origin(ty) is not tuple:
        return True
    return len(val.split(",")) == len(get_args(ty))

Prevention

When it happens

Trigger: Overriding a Tuple[int, int] field with '256' (one value) or '1,2,3' (three values); also passing a value with a trailing comma creating an empty element.

Common situations: Changing a tuple field's arity in the config but not the CLI override, or copying an override from a config with a different tuple size.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/cd9ff6dceeb3c0b9. Report an issue: GitHub.