zylon-ai/private-gpt · critical · ValueError

Default LLM model '{model_id}' could not be initialized: {e}

Error message

Default LLM model '{model_id}' could not be initialized: {e}

What it means

ValueError from LLMComponent startup: initializing the model configured as the default raised an exception, so the component removes it from the registry and re-raises (rather than the skip-and-warn path used for non-default models). The original exception is chained as __cause__, so the real failure (bad API key, unreachable endpoint, missing dependency) is in the caused-by chain.

Source

Thrown at private_gpt/components/llm/llm_component.py:98

                instance = factory.create_llm(model_config)

                alias = instance.alias
                aliases = [alias] if alias and alias != model_id else []
                if model_id == self._default_model_id:
                    aliases.append(LLMRegistry.default())

                registry_instance = LLMInstance(
                    llm=instance.llm, tokenizer=instance.tokenizer
                )
                self.registry.register(model_id, registry_instance, aliases=aliases)
                registered_model_ids.append(model_id)

                logger.info("Successfully registered LLM model '%s'", model_id)

            except Exception as e:
                self.llm_models.pop(model_id, None)
                if model_id == self._default_model_id:
                    raise ValueError(
                        f"Default LLM model '{model_id}' could not be initialized: {e}"
                    ) from e
                logger.warning(
                    "Skipping unavailable LLM model '%s': %s",
                    model_id,
                    e,
                )

        if not self._default_model_id and registered_model_ids:
            self._default_model_id = next(iter(self.llm_models))
            logger.warning(
                "No default LLM model configured. Auto-selecting: '%s'",
                self._default_model_id,
            )

        if self._default_model_id:
            default_instance = self.registry.get(self._default_model_id)
            if not default_instance:

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Read the chained exception (`raise ... from e` — inspect __cause__) to identify the real init failure and fix it (key, URL, dependency).
  2. Verify credentials/env for that provider are set in the environment the service actually runs in.
  3. As a stopgap, set default_model to a model that initializes cleanly so the app can boot while you fix the broken one.
Defensive patterns

Strategy: try-catch

Validate before calling

def default_model_config_valid(settings) -> bool:
    models = settings.llm.models or {}
    default = settings.llm.default_model
    return default is None or default in models

Try / catch

try:
    component = LLMComponent()
except ValueError as e:
    if 'could not be initialized' in str(e):
        cause = e.__cause__  # real failure: auth, endpoint, dependency
        log.error('Default model init failed: %s', cause)
        raise
    raise

Prevention

When it happens

Trigger: Any factory/init failure for the model whose id equals the configured default: invalid or missing OPENAI_API_KEY, wrong endpoint URL, missing optional extra for that mode, bad model path, or misconfigured tokenizer.

Common situations: First boot with incomplete credentials; rotating/revoked API keys; endpoint URL typos; adding a new default model that requires an extra not installed in the image.

Related errors


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