Skip to content

docs: use ChatPromptTemplate.fromMessages for LangChain chat prompts#2981

Open
bensondavis wants to merge 2 commits into
langfuse:mainfrom
bensondavis:docs/fix-langchain-chat-prompt-from-messages
Open

docs: use ChatPromptTemplate.fromMessages for LangChain chat prompts#2981
bensondavis wants to merge 2 commits into
langfuse:mainfrom
bensondavis:docs/fix-langchain-chat-prompt-from-messages

Conversation

@bensondavis
Copy link
Copy Markdown

@bensondavis bensondavis commented May 22, 2026

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 by getLangchainPrompt() / get_langchain_prompt(), switching them to the appropriate fromMessages / from_messages constructors.

  • variables.mdx: Both the Python (from_templatefrom_messages) and TypeScript (fromTemplatefromMessages with .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 to fromMessages() but omits the .map((m) => [m.role, m.content]) transform that converts plain {role, content} objects from the SDK into the [role, content] tuples that fromMessages() 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)"
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
content/docs/prompt-management/features/message-placeholders.mdx:182-184
The TypeScript fix should use `.map((m) => [m.role, m.content])` to convert the plain objects returned by `getLangchainPrompt()` into the `[role, content]` tuples that `fromMessages()` expects — the same pattern applied in `variables.mdx` and in the official Langfuse get-started docs. LangChain handles the `"placeholder"` role inside `fromMessages`, so `MessagesPlaceholder` objects will still be created correctly.

```suggestion
const langchainPrompt = ChatPromptTemplate.fromMessages(
  langfusePrompt.getLangchainPrompt().map((m) => [m.role, m.content])
);
```

Reviews (1): Last reviewed commit: "docs: use ChatPromptTemplate.fromMessage..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

fromTemplate is for text prompts only; chat prompts from getLangchainPrompt()
must use from_messages/fromMessages.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

@bensondavis is attempting to deploy a commit to the langfuse Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. documentation Improvements or additions to documentation labels May 22, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 22, 2026

CLA assistant check
All committers have signed the CLA.

Comment thread content/docs/prompt-management/features/message-placeholders.mdx
…xample

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants