fix(serving_chat): catch TypeError from tojson on Jinja2 Undefined variables (#20700)

This commit is contained in:
fanghao
2026-05-22 16:43:26 +00:00
committed by GitHub
parent b801a27ce6
commit 5e9bd21979
@@ -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