Skip to content

fix(prompts): escape json in getLangchainPrompt #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025

Conversation

hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jun 26, 2025

Important

Improved JSON handling in Langchain prompt conversion by escaping JSON curly braces and updating variable matching logic, with comprehensive tests added.

  • Behavior:
    • Added escapeJsonForLangchain method in promptClients.ts to escape JSON curly braces while preserving Mustache variables.
    • Updated regex in _transformToLangchainVariables to match only word characters.
    • Ensures JSON objects in prompts maintain structure when converted to Langchain format.
  • Tests:
    • Added tests in langfuse.prompts.spec.ts for JSON escaping, including edge cases like nested JSON, mixed variables, and empty objects.
  • Misc:
    • Updated package.json to include yarn as the package manager.

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


Greptile Summary

Disclaimer: Experimental PR review

Fixed JSON handling in Langchain prompt conversion by improving variable transformation logic to properly escape JSON curly braces while preserving Mustache template variables.

  • Modified langfuse-core/src/prompts/promptClients.ts to add escapeJsonForLangchain method that correctly handles JSON structures in prompts
  • Updated variable matching regex to only accept word characters (\w+), making it more precise
  • Added comprehensive test suite in langfuse-core/test/langfuse.prompts.spec.ts covering JSON escaping edge cases
  • Ensures JSON objects in prompts maintain their structure when converted to Langchain format

Copy link

vercel bot commented Jun 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
langfuse-js ✅ Ready (Inspect) Visit Preview Jun 26, 2025 0:19am

Copy link

@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.

LGTM

2 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@hassiebp hassiebp merged commit 8f159dc into main Jun 26, 2025
7 of 9 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-5472-fix-json-in-langchain-prompts branch June 26, 2025 12:51
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.

1 participant