Template variable handling in ChatPromptTemplate #29034 #29056
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for contributing to LangChain!
Title: core: fix template variable handling in ChatPromptTemplate BaseMessage objects #29043
Description:
Fixes a bug in ChatPromptTemplate where template variables in BaseMessage objects (like SystemMessage) were not being processed. Previously, template variables in direct BaseMessage instances would be left unformatted, while variables in MessagePromptTemplate instances were processed correctly. This PR modifies the
format_messages
method to properly handle template variables in all message types.Example of the bug:
Before fix:
After fix:
The fix adds template variable processing for BaseMessage objects while maintaining backward compatibility and existing functionality for other message types.
Key changes:
format_messages
method to detect and process template variables in BaseMessage contentImplementation details:
@baskaryan, @efriis, @eyurtsev, @ccurme