Rolex
Rolex4mo ago

Hey

Hey I am using langfuse with langchain integrations. I have a prompt stored in the langfuse. It generates the JSON and I have the format of the JSON as examples in the prompt. And it has a couple of variables too. So the variables are enclosed in {{}} and json is {"key": "value"} I use decorators (@observe) and .get_langchain_prompt() to convert the prompt to langfuse format. Now the problem is that when the prompt is converted to langfuse format, the variables get converted to {} but the json remains as is. So the JSON key is also considered as a variable. Any idea?
3 Replies
Marc
Marc4mo ago
What kind of issue is caused by this? The json should remain unchanged (desired behavior) when transforming Langfuse prompt variables ({{}}) into langchain prompt variables ({}) Justs saw your followup. Great that you figured this out. Feel free to reach out via the chat widget in the docs if you have other questions
Rolex
Rolex4mo ago
Yeah, the issue was when the prompt contained JSON. ex prompt in langfuse:
You are an expert in generating JSON for the given input

Example:
user: `I have 2 employees named Marc and Max who are the founders of Langfuse`
assistant: {"company": "Langfuse", "founders": ["Marc", "Max"]}

user: {{userInput}}
You are an expert in generating JSON for the given input

Example:
user: `I have 2 employees named Marc and Max who are the founders of Langfuse`
assistant: {"company": "Langfuse", "founders": ["Marc", "Max"]}

user: {{userInput}}
When I use .get_langchain_prompt() the variable is converted to langchain format. i,e {userInput} but the JSON remains as is. So the langchain considers "company" as a variable too. This is only when we use the new feature .get_langchain_prompt(). we can use old way, template format jinja2 In langchain the text prompt should be
You are an expert in generating JSON for the given input

Example:
user: `I have 2 employees named Marc and Max who are the founders of Langfuse`
assistant: {{"company": "Langfuse", "founders": ["Marc", "Max"]}}

user: {userInput}
You are an expert in generating JSON for the given input

Example:
user: `I have 2 employees named Marc and Max who are the founders of Langfuse`
assistant: {{"company": "Langfuse", "founders": ["Marc", "Max"]}}

user: {userInput}
Where a double mustache is used as escaping character
Marc
Marc4mo ago
Got it. Thanks!