xai-org/x-algorithm · error · ValueError

Invalid config {name!r}, expected format 'module.key'

Error message

Invalid config {name!r}, expected format 'module.key'

What it means

get_named_config_from_module resolves a config name like 'module.key': it splits on the first '.'. A name with no dot cannot yield both a module and a key, so it raises this ValueError.

Source

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

def get_configs_from_mod(
    mod: ModuleType,
) -> dict[str, Config] | None:
    if "CONFIGS" not in dir(mod):
        return None
    configs: dict[str, Any | Config] = mod.CONFIGS
    assert all(isinstance(config, Config) for config in configs.values())
    return cast(dict[str, Config], configs)


def get_named_config_from_module(
    name: str,
    base_module_name: str,
    on_failure_log_additional_info: bool = False,
) -> Config:
    parts = name.split(".", 1)
    if len(parts) < 2:
        raise ValueError(f"Invalid config {name!r}, expected format 'module.key'")

    mod_name, ver = parts
    try:
        mod = get_module(f"{base_module_name}.{mod_name}")
    except ModuleNotFoundError as e:
        if on_failure_log_additional_info:
            discovered_configs = get_all_configs_from_module(
                base_module_name, ignore_loading_errors=True
            )
            available_configs = sorted(discovered_configs.configs.keys())
            print(f"Available configs: {available_configs}")
        raise e
    configs = get_configs_from_mod(mod)
    if configs is None:
        raise ValueError(f"Module {mod_name!r} does not have CONFIGS")

    if ver not in configs:
        avail = ", ".join(configs.keys())

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use the 'module.key' format, e.g. 'base_cfg.v2'
  2. If the key itself contains dots, use the colon form or a library variant that supports it
  3. Verify the module exists under base_module_name

Example fix

# before
cfg = get_named_config_from_module("myconfig", "xrex.configs")
# after
cfg = get_named_config_from_module("myconfig.v1", "xrex.configs")
Defensive patterns

Strategy: validation

Validate before calling

import re
assert re.fullmatch(r"[^.]+\..+", name), f"Use 'module.key': {name!r}"

Type guard

def is_module_key(name: str) -> bool:
    return isinstance(name, str) and "." in name and name.split(".", 1)[0]

Prevention

When it happens

Trigger: Calling get_named_config_from_module('myconfig') instead of 'myconfig.v1', or a name where the dot is missing/typo'd.

Common situations: Config name typos in launch scripts, or switching from a colon-style ('module:key') convention used elsewhere (xrex's get_named_config) to this library's dot convention.

Related errors


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