langchain-ai/langchain · error · ValueError
Partial variables are not supported for list of templates.
Error message
Partial variables are not supported for list of templates.
What it means
In BaseChatPromptTemplate.from_template / ChatPromptTemplate.from_messages, when the template is a sequence of message templates (a list), passing non-empty partial_variables raises ValueError. Partials are only wired through the single-string branch (delegated to PromptTemplate.from_template); the list branch has no mechanism to distribute partials across heterogeneous message templates.
Source
Thrown at libs/core/langchain_core/prompts/chat.py:451
Raises:
ValueError: If the template is not a string or list of strings.
"""
prompt: (
StringPromptTemplate
| list[StringPromptTemplate | ImagePromptTemplate | DictPromptTemplate]
)
if isinstance(template, str):
prompt = PromptTemplate.from_template(
template,
template_format=template_format,
partial_variables=partial_variables,
)
return cls(prompt=prompt, **kwargs)
if isinstance(template, Sequence):
if (partial_variables is not None) and len(partial_variables) > 0:
msg = "Partial variables are not supported for list of templates."
raise ValueError(msg)
prompt = []
for tmpl in template:
if isinstance(tmpl, str) or (
isinstance(tmpl, dict)
and "text" in tmpl
and set(tmpl.keys()) <= {"type", "text"}
):
if isinstance(tmpl, str):
text: str = tmpl
else:
text = cast("_TextTemplateParam", tmpl)["text"] # type: ignore[assignment]
prompt.append(
PromptTemplate.from_template(
text, template_format=template_format
)
)
elif (
isinstance(tmpl, dict)View on GitHub (pinned to e32fa9a52e)
Solutions
- Drop partial_variables from the from_messages/from_template call and call .partial(**vars) on the resulting ChatPromptTemplate instead
- Or bake the partial values directly into the message template strings
Example fix
# before
ChatPromptTemplate.from_messages(
["system: Answer in {lang}", "human: {q}"],
partial_variables={"lang": "English"}, # ValueError
)
# after
(ChatPromptTemplate.from_messages(
["system: Answer in {lang}", "human: {q}"],
).partial(lang="English")) Defensive patterns
Strategy: validation
Validate before calling
def build_chat_prompt(messages, partials: dict | None = None):
if isinstance(messages, (list, tuple)) and partials:
return ChatPromptTemplate.from_messages(messages).partial(**partials)
return ChatPromptTemplate.from_messages(messages, partial_variables=partials) Prevention
- Use .partial() on the constructed ChatPromptTemplate instead of passing partial_variables to from_messages with lists
When it happens
Trigger: Calling ChatPromptTemplate.from_messages([...], partial_variables={'lang': 'en'}) or from_template(list_of_templates, partial_variables={...}) with a non-empty dict and a non-None value.
Common situations: Developers trying to share a common partial (like a date or locale) across a multi-message prompt in one call, following the single-string API ergonomics.
Related errors
- Cannot save prompt with partial variables.
- variable {self.variable_name} should be a list of base messa
- Only one format variable allowed per image template.\nGot: {
- Invalid image template: {tmpl}
- jinja2 is unsafe and is not supported for templates expresse
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/f53b55f1b24bde30.
Report an issue: GitHub.