xai-org/x-algorithm · error · ValueError

Invalid argument {arg!r}, not a key=value replacement and no

Error message

Invalid argument {arg!r}, not a key=value replacement and no matching preset found

What it means

xai_configlib's replace_presets expands CLI arguments before applying them to a config. Each argument must either contain '=' (a direct key=value replacement) or match a key in the presets dict. Otherwise this ValueError is raised, listing the offending argument.

Source

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

    for kv in kvs:
        k, v = parse_kv(kv)
        key_path = tuple(k.split("."))
        used = []
        new_config = replace_recursive(new_config, (), key_path, v, used)
        kv_used[k] = [".".join(x) for x in used]
    return new_config, kv_used


def replace_presets(args: list[str], presets: dict[str, list[str]]) -> list[str]:
    kvs = []
    for arg in args:
        if "=" in arg:
            kvs.append(arg)
        else:
            preset = presets.get(arg)
            if not preset:
                raise ValueError(
                    f"Invalid argument {arg!r}, not a key=value replacement and no matching preset found"
                )
            kvs += preset
    return kvs


def replace_recursive(
    dcls: Any,
    current_path: tuple[str, ...],
    key_path: tuple[str, ...],
    value: str,
    used: list[tuple[str, ...]],
) -> Any:
    new_dcls = dcls
    ty_hints = resolve_type_hints(dcls)
    for dataclass_field in dataclasses.fields(dcls):
        name = dataclass_field.name
        if not hasattr(dcls, name):

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Fix the typo so the argument matches a preset name or is 'key=value'
  2. Print/inspect the presets dict passed in to see valid names
  3. If the argument should be a direct override, add '=' (e.g. 'lr=3e-4')
  4. If it's a new option, register it in PRESETS

Example fix

# before
replace_cli_subs(cfg, ["leraning_rate"])
# after
replace_cli_subs(cfg, ["lr=3e-4"])  # or a valid preset name
Defensive patterns

Strategy: validation

Validate before calling

def valid_args(args, presets):
    bad = [a for a in args if "=" not in a and a not in presets]
    assert not bad, f"Unknown preset args: {bad}; valid: {sorted(presets)}"

Prevention

When it happens

Trigger: Calling replace_cli_subs (or a CLI wrapper) with an argument like 'foo' that has no '=' and no entry in the PRESETS mapping passed to replace_presets; typically a typo'd preset name or a flag-style argument ('--lr') passed where only kvs/preset names are accepted.

Common situations: Typos in preset names on the command line, presets renamed between config library versions, passing bare flags that the config layer does not support, or an empty/stale PRESETS dict.

Related errors


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