{"record":{"id":"d9f4a145f2b6b105","repo":"sgl-project/sglang","slug":"id2label-mapping-is-missing","errorCode":null,"errorMessage":"id2label mapping is missing","messagePattern":"id2label mapping is missing","errorType":"exception","errorClass":"ValueError","httpStatus":500,"severity":"critical","filePath":"python/sglang/srt/entrypoints/openai/serving_classify.py","lineNumber":45,"sourceCode":"\nclass OpenAIServingClassify(OpenAIServingBase):\n    \"\"\"Handler for v1/classify requests\"\"\"\n\n    def __init__(\n        self,\n        tokenizer_manager: TokenizerManager,\n        template_manager: TemplateManager,\n    ):\n        super().__init__(tokenizer_manager)\n        self.template_manager = template_manager\n        self.id2label = self._get_id2label_mapping()\n        self.model_name = (\n            self.tokenizer_manager.served_model_name\n            if self.tokenizer_manager.served_model_name\n            else self.tokenizer_manager.model_path\n        )\n        if not self.id2label:\n            raise ValueError(\"id2label mapping is missing\")\n\n    def _request_id_prefix(self) -> str:\n        return \"classify-\"\n\n    def _convert_to_internal_request(\n        self,\n        request: ClassifyRequest,\n        raw_request: Request = None,\n    ) -> tuple[EmbeddingReqInput, ClassifyRequest]:\n        \"\"\"Convert OpenAI embedding request to internal format\"\"\"\n        prompt = request.input\n\n        if isinstance(prompt, str):\n            # Single string input\n            prompt_kwargs = {\"text\": prompt}\n        elif isinstance(prompt, list):\n            if len(prompt) > 0 and isinstance(prompt[0], str):\n                prompt_kwargs = {\"text\": prompt}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/serving_classify.py#L27-L63","documentation":"OpenAIEmbedding-style classify serving requires the model config to define id2label (classification label mapping) to build response labels. If the loaded model's config has no id2label, the ClassifyService __init__ aborts at startup with this ValueError.","triggerScenarios":"Launching the server with a classification/classify serving path for a model whose config.json lacks an id2label mapping.","commonSituations":"Pointing --model-path at a checkpoint missing classification head metadata; using a base/embedding model with the classify endpoint enabled; a converted/merged model that dropped id2label during export.","solutions":["Use a model checkpoint that includes id2label in config.json (proper classification model)","Add/restore the id2label map to the model's config.json if the head exists","Don't expose the classify endpoint for models that aren't classifiers"],"exampleFix":"// config.json before: {}\n// after\n{\"id2label\": {\"0\": \"negative\", \"1\": \"positive\"}}","handlingStrategy":"validation","validationCode":"import json; cfg = json.load(open(model_config_path)); assert cfg.get('id2label'), 'model lacks id2label'","typeGuard":"def is_classifier(config) -> bool: return isinstance(config.get('id2label'), dict) and len(config['id2label']) > 0","tryCatchPattern":null,"preventionTips":["Pre-check config.json for id2label before launching classify serving","Use genuine classification checkpoints","Validate exported models retain head metadata"],"tags":["classify","model-config","startup"],"backgroundTag":"model-config-missing-field","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}