python-poetry/poetry · error · RuntimeError

"{value}" is an invalid value for {key}

Error message

"{value}" is an invalid value for {key}

What it means

RuntimeError from `_handle_single_value` (config.py:382-383) when the validator callback returns False. Each setting has a `(validator, normalizer)` pair; e.g. `virtualenvs.create` requires a boolean, `requests.max-retries` requires `int(val) >= 0`, `installer.max-workers` requires `int(val) > 0`.

Source

Thrown at src/poetry/console/commands/config.py:383

            return 0

        raise ValueError(f"Setting {self.argument('key')} does not exist")

    def _handle_single_value(
        self,
        source: ConfigSource,
        key: str,
        callbacks: tuple[Any, Any],
        values: list[Any],
    ) -> int:
        validator, normalizer = callbacks

        if len(values) > 1:
            raise RuntimeError("You can only pass one value.")

        value = values[0]
        if not validator(value):
            raise RuntimeError(f'"{value}" is an invalid value for {key}')

        source.add_property(key, normalizer(value))

        return 0

    def _list_configuration(
        self, config: dict[str, Any], raw: dict[str, Any], k: str = ""
    ) -> None:
        orig_k = k
        for key, value in sorted(config.items()):
            if k + key in self.LIST_PROHIBITED_SETTINGS:
                continue

            raw_val = raw.get(key)

            if isinstance(value, dict):
                k += f"{key}."
                raw_val = cast("dict[str, Any]", raw_val)

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Match the validator: use `true`/`false` for booleans, a positive int for `installer.max-workers`, a non-negative int for `requests.max-retries`.
  2. Inspect the validator in `unique_config_values` (config.py:78-101) to confirm accepted input.
  3. Use `poetry config --list` to see current normalized values and mirror their format.

Example fix

# before
poetry config requests.max-retries -1
# after
poetry config requests.max-retries 5
Defensive patterns

Strategy: type-guard

Validate before calling

from poetry.config.config import boolean_validator
value = "true"
if not boolean_validator(value):
    raise SystemExit(f"{value} is not a boolean")
# for numeric keys:
# assert int(value) > 0 for installer.max-workers

Type guard

def fits_setting(key: str, value: str) -> bool:
    from poetry.console.commands.config import ConfigCommand
    specs = ConfigCommand().unique_config_values
    if key not in specs:
        return True  # unknown key handled elsewhere
    validator, _ = specs[key]
    try:
        return bool(validator(value))
    except Exception:
        return False

Prevention

When it happens

Trigger: Passing `maybe` to a boolean setting; a negative integer to `requests.max-retries`; zero to `installer.max-workers`; a non-integer to a numeric key.

Common situations: Misremembering the expected type; passing `yes`/`no`/`on`/`off` when only strict booleans are accepted; negative retry counts.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/c852e92d441006aa.json. Report an issue: GitHub.