sgl-project/sglang · error · ValueError
{template_error}{suffix}
Error message
{template_error}{suffix} What it means
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.
Source
Thrown at python/sglang/srt/entrypoints/openai/serving_embedding.py:239
template_content_format,
image_data=[],
video_data=[],
audio_data=[],
modalities=[],
)
try:
prompt = self.tokenizer_manager.tokenizer.apply_chat_template(
[processed_msg],
tokenize=False,
add_generation_prompt=True,
)
except jinja2.TemplateError as template_error:
location = getattr(template_error, "lineno", None)
name = getattr(template_error, "name", None)
suffix = ""
if name or location:
suffix = f" (template={name or '<unknown>'}, line={location})"
raise ValueError(f"{template_error}{suffix}") from template_error
except (TypeError, KeyError, AttributeError) as template_error:
raise ValueError(
f"Failed to render chat template for embedding input: {template_error}"
) from template_error
prompts.append(prompt)
return prompts
async def _handle_non_streaming_request(
self,
adapted_request: EmbeddingReqInput,
request: EmbeddingRequest,
raw_request: Request,
) -> Union[EmbeddingResponse, ErrorResponse, ORJSONResponse]:
"""Handle the embedding request"""
try:
ret = await self.tokenizer_manager.generate_request(
adapted_request, raw_requestView on GitHub (pinned to 0132848349)
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
Defensive patterns
Strategy: try-catch
Validate before calling
from jinja2 import Environment; Environment().parse(open(template_path).read()) # syntax pre-check
Try / catch
except ValueError as e: report template name/line from message back to user
Prevention
- Lint templates with jinja2 parse before server launch
- Keep embedding chat templates version-controlled
- Test render with a sample payload in CI
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to render chat template for embedding input: {templat
- {template_error}
- Invalid content format: {content_format}
- Invalid thinking_mode `{thinking_mode}`
- Unknown role: {role}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/4d64dbfd47329976.
Report an issue: GitHub.