Skip to content

PYTHON-5667: Update prompt.py - #162

Open
Putu Gede Pradana Adnyana (pradanaadn) wants to merge 2 commits into
langchain-ai:mainfrom
pradanaadn:patch-1
Open

Putu Gede Pradana Adnyana (pradanaadn) wants to merge 2 commits into
langchain-ai:mainfrom
pradanaadn:patch-1

Conversation

@pradanaadn

@pradanaadn Putu Gede Pradana Adnyana (pradanaadn) commented Jul 7, 2025 •

Copy link
Copy Markdown
  • Update the agent_toolkit prompt for the query checker to ensure it return pymongo syntax.

It keep return query in json:

================================= Tool Message =================================
Name: mongodb_query_checker

content='json\n{\n aggregate: "sales",\n pipeline: [\n { $unwind: "$items" },\n { $unwind: "$items.tags" },\n {\n $group: {\n _id: "$items.tags",\n totalSales: { $sum: { $multiply: ["$items.price", "$items.quantity"] } }\n }\n },\n { $sort: { totalSales: -1 } },\n { $limit: 5 }\n ]\n}\n\n\n### Explanation:\n1. Unwinding Tags: The tags field within items is likely an array, which requires an additional $unwind stage to flatten the array and properly group by individual tags.\n2. Identifiers and Operators Quoting: The identifiers and operators are quoted correctly in the original query, and there are no syntax errors related to quoting.\n3. JSON Validity: The query is valid JSON format as part of a MongoDB aggregation pipeline.\n\nThe main change is the addition of an extra $unwind stage for items.tags. This ensures the query groups by each individual tag rather than the array of tags.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 239, 'prompt_tokens': 178, 'total_tokens': 417, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_a288987b44', 'id': 'chatcmpl-BqWxt1ajfavqmGTBS06BLsuDhCM1D', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None} id='run--75a8df8b-cf4e-4e79-aba0-dcea8b9c8e69-0' usage_metadata={'input_tokens': 178, 'output_tokens': 239, 'total_tokens': 417, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I just have one comment



MONGODB_QUERY_CHECKER = """
MONGODB_QUERY_CHECKER = MONGODB_QUERY_CHECKER = """

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change unintentional?

@caseyclements Casey Clements (caseyclements) changed the title Update prompt.py PYTHON-5667: Update prompt.py Dec 4, 2025
@caseyclements

Copy link
Copy Markdown
Collaborator

Thanks Putu Gede Pradana Adnyana (@pradanaadn) for your contribution. I hope that you are still using langchain-mongodb! I have created JIRA ticket to pick up this work: PYTHON-5667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants