HKUDS/nanobot · error · ValueError

model_preset must be a non-empty string

Error message

model_preset must be a non-empty string

What it means

Raised by normalize_preset_name when the model_preset argument is not a string or is empty/whitespace-only before preset lookup is attempted. It is the input-sanitization gate for every preset selection; a None default, a non-string config value, or an accidental blank in config triggers it.

Solutions

  1. Pass a non-empty string preset name, e.g. "default" or a key from the configured model_presets dict
  2. If the preset comes from config, check that model_preset is set and not an empty string in the config file
  3. Omit model_preset entirely if you want the default model instead of a preset
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nanobot/agent/model_presets.py:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26). Data as JSON: /api/errors/4f65ae632113f097. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/agent/model_presets.py:80

        model_preset=name,
    )


def build_runtime_preset_snapshot(
    *,
    name: str,
    presets: dict[str, ModelPresetConfig],
    provider: LLMProvider,
    loader: PresetSnapshotLoader | None,
) -> ProviderSnapshot:
    if loader is not None:
        return replace(loader(name), model_preset=name)
    return build_static_preset_snapshot(provider, name, presets[name])


def normalize_preset_name(name: str | None, presets: dict[str, ModelPresetConfig]) -> str:
    if not isinstance(name, str) or not name.strip():
        raise ValueError("model_preset must be a non-empty string")
    name = name.strip()
    if name in presets:
        return name
    matches = [candidate for candidate in presets if candidate.casefold() == name.casefold()]
    if len(matches) == 1:
        return matches[0]
    raise KeyError(f"model_preset {name!r} not found. Available: {', '.join(presets) or '(none)'}")

View on GitHub (pinned to 42f37dc4c0)