Skip to content

The agent engineering platform.

fix: agent json parser fails with text in suffix (#1734)

Merbin J Anselmfbc0c85b90a1
diff --git a/langchain/agents/conversational_chat/base.py b/langchain/agents/conversational_chat/base.py
index 94afc855b6..e3cc9494d5 100644
--- a/langchain/agents/conversational_chat/base.py
+++ b/langchain/agents/conversational_chat/base.py
@@ -39,6 +39,8 @@ class AgentOutputParser(BaseOutputParser):
cleaned_output = text.strip()
if "```json" in cleaned_output:
_, cleaned_output = cleaned_output.split("```json")
+ if "```" in cleaned_output:
+ cleaned_output, _ = cleaned_output.split("```")
if cleaned_output.startswith("```json"):
cleaned_output = cleaned_output[len("```json") :]
if cleaned_output.startswith("```"):