#18027·langfuse

bug(sdk-js): getLangchainPrompt drops the closing brace of nested JSON

Author: sarmah-rupCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbugsdk-jsfeat-prompt-managementintegration-langchain

Describe the bug

getLangchainPrompt() drops the final closing brace when a prompt contains nested JSON. The model then receives malformed JSON.

Prompt text: Reply with JSON like {"user": {"name": "{{name}}"}}

getLangchainPrompt() returns Reply with JSON like {{"user": {{"name": "{name}"}} (two escaped opening braces, one escaped closing pair), and PromptTemplate.fromTemplate(...).format({ name: "Ann" }) renders Reply with JSON like {"user": {"name": "Ann"}. Deeper nesting loses one brace per }} run. Chat prompts are affected the same way.

Cause: escapeJsonForLangchain in packages/client/src/prompt/promptClients.ts treats every }} as already escaped and passes it through, even when the first } closes a JSON brace it doubled earlier.

Steps to reproduce

  1. Create a text prompt with the content above.
  2. const prompt = await langfuse.prompt.get(...); PromptTemplate.fromTemplate(prompt.getLangchainPrompt()).format({ name: "Ann" })
  3. The output is missing the last }.

Langfuse Cloud or self-hosted?

Langfuse Cloud

SDK and integration versions

@langfuse/client 5.11.1, @langchain/core

Are you interested in contributing a fix for this bug?

Yes, PR: https://github.com/langfuse/langfuse-js/pull/970