[X] I added a very descriptive title to this issue.
[X] I searched the LangChain documentation with the integrated search.
[X] I used the GitHub search to find a similar question and didn't find it.
[X] I am sure that this is a bug in LangChain rather than my code.
[X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import json
from langchain_core.output_parsers import JsonOutputParser
from langchain_core.runnables import RunnableLambda
def fake_llm1(inputs):
return json.dumps(str({
"response": "The user question does not align with the structure or data within our database tables. The tables are relational in terms and follow the naming convention of 'galvatron\' or'mac_\', however the user question appears unrelated to the type of data and structure of the tables."}))
def fake_llm2(inputs):
return str({
"response": "The user question does not align with the structure or data within our database tables. The tables are relational in terms and follow the naming convention of 'galvatron\' or'mac_\', however the user question appears unrelated to the type of data and structure of the tables."})
chain1 = RunnableLambda(fake_llm1) | JsonOutputParser()
chain2 = RunnableLambda(fake_llm2) | JsonOutputParser()
# execute
print(chain1.invoke(""))
# throw exception
print(chain2.invoke(""))
File "langchain_core\output_parsers\json.py", line 87, in parse_result
raise OutputParserException(msg, llm_output=text) from e
langchaincore.exceptions.OutputParserException: Invalid json output: {'response': "The user question does not align with the structure or data within our database tables. The tables are relational in terms and follow the naming convention of 'galvatron' or'mac', however the user question appears unrelated to the type of data and structure of the tables."}
Description
I'm not entirely sure if it is a bug. I found it really strange that when string contains escape character we have such an issue. We can resolve the issue by dumping it to JSON first.
System Info
System Information
OS: Windows
OS Version: 10.0.19045
Python Version: 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
File "langchain_core\output_parsers\json.py", line 87, in parse_result raise OutputParserException(msg, llm_output=text) from e langchaincore.exceptions.OutputParserException: Invalid json output: {'response': "The user question does not align with the structure or data within our database tables. The tables are relational in terms and follow the naming convention of 'galvatron' or'mac', however the user question appears unrelated to the type of data and structure of the tables."}
Description
I'm not entirely sure if it is a bug. I found it really strange that when string contains escape character we have such an issue. We can resolve the issue by dumping it to JSON first.
System Info
System Information
Package Information