microsoft/graphrag · error · ValueError

model_id must be specified for LiteLLM tokenizer.

Error message

model_id must be specified for LiteLLM tokenizer.

What it means

TokenizerConfig validation requires model_id when using the LiteLLM tokenizer, because LiteLLM resolves tokenizers by model identifier. A missing or blank model_id is rejected at config load.

Source

Thrown at packages/graphrag-llm/graphrag_llm/config/tokenizer_config.py:36

        default=TokenizerType.LiteLLM,
        description="The type of tokenizer to use. [litellm] (default: litellm).",
    )

    model_id: str | None = Field(
        default=None,
        description="The identifier for the tokenizer model. Example: openai/gpt-4o. Used by the litellm tokenizer.",
    )

    encoding_name: str | None = Field(
        default=None,
        description="The encoding name for the tokenizer. Example: gpt-4o.",
    )

    def _validate_litellm_config(self) -> None:
        """Validate LiteLLM tokenizer configuration."""
        if self.model_id is None or self.model_id.strip() == "":
            msg = "model_id must be specified for LiteLLM tokenizer."
            raise ValueError(msg)

    def _validate_tiktoken_config(self) -> None:
        """Validate TikToken tokenizer configuration."""
        if self.encoding_name is None or self.encoding_name.strip() == "":
            msg = "encoding_name must be specified for TikToken tokenizer."
            raise ValueError(msg)

    @model_validator(mode="after")
    def _validate_model(self):
        """Validate the tokenizer configuration based on its type."""
        if self.type == TokenizerType.LiteLLM:
            self._validate_litellm_config()
        elif self.type == TokenizerType.Tiktoken:
            self._validate_tiktoken_config()
        return self

View on GitHub (pinned to f40e9a26ce)

Solutions

  1. Set model_id on the tokenizer config, e.g. TokenizerConfig(type="litellm", model_id="text-embedding-3-small")
  2. When calling create_embedding, pass model_id or an explicit tokenizer so the LiteLLM default gets a valid model

Example fix

# before
create_embedding(model_config=cfg)  # no model_id anywhere
# after
create_embedding(model_config=cfg, model_id="text-embedding-3-small")
Defensive patterns

Strategy: validation

Validate before calling

if tok_cfg.get("type") == "litellm" and not (tok_cfg.get("model_id") or "").strip():
    tok_cfg["model_id"] = cfg["models"]["default"]["model"]  # inherit model id
# or raise if still empty

Prevention

When it happens

Trigger: TokenizerConfig(type=TokenizerType.LiteLLM) with model_id=None or model_id="" in code or settings.yaml; also when create_embedding is called and no tokenizer/model_id is supplied, since it defaults to a LiteLLM TokenizerConfig.

Common situations: Building a custom embedding/completion setup without specifying model_id; settings.yaml tokenizer block missing model_id; whitespace model_id from templated config.

Related errors


AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27). Data as JSON: /api/errors/538ef4a332161519. Report an issue: GitHub.