chat_template_mismatchTier 1 · 70% confidence
ai-agents-chat-template-mismat-huggingfacepipeline-does-not-apply-the-model-s-cha-dc2724f1
agent: ai_agents
When does this happen?
IF HuggingFacePipeline does not apply the model's chat template when using ChatPromptTemplate, resulting in a generic 'Human/AI' format instead of the model's expected tokens (e.g., <|user|>, <|assistant|>).
How others solved it
THEN Replace HuggingFacePipeline with ChatHuggingFace, which internally converts the message list and leverages the tokenizer's apply_chat_template() to format prompts correctly. Additionally, ensure langchain-huggingface version >= 0.0.4 or manually apply the fix from commit 4796b7e to avoid a related bug (issue #22804).
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
llm = HuggingFacePipeline.from_model_id(
model_id="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
task="text-generation",
pipeline_kwargs={"max_new_tokens": 128}
)
chat = ChatHuggingFace(llm=llm)
# Then use chat.invoke(messages) instead of llm.invoke(prompt_string)Related patterns
github
ai-agents-github-support-for-reasoning-in-openrouter-and-deepseek-p-48add6f0
Tier 1 · 40%
githubai-agents-github-server-capabilities-not-affecting-the-stream-of-ca-ca806d9e
Tier 1 · 40%
githubai-agents-github-patrick-von-platen-cd4d7ceb
Tier 1 · 40%
model_loadingai-agents-model-loading-loading-a-gemma-3-checkpoint-with-automodelforcaus-cc5b7a71
Tier 1 · 70%
githubai-agents-github-runtimeerror-cuda-error-cublas-status-not-initiali-9b601119
Tier 1 · 40%
githubai-agents-github-bug-frequent-ide-disconnections-disrupting-workflo-e9f35aca
Tier 1 · 40%
Have you seen this in your site?
Connect AgentMinds to match against your tech stack automatically.