Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

nimarb
Copy link
Contributor

@nimarb nimarb commented Sep 16, 2025

fixes langfuse/langfuse#9097


Important

ChatPromptClient now uses a plain text format for unresolved placeholders compatible with LangChain, with updated tests to verify this behavior.

  • Behavior:
    • ChatPromptClient in promptClients.ts now converts unresolved placeholders to a plain text format compatible with LangChain, avoiding direct dependency on LangChain.
    • Updates getLangchainPrompt() to return placeholders as tuples like ["placeholder", "{name}"].
  • Tests:
    • Updates prompts.e2e.test.ts to verify new placeholder format in getLangchainPrompt().
    • Adds test to ensure compatibility with ChatPromptTemplate.fromMessages() for unresolved placeholders.

This description was created by Ellipsis for cf67c43. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Summary

Updated On: 2025-09-16 14:27:48 UTC

This PR fixes the format of unresolved message placeholders when converting Langfuse chat prompts to LangChain format. The core change addresses compatibility issues between Langfuse's getLangchainPrompt() method and LangChain's ChatPromptTemplate.fromMessages() functionality.

What Changed:
The PR modifies how unresolved placeholders are represented in the LangChain format conversion. Previously, placeholders were returned as objects with variableName and optional properties:

{
  variableName: item.name,
  optional: false
}

Now they are returned as simple tuples matching LangChain's native format:

["placeholder", `{${item.name}}`]

Integration with Codebase:
This change is part of the prompt management system in the packages/client/src/prompt/promptClients.ts file, specifically within the ChatPromptClient.getLangchainPrompt() method. The fix ensures that when users call this method to get LangChain-compatible prompts, the output can be directly consumed by LangChain's ChatPromptTemplate.fromMessages() without requiring additional transformation logic.

The change maintains Langfuse's independence from LangChain as a direct dependency while ensuring proper interoperability. The E2E tests were updated to reflect this new tuple format and include a new test case that verifies direct compatibility with ChatPromptTemplate.fromMessages().

PR Description Notes:

  • The PR description is minimal, containing only a link to the GitHub issue being fixed

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it fixes a clear compatibility issue without breaking existing functionality
  • Score reflects well-targeted changes that address a specific integration problem with comprehensive test coverage
  • Pay close attention to the test files to ensure the new tuple format is correctly validated across all scenarios

Context used:

Rule - Open a GitHub issue or discussion first before submitting PRs to explain the rationale and necessity of the proposed changes, as required by the contributing guide. (link)

Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
langfuse-js Ready Ready Preview Sep 17, 2025 1:57pm

@nimarb nimarb requested a review from hassiebp September 16, 2025 14:26
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@nimarb
Copy link
Contributor Author

nimarb commented Sep 16, 2025

failing test works locally -> flakey? should eventually probably move to recordings

@nimarb nimarb merged commit 7229b1a into main Sep 17, 2025
8 checks passed
@nimarb nimarb deleted the nimar/lfe-6697-resolve-placeholder-to-langchain branch September 17, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: getLangchainPrompt not handling unresolved placeholder
1 participant