Skip to content

Commit 3bd3818

Browse files
authored
Fix: Enhance _parse_command to robustly handle whitespace and formatting (#131)
1 parent a5348b6 commit 3bd3818

File tree

1 file changed

+2
-1
lines changed
  • libs/langchain-mongodb/langchain_mongodb/agent_toolkit

1 file changed

+2
-1
lines changed

libs/langchain-mongodb/langchain_mongodb/agent_toolkit/database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import json
6+
import re
67
from datetime import date, datetime
78
from importlib.metadata import version
89
from typing import Any, Dict, Iterable, List, Optional, Union
@@ -207,7 +208,7 @@ def _elide_doc(self, doc: dict[str, Any]) -> None:
207208

208209
def _parse_command(self, command: str) -> Any:
209210
# Convert a JavaScript command to a python object.
210-
command = command.strip().replace("\n", "").replace(" ", "")
211+
command = re.sub(r"\s+", " ", command.strip())
211212
# Handle missing closing parens.
212213
if command.endswith("]"):
213214
command += ")"

0 commit comments

Comments
 (0)