Skip to content

fix: include conversation history in SQL prompt template#1875

Open
Br1an67 wants to merge 1 commit into
sinaptik-ai:mainfrom
Br1an67:fix/sql-prompt-history-template
Open

fix: include conversation history in SQL prompt template#1875
Br1an67 wants to merge 1 commit into
sinaptik-ai:mainfrom
Br1an67:fix/sql-prompt-history-template

Conversation

@Br1an67

@Br1an67 Br1an67 commented Mar 1, 2026

Copy link
Copy Markdown

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 CONVERSATION block to the SQL template, gated behind context.memory.count() > 1, mirroring the existing behavior in generate_python_code.tmpl.

Files changed:

  • pandasai/core/prompts/templates/generate_python_code_with_sql.tmpl — added history rendering block
  • tests/unit_tests/core/prompts/test_generate_python_code_with_sql_prompt.py — added tests for history rendering

Important

Adds conversation history to SQL prompt template for multi-turn queries, with tests to verify functionality.

  • Behavior:
    • Added PREVIOUS CONVERSATION block to generate_python_code_with_sql.tmpl, visible if context.memory.count() > 1.
    • Ensures SQL prompt template includes conversation history for multi-turn queries.
  • Tests:
    • Added test_template_includes_previous_conversation to verify history inclusion in test_generate_python_code_with_sql_prompt.py.
    • Added test_template_no_previous_conversation_for_single_message to ensure single-message memory does not show history.

This description was created by Ellipsis for 3ace600. You can customize this summary. It will automatically update as commits are pushed.

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

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 3ace600 in 11 seconds. Click for details.
  • Reviewed 82 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft 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 Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

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.

Agent ignores Conversation History: Missing placeholders in generate_python_code_with_sql.tmpl

1 participant