{"record":{"id":"538ef4a332161519","repo":"microsoft/graphrag","slug":"model-id-must-be-specified-for-litellm-tokenizer","errorCode":null,"errorMessage":"model_id must be specified for LiteLLM tokenizer.","messagePattern":"model_id must be specified for LiteLLM tokenizer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-llm/graphrag_llm/config/tokenizer_config.py","lineNumber":36,"sourceCode":"        default=TokenizerType.LiteLLM,\n        description=\"The type of tokenizer to use. [litellm] (default: litellm).\",\n    )\n\n    model_id: str | None = Field(\n        default=None,\n        description=\"The identifier for the tokenizer model. Example: openai/gpt-4o. Used by the litellm tokenizer.\",\n    )\n\n    encoding_name: str | None = Field(\n        default=None,\n        description=\"The encoding name for the tokenizer. Example: gpt-4o.\",\n    )\n\n    def _validate_litellm_config(self) -> None:\n        \"\"\"Validate LiteLLM tokenizer configuration.\"\"\"\n        if self.model_id is None or self.model_id.strip() == \"\":\n            msg = \"model_id must be specified for LiteLLM tokenizer.\"\n            raise ValueError(msg)\n\n    def _validate_tiktoken_config(self) -> None:\n        \"\"\"Validate TikToken tokenizer configuration.\"\"\"\n        if self.encoding_name is None or self.encoding_name.strip() == \"\":\n            msg = \"encoding_name must be specified for TikToken tokenizer.\"\n            raise ValueError(msg)\n\n    @model_validator(mode=\"after\")\n    def _validate_model(self):\n        \"\"\"Validate the tokenizer configuration based on its type.\"\"\"\n        if self.type == TokenizerType.LiteLLM:\n            self._validate_litellm_config()\n        elif self.type == TokenizerType.Tiktoken:\n            self._validate_tiktoken_config()\n        return self\n","sourceCodeStart":18,"sourceCodeEnd":52,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-llm/graphrag_llm/config/tokenizer_config.py#L18-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"Building a custom embedding/completion setup without specifying model_id; settings.yaml tokenizer block missing model_id; whitespace model_id from templated config.","solutions":["Set model_id on the tokenizer config, e.g. TokenizerConfig(type=\"litellm\", model_id=\"text-embedding-3-small\")","When calling create_embedding, pass model_id or an explicit tokenizer so the LiteLLM default gets a valid model"],"exampleFix":"# before\ncreate_embedding(model_config=cfg)  # no model_id anywhere\n# after\ncreate_embedding(model_config=cfg, model_id=\"text-embedding-3-small\")","handlingStrategy":"validation","validationCode":"if tok_cfg.get(\"type\") == \"litellm\" and not (tok_cfg.get(\"model_id\") or \"\").strip():\n    tok_cfg[\"model_id\"] = cfg[\"models\"][\"default\"][\"model\"]  # inherit model id\n# or raise if still empty","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass model_id/model explicitly to create_embedding","Mirror the model id into the tokenizer block when customizing it"],"tags":["tokenizer","litellm","config-validation","required-field"],"backgroundTag":"missing-required-config-field","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}