Find answers from the community

Updated last year

SQL Prompt

At a glance

The community member is asking how to specify which prompt template to use depending on the table with SQLTableRetrieverQueryEngine. They want to pass in few-shot prompts and format the answer in a certain way based on the table being queried.

Other community members suggest that the user can define the prompt and pass it into SQLTableRetrieverQueryEngine using the text_to_sql_prompt keyword, and make additions based on the table contents. They also recommend using the response_synthesis_prompt to format the response.

The community members discuss the ability to pass in multiple prompts, the handling of language-specific prompts, and the possibility of using the response_synthesis_prompt to format the response based on the table and query.

There is no explicitly marked answer, but the community members provide helpful suggestions and guidance to the original poster.

Useful resources
Is there a way to specific which prompt template to use depending on the table with SQLTableRetrieverQueryEngine ?
Depending on the table being queried, I would like to pass in few shot prompts and also tell it format the answer in a certain way.
https://docs.llamaindex.ai/en/stable/end_to_end_tutorials/structured_data/sql_guide.html#using-natural-language-sql-queries
W
c
7 comments
You can define the prompt and pass it into SQLTableRetrieverQueryEngine with text_to_sql_prompt keyword and make some additions like if the table contains certain things do this and if it contains other table then do this.


For response format use the response_synthesis_prompt

https://github.com/run-llama/llama_index/blob/31d132c56b1836603d48e02786cd29a74a28f527/llama_index/indices/struct_store/sql_query.py#L441
So what you're saying is I can only pass in 1 prompt and just do the if this table stuff in that 1 prompt.
I changed my text_to_sql prompt all into Japanese and told it to reply in Japanese but it still replied it in English. I'm guessing that's where the response_synthesis_prompt comes in.
Sorry, another question. If I have a query that asks about Table A, I can pass my few shot prompts in the text_to_sql_prompt and in the response_synthesis_prompt can I say If SQL generated from Table A and the query is about XXX, provide the response in markdown table format ?
Yes, that should work
Add a reply
Sign up and join the conversation on Discord