{"record":{"id":"4d64dbfd47329976","repo":"sgl-project/sglang","slug":"template-error-suffix","errorCode":null,"errorMessage":"{template_error}{suffix}","messagePattern":"\\{template_error\\}\\{suffix\\}","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/serving_embedding.py","lineNumber":239,"sourceCode":"                template_content_format,\n                image_data=[],\n                video_data=[],\n                audio_data=[],\n                modalities=[],\n            )\n            try:\n                prompt = self.tokenizer_manager.tokenizer.apply_chat_template(\n                    [processed_msg],\n                    tokenize=False,\n                    add_generation_prompt=True,\n                )\n            except jinja2.TemplateError as template_error:\n                location = getattr(template_error, \"lineno\", None)\n                name = getattr(template_error, \"name\", None)\n                suffix = \"\"\n                if name or location:\n                    suffix = f\" (template={name or '<unknown>'}, line={location})\"\n                raise ValueError(f\"{template_error}{suffix}\") from template_error\n            except (TypeError, KeyError, AttributeError) as template_error:\n                raise ValueError(\n                    f\"Failed to render chat template for embedding input: {template_error}\"\n                ) from template_error\n            prompts.append(prompt)\n\n        return prompts\n\n    async def _handle_non_streaming_request(\n        self,\n        adapted_request: EmbeddingReqInput,\n        request: EmbeddingRequest,\n        raw_request: Request,\n    ) -> Union[EmbeddingResponse, ErrorResponse, ORJSONResponse]:\n        \"\"\"Handle the embedding request\"\"\"\n        try:\n            ret = await self.tokenizer_manager.generate_request(\n                adapted_request, raw_request","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/serving_embedding.py#L221-L257","documentation":"While rendering an embedding input through the Jinja chat template, a jinja2.TemplateError (e.g. TemplateSyntaxError, TemplateNotFound) occurred. The embedding serving layer rethrows it as ValueError with the template name and line number so clients get a 400 rather than a 500.","triggerScenarios":"POST /v1/embeddings with chat-template input (e.g. messages or a --chat-template for embedding models) where the template itself is malformed or references an undefined construct that raises TemplateError.","commonSituations":"Supplying a broken custom --chat-template for an embedding/reranker model; template syntax errors introduced when hand-editing; template referencing variables not present in embedding requests.","solutions":["Check the reported (template=..., line=...) in the message and fix the template syntax at that line","Validate the template renders standalone with jinja2 before passing it to the server","Use the tokenizer's built-in chat template for embedding models like Qwen3-Embedding"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from jinja2 import Environment; Environment().parse(open(template_path).read())  # syntax pre-check","typeGuard":null,"tryCatchPattern":"except ValueError as e: report template name/line from message back to user","preventionTips":["Lint templates with jinja2 parse before server launch","Keep embedding chat templates version-controlled","Test render with a sample payload in CI"],"tags":["jinja","embeddings","chat-template"],"backgroundTag":"chat-template-render-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}