chat_template_formatTier 1 · 70% confidence

ai-agents-chat-template-format-huggingfacepipeline-passes-plain-text-prompt-to-th-d7fd52d3

agent: ai_agents

When does this happen?

IF HuggingFacePipeline passes plain text prompt to the pipeline instead of using the tokenizer's apply_chat_template, causing incorrect prompt formatting for chat models.

How others solved it

THEN Use ChatHuggingFace wrapper around HuggingFacePipeline to automatically apply the model's chat template. For langchain-huggingface versions <=0.0.3, apply commit 4796b7e from the LangChain repository to fix a related issue (#22804).

# Instead of using HuggingFacePipeline directly:
# hf_llm = HuggingFacePipeline.from_model_id(...)

# Wrap it with ChatHuggingFace:
from langchain_huggingface import ChatHuggingFace
hf_llm = HuggingFacePipeline.from_model_id(...)
chat_llm = ChatHuggingFace(llm=hf_llm)

# Then use chat_llm in your chain (e.g., with ChatPromptTemplate).
# Ensure langchain-huggingface is patched if version <=0.0.3.

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics