Skip to content

Commit efec545

Browse files
committed
Fix _id handling for LLM pipeline generation
1 parent 2864476 commit efec545

File tree

1 file changed

+5
-0
lines changed
  • libs/langchain-mongodb/langchain_mongodb/agent_toolkit

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,15 @@ def _handle_object_id(match: Any) -> str:
341341
raise ValueError("ObjectId must contain a value.")
342342
return f"ObjectId('{oid_str}')"
343343

344+
def _handle_id_key(match: Any) -> str:
345+
return f'"{match.group(1)}"'
346+
344347
patterns = [
345348
(r'ISODate\(\s*["\']([^"\']*)["\']\s*\)', _handle_iso_date),
346349
(r'new\s+Date\(\s*["\']([^"\']*)["\']\s*\)', _handle_new_date),
347350
(r'ObjectId\(\s*["\']([^"\']*)["\']\s*\)', _handle_object_id),
351+
(r'ObjectId\(\s*["\']([^"\']*)["\']\s*\)', _handle_object_id),
352+
(r'(?<!["\'])\b(_id)\b(?!["\'])', _handle_id_key),
348353
]
349354

350355
for pattern, replacer in patterns:

0 commit comments

Comments
 (0)