From c3b51891371e659c92936697c622df1162fb6eff Mon Sep 17 00:00:00 2001 From: Guillaume Calmettes Date: Wed, 9 Apr 2025 19:33:24 +0200 Subject: [PATCH] [Bugfix] catch AssertionError in MistralTokenizer as ValueError (#16344) Signed-off-by: Guillaume Calmettes --- vllm/entrypoints/chat_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/vllm/entrypoints/chat_utils.py b/vllm/entrypoints/chat_utils.py index 0e216f53c13b7..23c2c3cfd5811 100644 --- a/vllm/entrypoints/chat_utils.py +++ b/vllm/entrypoints/chat_utils.py @@ -1193,8 +1193,15 @@ def apply_mistral_chat_template( **kwargs, ) - return tokenizer.apply_chat_template( - messages=messages, - tools=tools, - **kwargs, - ) + try: + return tokenizer.apply_chat_template( + messages=messages, + tools=tools, + **kwargs, + ) + # mistral-common uses assert statements to stop processing of input + # if input does not comply with the expected format. + # We convert those assertion errors to ValueErrors so they can be + # are properly caught in the preprocessing_input step + except AssertionError as e: + raise ValueError from e