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

Skip to content

Conversation

marcesengel
Copy link

@marcesengel marcesengel commented Sep 1, 2025

Problem

We are replacing message placeholders with messages containing images, which breaks the mustache rendering.

TypeError: Invalid template! Template should be a "string" but "array" was given as the first argument for mustache#render(template, view, partials)
    at render (/node_modules/mustache/mustache.mjs:747:11)
    at item (/node_modules/langfuse-core/src/prompts/promptClients.ts:241:29)
    at Array.map (<anonymous>)
    at compile (/node_modules/langfuse-core/src/prompts/promptClients.ts:237:45)

Changes

Release info Sub-libraries affected

Bump level

  • Major
  • Minor
  • Patch

Libraries affected

  • All of them
  • langfuse
  • langfuse-node

Changelog notes

  • Fixed message placeholder replacements with non-string content

Important

Fixes TypeError in ChatPromptClient.compile() by ensuring content is a string before mustache rendering, handling non-string content gracefully.

  • Behavior:
    • Fixes TypeError in ChatPromptClient.compile() by ensuring content is a string before rendering with mustache.
    • Handles non-string content in message placeholders gracefully.
  • Misc:
    • Affects all libraries, marked as a patch-level change.

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

Disclaimer: Experimental PR review

Greptile Summary

Updated On: 2025-09-01 09:12:49 UTC

This PR fixes a critical bug in the prompt client system where mustache template rendering would fail when processing ChatMessage content that isn't a string. The issue occurred when trying to use message placeholders with multimodal content (like messages containing images), where the content field contains arrays or objects instead of plain strings.

The fix is implemented in langfuse-core/src/prompts/promptClients.ts by adding a type guard that checks typeof item.content === "string" before applying mustache rendering. This ensures that only string content goes through template processing, while complex content structures (arrays, objects with image data, etc.) are left untouched.

This change aligns with modern AI applications that use multimodal content in chat messages, where the content field can contain structured data beyond simple text. The solution maintains backward compatibility for existing string-based prompts while enabling support for more complex message formats without breaking the rendering pipeline.

PR Description Notes:

  • The "Changes" section in the PR description is empty and should describe what was actually modified
  • Consider opening a GitHub issue first to discuss the rationale for this change as required by the contributing guidelines

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it addresses a specific runtime error without changing core functionality
  • Score reflects a targeted fix with clear error reproduction and minimal code changes that preserve existing behavior
  • Pay close attention to langfuse-core/src/prompts/promptClients.ts to ensure the type checking logic is sound

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 1, 2025

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

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2025

CLA assistant check
All committers have signed the CLA.

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.

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@hassiebp hassiebp requested review from hassiebp and nimarb and removed request for hassiebp September 2, 2025 10:03
@nimarb
Copy link
Contributor

nimarb commented Sep 2, 2025

Hi @marcesengel , thank you for the contribution! Could you add a single simple test case for this (or add it to an existing test)? Thank you. Please check e.g. tests/e2e/prompts.e2e.test.ts lines 1193 and following where a good test would fit.

@OzzieOrca
Copy link

I'm also having this issue using Vercel's AI SDK where the content key is often an array of parts, not just a string.

Let me know if I can help. Are one of you working on the tests?

@marcesengel
Copy link
Author

Sorry currently not, I just wanted to share the fix (you can install from @marces/langfuse if you'd like) but atm don't have the time to take care of the additional tests.

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.

4 participants