fix: support non-string content in message placeholders #601
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.
Problem
We are replacing message placeholders with messages containing images, which breaks the mustache rendering.
Changes
Release info Sub-libraries affected
Bump level
Libraries affected
Changelog notes
content
Important
Fixes
TypeError
inChatPromptClient.compile()
by ensuringcontent
is a string before mustache rendering, handling non-string content gracefully.TypeError
inChatPromptClient.compile()
by ensuringcontent
is a string before rendering with mustache.content
in message placeholders gracefully.This description was created by
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 checkstypeof 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:
Confidence score: 4/5
langfuse-core/src/prompts/promptClients.ts
to ensure the type checking logic is soundContext 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)