fix: include conversation history in SQL prompt template#1875
Open
Br1an67 wants to merge 1 commit into
Open
Conversation
The SQL code generation template was missing the previous conversation context that the Python template already includes. Multi-turn follow-up queries produced incorrect results because the LLM had no visibility into prior questions and answers. Add a PREVIOUS CONVERSATION block to generate_python_code_with_sql.tmpl that mirrors the existing behavior in generate_python_code.tmpl, gated behind a memory.count() > 1 check. Closes sinaptik-ai#1856
Contributor
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 3ace600 in 11 seconds. Click for details.
- Reviewed
82lines of code in2files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_zt06wYYlmoAHKtUN
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SQL code generation template (
generate_python_code_with_sql.tmpl) was missing the previous conversation history block that the Python template already includes. Multi-turn follow-up queries in SQL mode produced incorrect results because the LLM had no visibility into prior questions and answers.Changes
Added a
PREVIOUS CONVERSATIONblock to the SQL template, gated behindcontext.memory.count() > 1, mirroring the existing behavior ingenerate_python_code.tmpl.Files changed:
pandasai/core/prompts/templates/generate_python_code_with_sql.tmpl— added history rendering blocktests/unit_tests/core/prompts/test_generate_python_code_with_sql_prompt.py— added tests for history renderingImportant
Adds conversation history to SQL prompt template for multi-turn queries, with tests to verify functionality.
PREVIOUS CONVERSATIONblock togenerate_python_code_with_sql.tmpl, visible ifcontext.memory.count() > 1.test_template_includes_previous_conversationto verify history inclusion intest_generate_python_code_with_sql_prompt.py.test_template_no_previous_conversation_for_single_messageto ensure single-message memory does not show history.This description was created by
for 3ace600. You can customize this summary. It will automatically update as commits are pushed.