Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: SQLTableRetrieverQueryEngine => "sql" at the start of most SQL statements #13491

Open
nick-youngblut opened this issue May 14, 2024 · 1 comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@nick-youngblut
Copy link

Bug Description

SQLTableRetrieverQueryEngine is generating SQL statements with "sql" at the start. For example:

sql
SELECT room$raw.name$ AS room_name, freezer$raw.name$ AS freezer_name
FROM freezer$raw
JOIN room$raw ON freezer$raw.location_id$ = room$raw.id
WHERE freezer$raw.archived$ = false AND room$raw.archived$ = false
ORDER BY room$raw.name$;

This results in GPT-4o stating "It appears there was an error in the SQL query provided".

Version

0.10.36

Steps to Reproduce

Follow https://docs.llamaindex.ai/en/stable/examples/index_structs/struct_indices/SQLIndexDemo/, but place in a streamlit chat app.

Relevant Logs/Tracbacks

No response

@nick-youngblut nick-youngblut added bug Something isn't working triage Issue needs to be triaged/prioritized labels May 14, 2024
Copy link

dosubot bot commented May 14, 2024

It looks like the issue with the "sql" prefix in the SQL statements generated by SQLTableRetrieverQueryEngine might be related to the context_str_prefix parameter used in the initialization of the NLSQLRetriever. This parameter, if incorrectly set to include "sql", could lead to the observed behavior.

To address this, please check the configuration of the context_str_prefix in your setup to ensure it doesn't unintentionally include "sql". This parameter is meant to prefix the context string passed to the language model for SQL query generation and should be carefully configured to avoid such issues.

For a deeper dive, the configuration is found in the initialization of SQLTableRetrieverQueryEngine, specifically in the setup of the NLSQLRetriever. Here's a snippet for reference:

self._sql_retriever = NLSQLRetriever(
    sql_database,
    text_to_sql_prompt=text_to_sql_prompt,
    context_query_kwargs=context_query_kwargs,
    table_retriever=table_retriever,
    context_str_prefix=context_str_prefix,
    service_context=service_context,
    sql_only=sql_only,
)

Ensure that the context_str_prefix does not include "sql" unless it's intended for your specific use case. If adjusting this does not resolve the issue, further details about your configuration and the steps you're following would be helpful for a more targeted solution.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant