{"record":{"id":"e6959cf733b8f2e0","repo":"microsoft/semantic-kernel","slug":"transformers-is-not-installed","errorCode":null,"errorMessage":"transformers is not installed.","messagePattern":"transformers is not installed\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/hugging_face/hf_prompt_execution_settings.py","lineNumber":33,"sourceCode":"\nclass HuggingFacePromptExecutionSettings(PromptExecutionSettings):\n    \"\"\"Hugging Face prompt execution settings.\"\"\"\n\n    do_sample: bool = True\n    max_new_tokens: int = 256\n    num_return_sequences: int = 1\n    stop_sequences: Any = None\n    pad_token_id: int = 50256\n    eos_token_id: int = 50256\n    temperature: float = 1.0\n    top_p: float = 1.0\n\n    def get_generation_config(self) -> \"GenerationConfig\":\n        \"\"\"Get the generation config.\"\"\"\n        from transformers import GenerationConfig\n\n        if not ready:\n            raise ImportError(\"transformers is not installed.\")\n\n        return GenerationConfig(\n            **self.model_dump(\n                include={\"max_new_tokens\", \"pad_token_id\", \"eos_token_id\", \"temperature\", \"top_p\"},\n                exclude_unset=False,\n                exclude_none=True,\n                by_alias=True,\n            )\n        )\n\n    def prepare_settings_dict(self, **kwargs) -> dict[str, Any]:\n        \"\"\"Prepare the settings dictionary.\"\"\"\n        gen_config = self.get_generation_config()\n        settings = {\n            \"generation_config\": gen_config,\n            \"num_return_sequences\": self.num_return_sequences,\n            \"do_sample\": self.do_sample,\n        }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/hugging_face/hf_prompt_execution_settings.py#L15-L51","documentation":"Raised by HuggingFacePromptExecutionSettings.get_generation_config() when the module-level 'ready' flag is False. 'ready' is computed at import time by attempting to import the 'transformers' package and checking for GenerationConfig; if transformers isn't installed or lacks that symbol, calling get_generation_config (and thus prepare_settings_dict) raises ImportError.","triggerScenarios":"Calling a HuggingFace text-completion flow without the 'transformers' extra installed, or with a transformers version so old it lacks GenerationConfig. Triggered when prepare_settings_dict() is invoked to build generation config.","commonSituations":"Installing semantic-kernel without the hugging_face/transformers extra. Downgrading transformers below the required version. Running in a slimmed image that strips optional deps.","solutions":["Install the transformers dependency: pip install transformers (or the project's hugging-face extra).","Verify importlib can resolve transformers and that GenerationConfig exists: python -c 'from transformers import GenerationConfig'.","Pin a compatible transformers version per the project's requirements.","Ensure the same environment that loads HuggingFacePromptExecutionSettings also has transformers installed."],"exampleFix":"# before: transformers missing\npip install transformers\n# after\npython -c \"from transformers import GenerationConfig; print('ok')\"","handlingStrategy":"validation","validationCode":"import importlib\n_ready = False\ntry:\n    m = importlib.import_module('transformers')\n    _ready = hasattr(m, 'GenerationConfig')\nexcept ImportError:\n    _ready = False\nassert _ready, 'Install transformers: pip install transformers'","typeGuard":"def transformers_ready() -> bool:\n    import importlib\n    try:\n        return hasattr(importlib.import_module('transformers'), 'GenerationConfig')\n    except ImportError:\n        return False","tryCatchPattern":null,"preventionTips":["Install the hugging-face/transformers extra in every environment that uses HF connectors.","Pin a transformers version that exposes GenerationConfig.","Check the 'ready' flag (or run an import probe) before calling HF completion flows."],"tags":["hugging-face","dependencies","transformers","installation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}