[PR #4527] Fix: optimize SQL agent's system prompt to improve stability of tool invocation. #3884

Closed
opened 2026-02-20 17:49:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/4527

State: closed
Merged: No


Hi, I'm very pleased to see the SQL agent tutorial updated three days ago! In fact, over the past few weeks, I've been troubled by an issue with the previous implementation of the SQL agent (as also pointed out by others in the comments): specifically, the model would frequently invoke the model_get_schema tool but fail to generate an actual query afterward. Instead, it directly return results based purely on the sample data provided in the schema.

I believe the root cause of this issue was a lack of robustness in the system prompt. Specifically, it did not clearly instruct the model on the appropriate usage and order of tools, leading to confusion and incorrect outcomes.

Fortunately, the recent update utilizing the prebuilt agent significantly alleviates this issue. However, I found that my optimized prompt still provides noticeable improvements—particularly for less capable models or smaller-scale models. Thus, I've initiated this pull request to contribute my improvements.

Thank you very much for your consideration—I sincerely hope you find these adjustments valuable and decide to merge this pull request!
image
image

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/4527 **State:** closed **Merged:** No --- Hi, I'm very pleased to see the SQL agent tutorial updated three days ago! In fact, over the past few weeks, I've been troubled by an issue with the previous implementation of the SQL agent (as also pointed out by others in the comments): specifically, the model would frequently invoke the model_get_schema tool but fail to generate an actual query afterward. Instead, it directly return results based purely on the sample data provided in the schema. I believe the root cause of this issue was a lack of robustness in the system prompt. Specifically, it did not clearly instruct the model on the appropriate usage and order of tools, leading to confusion and incorrect outcomes. Fortunately, the recent update utilizing the prebuilt agent significantly alleviates this issue. However, I found that my optimized prompt still provides noticeable improvements—particularly for less capable models or smaller-scale models. Thus, I've initiated this pull request to contribute my improvements. Thank you very much for your consideration—I sincerely hope you find these adjustments valuable and decide to merge this pull request! <img width="787" alt="image" src="https://github.com/user-attachments/assets/d7dc5a8f-0baa-4584-ab08-0a6db5f9acd0" /> <img width="780" alt="image" src="https://github.com/user-attachments/assets/8fe29988-cc51-4ad1-b847-56182711ae17" />
yindo added the pull-request label 2026-02-20 17:49:19 -05:00
yindo closed this issue 2026-02-20 17:49:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3884