zylon-ai/private-gpt · error · ImportError

Mistral tokenizer dependencies are not installed. Install wi

Error message

Mistral tokenizer dependencies are not installed. Install with `uv sync --inexact --extra llm-mistral`.

What it means

MistralTokenizer lazily imports modules from mistral_common via _load_mistral_module; module-level imports like mistral_common.protocol.instruct.messages run at import time. If mistral-common is missing, ImportError is raised with the hint to install the llm-mistral extra.

Source

Thrown at private_gpt/components/llm/tokenizers/mistral.py:34

    AudioLike,
    ImageLike,
    TextLike,
    TokenizedInput,
    TokenizerBase,
)
from private_gpt.utils.dependencies import format_missing_dependency_message

ChatMessageType: TypeAlias = Any
Tokenized: TypeAlias = Any
PublicMistralTokenizer: TypeAlias = Any


@lru_cache
def _load_mistral_module(module_name: str) -> Any:
    try:
        return importlib.import_module(module_name)
    except ImportError as e:
        raise ImportError(
            format_missing_dependency_message(
                "Mistral tokenizer",
                extras="llm-mistral",
            )
        ) from e


_messages_module = _load_mistral_module("mistral_common.protocol.instruct.messages")
AssistantMessage = _messages_module.AssistantMessage
SystemMessage = _messages_module.SystemMessage
ToolMessage = _messages_module.ToolMessage
UserMessage = _messages_module.UserMessage

logger = logging.getLogger(__name__)


def is_list_of(
    value: object,

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Install the extra: uv sync --inexact --extra llm-mistral.
  2. Verify: python -c "import mistral_common".
  3. If Mistral is not intended, change tokenizer_mode away from 'mistral'.

Example fix

# before: tokenizer_mode='mistral' without mistral-common
# after
uv sync --inexact --extra llm-mistral
Defensive patterns

Strategy: validation

Validate before calling

def mistral_deps_available() -> bool:
    try:
        import mistral_common  # noqa: F401
        return True
    except ImportError:
        return False

assert mistral_deps_available(), 'install: uv sync --inexact --extra llm-mistral'

Try / catch

try:
    from private_gpt.components.llm.tokenizers.mistral import MistralTokenizer
except ImportError as e:
    raise RuntimeError('tokenizer_mode=mistral requires the llm-mistral extra') from e

Prevention

When it happens

Trigger: Importing private_gpt.components.llm.tokenizers.mistral (or using tokenizer_mode='mistral') in an environment where mistral-common is not installed. Because several imports happen at module level, the error fires as soon as the module is imported.

Common situations: Minimal installs without the llm-mistral extra; deploying for a different backend (openai/local) but config or DI still selects the mistral tokenizer; fresh venvs created from a trimmed lockfile.

Related errors


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