docs: use ChatPromptTemplate.fromMessages for LangChain chat prompts#2981
Open
bensondavis wants to merge 2 commits into
Open
docs: use ChatPromptTemplate.fromMessages for LangChain chat prompts#2981bensondavis wants to merge 2 commits into
bensondavis wants to merge 2 commits into
Conversation
fromTemplate is for text prompts only; chat prompts from getLangchainPrompt() must use from_messages/fromMessages. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@bensondavis is attempting to deploy a commit to the langfuse Team on Vercel. A member of the Team first needs to authorize it. |
…xample Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fromTemplate is for text prompts only; chat prompts from getLangchainPrompt() must use from_messages/fromMessages.
Greptile Summary
This PR corrects documentation code samples that incorrectly used
ChatPromptTemplate.fromTemplate(a text-only API) for chat prompts returned bygetLangchainPrompt()/get_langchain_prompt(), switching them to the appropriatefromMessages/from_messagesconstructors.variables.mdx: Both the Python (from_template→from_messages) and TypeScript (fromTemplate→fromMessageswith.map((m) => [m.role, m.content])) fixes are correct and consistent with official Langfuse docs.message-placeholders.mdx: The Python fix is correct. The TypeScript fix switches tofromMessages()but omits the.map((m) => [m.role, m.content])transform that converts plain{role, content}objects from the SDK into the[role, content]tuples thatfromMessages()requires — leaving the example non-functional.Confidence Score: 3/5
The TypeScript snippet in message-placeholders.mdx is still broken — it calls fromMessages() without the .map() transform, so readers copying it will hit a runtime error. The variables.mdx fixes are solid.
The variables.mdx changes are correct and improve existing broken examples. However, the TypeScript example in message-placeholders.mdx omits the .map((m) => [m.role, m.content]) call that all official Langfuse docs apply when feeding getLangchainPrompt() into fromMessages(). Without it, plain {role, content} objects are passed where [role, content] tuples are required, leaving the example non-functional after the fix.
content/docs/prompt-management/features/message-placeholders.mdx — the TypeScript block at the fromMessages() call needs the .map() transform added.
Sequence Diagram
sequenceDiagram participant App participant LangfuseSDK participant LangChain App->>LangfuseSDK: getLangchainPrompt() LangfuseSDK-->>App: "[{role, content}, ...]" Note over App: .map((m) => [m.role, m.content]) App->>LangChain: ChatPromptTemplate.fromMessages([[role, content], ...]) LangChain-->>App: "ChatPromptTemplate (with MessagesPlaceholder if role=placeholder)"Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "docs: use ChatPromptTemplate.fromMessage..." | Re-trigger Greptile