diff --git a/src/cpp/src/tokenizer.cpp b/src/cpp/src/tokenizer.cpp index 2f18e87839..b22f103577 100644 --- a/src/cpp/src/tokenizer.cpp +++ b/src/cpp/src/tokenizer.cpp @@ -575,13 +575,18 @@ class Tokenizer::TokenizerImpl { {"slice", slice_callable}, }; + std::string result; try { - return tpl.RenderAsString(params).value(); + result = tpl.RenderAsString(params).value(); } catch (const std::exception& error) { OPENVINO_THROW("Chat template for the current model is not supported by Jinja2Cpp. " "Please apply template manually to your prompt before calling generate. " "For example: user{user_prompt}model"); } + OPENVINO_ASSERT(!result.empty(), "Applied chat template resulted in an empty string. " + "Please check the chat template or apply template manually to your prompt before calling generate." + "For example: user{user_prompt}model"); + return result; } void set_chat_template(const std::string& chat_template) {