-
Notifications
You must be signed in to change notification settings - Fork 19.8k
Labels
bugRelated to a bug, vulnerability, unexpected error with an existing featureRelated to a bug, vulnerability, unexpected error with an existing featurecoreRelated to the package `langchain-core`Related to the package `langchain-core`
Description
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- This is not related to the langchain-community package.
- I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain_core.messages import HumanMessage
print("Testing all ChatPromptTemplate.from_messages() syntax options:\n")
# 0. BaseMessagePromptTemplate
try:
p0 = ChatPromptTemplate.from_messages(
[HumanMessagePromptTemplate.from_template("{input}")]
)
print("0. ✓ BaseMessagePromptTemplate - creation works")
result0 = p0.invoke({"input": "hello world"})
print(f" Result: {result0.to_messages()[-1].content}")
except Exception as e:
print(f"0. ✗ BaseMessagePromptTemplate: {e}")
print()
# 1. BaseMessage (Message instance)
try:
p1 = ChatPromptTemplate.from_messages([HumanMessage(content="{input}")])
print("1. ✓ BaseMessage (Message instance) - creation works")
result1 = p1.invoke({"input": "hello world"})
print(f" Result: {result1.to_messages()[-1].content}")
except Exception as e:
print(f"1. ✗ BaseMessage (Message instance): {e}")
print()
# 2. 2-tuple of (message type, template)
try:
p2 = ChatPromptTemplate.from_messages([("human", "{input}")])
print("2. ✓ 2-tuple of (message type, template) - creation works")
result2 = p2.invoke({"input": "hello world"})
print(f" Result: {result2.to_messages()[-1].content}")
except Exception as e:
print(f"2. ✗ 2-tuple of (message type, template): {e}")
print()
# 3. 2-tuple of (message class, template)
try:
p3 = ChatPromptTemplate.from_messages([(HumanMessage, "{input}")])
print("3. ✓ 2-tuple of (message class, template) - creation works")
result3 = p3.invoke({"input": "hello world"})
print(f" Result: {result3.to_messages()[-1].content}")
except Exception as e:
print(f"3. ✗ 2-tuple of (message class, template): {e}")
print()
# 4. String shorthand for ("human", template)
try:
p4 = ChatPromptTemplate.from_messages(["{input}"])
print("4. ✓ String shorthand - creation works")
result4 = p4.invoke({"input": "hello world"})
print(f" Result: {result4.to_messages()[-1].content}")
except Exception as e:
print(f"4. ✗ String shorthand: {e}")
Error Message and Stack Trace (if applicable)
Testing all ChatPromptTemplate.from_messages() syntax options:
0. ✓ BaseMessagePromptTemplate - creation works
Result: hello world
1. ✓ BaseMessage (Message instance) - creation works
Result: {input}
2. ✓ 2-tuple of (message type, template) - creation works
Result: hello world
3. ✗ 2-tuple of (message class, template): 2 validation errors for HumanMessage
content.str
Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[union[str,dict[any,any]]]
Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.12/v/list_type
4. ✓ String shorthand - creation works
Result: hello world
Description
Although the docs state that ChatPromptTemplate.from_messages() accepts (message class, template) tuples, it doesn't. See the MWE and the output.
System Info
System Information
------------------
> OS: Linux
> OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
> Python Version: 3.10.12 (main, Aug 15 2025, 14:32:43) [GCC 11.4.0]
Package Information
-------------------
> langchain_core: 1.0.2
> langchain: 1.0.3
> langchain_community: 0.4.1
> langsmith: 0.4.38
> langchain_classic: 1.0.0
> langchain_openai: 1.0.1
> langchain_text_splitters: 1.0.0
> langgraph_sdk: 0.2.9
Optional packages not installed
-------------------------------
> langserve
Other Dependencies
------------------
> aiohttp: 3.13.2
> async-timeout: 4.0.3
> claude-agent-sdk: Installed. No version info available.
> dataclasses-json: 0.6.7
> httpx: 0.28.1
> httpx-sse: 0.4.3
> jsonpatch: 1.33
> langchain-anthropic: Installed. No version info available.
> langchain-aws: Installed. No version info available.
> langchain-deepseek: Installed. No version info available.
> langchain-fireworks: Installed. No version info available.
> langchain-google-genai: Installed. No version info available.
> langchain-google-vertexai: Installed. No version info available.
> langchain-groq: Installed. No version info available.
> langchain-huggingface: Installed. No version info available.
> langchain-mistralai: Installed. No version info available.
> langchain-ollama: Installed. No version info available.
> langchain-perplexity: Installed. No version info available.
> langchain-together: Installed. No version info available.
> langchain-xai: Installed. No version info available.
> langgraph: 1.0.2
> langsmith-pyo3: Installed. No version info available.
> numpy: 2.2.6
> openai: 2.6.1
> openai-agents: Installed. No version info available.
> opentelemetry-api: Installed. No version info available.
> opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
> opentelemetry-sdk: Installed. No version info available.
> orjson: 3.11.4
> packaging: 25.0
> pydantic: 2.12.3
> pydantic-settings: 2.11.0
> pytest: Installed. No version info available.
> PyYAML: 6.0.3
> pyyaml: 6.0.3
> requests: 2.32.5
> requests-toolbelt: 1.0.0
> rich: Installed. No version info available.
> SQLAlchemy: 2.0.44
> sqlalchemy: 2.0.44
> tenacity: 9.1.2
> tiktoken: 0.12.0
> typing-extensions: 4.15.0
> vcrpy: Installed. No version info available.
> zstandard: 0.25.0
Metadata
Metadata
Assignees
Labels
bugRelated to a bug, vulnerability, unexpected error with an existing featureRelated to a bug, vulnerability, unexpected error with an existing featurecoreRelated to the package `langchain-core`Related to the package `langchain-core`