Skip to content

Conversation

@hyattc1
Copy link

@hyattc1 hyattc1 commented Nov 16, 2025

Description

This PR fixes the incomplete conversion logic in ChatPromptTemplate.from_messages that prevented the documented (message class, template) tuple syntax from working.

Previously, passing tuples like (HumanMessage, "{input}") raised a Pydantic validation error because BaseMessage subclasses were not handled.
This adds the missing branch that detects message classes with a type field and creates the appropriate template using _create_template_from_message_type.

Changes

  • Updated _convert_to_message_template to properly support (message class, template) tuples.
  • Added a unit test covering HumanMessage, AIMessage, and SystemMessage.

Issue

Fixes #33791

Dependencies

None

Noting that the failing Pydantic tests are also failing on main right now.
This PR appears unrelated to the breakage.

…essages

Adds missing conversion logic so BaseMessage subclasses work when provided
as (message class, template) tuples. Includes tests for HumanMessage,
AIMessage, and SystemMessage.
@hyattc1 hyattc1 requested a review from eyurtsev as a code owner November 16, 2025 08:22
@github-actions github-actions bot added core Related to the package `langchain-core` fix labels Nov 16, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 16, 2025

CodSpeed Performance Report

Merging #33989 will not alter performance

Comparing hyattc1:fix-message-class-tuple (8013ea6) with master (52b1516)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions github-actions bot added fix and removed fix labels Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to the package `langchain-core` fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatPromptTemplate.from_messages() doesn't support (message class, template) tuples

1 participant