zylon-ai/private-gpt · error · ValueError

Names already registered: {existing_names}

Error message

Names already registered: {existing_names}

What it means

LLMRegistry.register stores a component under a primary name plus aliases, and refuses any name collision. Before inserting, it collects every requested name already present in the internal dict and raises ValueError listing them, keeping registrations unambiguous.

Source

Thrown at private_gpt/components/llm/registry.py:49

        """Default name for the main LLM."""
        return "default"

    def register(
        self, name: str, component: LLMInstance, aliases: list[str] | None = None
    ) -> None:
        """Register a new LLM component with a given name and optional aliases.

        :param name: The primary name of the LLM component.
        :param component: The LLM component to register.
        :param aliases: Optional list of aliases for this component.
        """
        aliases = [alias.strip() for alias in (aliases or []) if alias.strip()]
        all_names = [name, *aliases]

        # Check if any name is already registered
        existing_names = [n for n in all_names if n in self._registry]
        if existing_names:
            raise ValueError(f"Names already registered: {existing_names}")

        # Register component under all names
        for alias in all_names:
            self._registry[alias] = component

    def unregister(self, name: str) -> None:
        """Unregister an LLM component by its name or alias.

        :param name: The name or alias of the LLM component to unregister.
        """
        if name not in self._registry:
            raise KeyError(f"LLM component '{name}' is not registered.")
        del self._registry[name]

    def get(self, name: str) -> LLMInstance | None:
        """Retrieve an LLM component by its name or alias.

        :param name: The name or alias of the LLM component to retrieve.

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Check registry.get_all_aliases() (or registry.get(name)) before registering and unregister the existing entry first.
  2. Use unique names/aliases for each new LLM component.
  3. In tests, call registry.unregister(name) in teardown or use a fresh LLMRegistry instance instead of the singleton.

Example fix

// before
registry.register('default', llm_instance, aliases=['openai'])  # raises if taken

// after
for n in ['default', 'openai']:
    if registry.get(n) is not None:
        registry.unregister(n)
registry.register('default', llm_instance, aliases=['openai'])
Defensive patterns

Strategy: validation

Validate before calling

def safe_register(registry, name, component, aliases=None):
    wanted = [name, *(aliases or [])]
    taken = [n for n in wanted if registry.get(n) is not None]
    for n in taken:
        registry.unregister(n)
    registry.register(name, component, aliases=aliases)

Try / catch

try:
    registry.register(name, inst, aliases=aliases)
except ValueError as e:
    if 'already registered' in str(e):
        registry.unregister(name)  # or pick new names
        registry.register(name, inst, aliases=aliases)
    else:
        raise

Prevention

When it happens

Trigger: Calling registry.register('default', instance) twice, or registering a component whose alias (e.g. 'openai') already maps to another LLMInstance. Also happens in tests that re-register the default LLM without resetting the singleton registry.

Common situations: Reload/re-import loops or DI containers re-running wiring code against the @singleton LLMRegistry; adding a new LLM component whose alias clashes with an existing one; test suites that don't call unregister between cases.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/76130a1694ca391c. Report an issue: GitHub.