How to escape curly-braces "{}" in a customized prompt?
Hi. I am trying to generate a customized prompt where I need to escape the curly-braces. Whenever I use curly braces in my prompt, it is being taken as place holders.
So, can you please suggest how to escape the curly braces in the prompts?
They are f-strings; they can be escaped like this: {{not a placeholder}}
The solution is to use double curly braces, {{}}, as shown by @batmanscode.
I'd recommend using the Discord for quick questions as you'll receive a much quicker reply.
This issue can be closed.
Hey, thanks for the reply. Will try that @batmanscode @nosas
Hi, @tamil-acog! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, the issue you raised was about escaping curly braces in a customized prompt. It seems that @batmanscode suggested using double curly braces, {{}}, to escape them, and @nosas confirmed that this solution works. It's great to hear that the issue has been resolved!
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your contribution, and please don't hesitate to reach out if you have any further questions or concerns.
if outputting JSON into the the history the issues still happens
Thank you for your response, @not2technical! We appreciate your input. Based on your comment, it seems that the issue is still relevant. We will proceed to close the issue.
Maybe finding more ways to deal with JSON formatting in langchain is a good idea. I am trying to write my custom formatting instructions without using the pydantic parser's auto generated formatting prompt, however I am unable to add formatting instructions to the prompt because the prompt treats it as placeholders. Maybe I just haven't found the function for that yet.
My solution is to pass it as a string, then through lambda function. For instance, json_data is our json object and defined as a string:
json_data = """
{
... some information here ....
}
"""
I define my prompt template consists of json_data and question. In my pipe, I pass the input like this:
rag_chain = (
{"json_data": lambda x: json_data, "question": RunnablePassthrough()}
| rag_prompt
| llm
)
Hope it can help!
The solution is to use double curly braces,
{{}}, as shown by @batmanscode. I'd recommend using the Discord for quick questions as you'll receive a much quicker reply.This issue can be closed.
This method works If you are passing multiple objects , make sure each of the object is enclosed with {{}}