Closed rvmtz closed 2 months ago
@rvmtz Thank you for identifying the bug. Sounds like there's a bug. This code:
data = '{"nested":{"foo":"bar"}}'
prompt = Langchain::Prompt::PromptTemplate.new(template: '{data}', input_variables: ['data'])
prompt.format(data: data)
should produce:
=> "{\"nested\":{\"foo\":\"bar\"}}"
Feel free to open up a fix if you have any ideas on solving it.
@andreibondarev , sorry for the late reply. I just open a PR trying to address the issue. Let me know your thoughts: https://github.com/patterns-ai-core/langchainrb/pull/751. Have a great weekend!
Describe the bug When using
Langchain::Prompt::PromptTemplate
to inject a JSON document where the sequence of characters{{
or}}
happens, it turns them into a single bracket{
and}
.To Reproduce Steps to reproduce the behavior.
Expected behavior To inject the JSON accordingly.
Additional context
This behavior was introduced in commit https://github.com/patterns-ai-core/langchainrb/commit/63ed16509c866e04792930c8b677f2ed2a256379.
Should we enhance
PromptTemplate
to process JSON as-is, or add an extra option (besides double braces{{ }}
) to escape these sequences? I’m available to discuss and submit a PR if needed. Looking forward to your guidance!