diff --git a/python/sglang/srt/entrypoints/openai/serving_chat.py b/python/sglang/srt/entrypoints/openai/serving_chat.py index 973ae28ce..5b31de242 100644 --- a/python/sglang/srt/entrypoints/openai/serving_chat.py +++ b/python/sglang/srt/entrypoints/openai/serving_chat.py @@ -785,8 +785,9 @@ class OpenAIServingChat(OpenAIServingBase): prompt_ids = self.tokenizer_manager.tokenizer.encode( rendered_prompt, **encode_kwargs ) - except jinja2.TemplateError as template_error: + except (jinja2.TemplateError, TypeError) as template_error: # Template errors (e.g., from raise_exception in Jinja templates) + # and TypeError (e.g., tojson filter on Jinja2 Undefined variables) # should be treated as client errors (400 BadRequest) raise ValueError(str(template_error)) from template_error