@@ -18,18 +18,29 @@ def get_analysis( # pylint: disable=too-many-arguments, too-many-positional-arg
1818 db_description : str ,
1919 instructions : str | None = None ,
2020 memory_context : str | None = None ,
21+ database_type : str | None = None ,
2122 ) -> dict :
2223 """Get analysis of user query against database schema."""
2324 formatted_schema = self ._format_schema (combined_tables )
25+ # Add system message with database type if not already present
26+ if not self .messages or self .messages [0 ].get ("role" ) != "system" :
27+ self .messages .insert (0 , {
28+ "role" : "system" ,
29+ "content" : (
30+ f"You are a SQL expert. TARGET DATABASE: "
31+ f"{ database_type .upper () if database_type else 'UNKNOWN' } "
32+ )
33+ })
34+
2435 prompt = self ._build_prompt (
25- user_query , formatted_schema , db_description , instructions , memory_context
36+ user_query , formatted_schema , db_description ,
37+ instructions , memory_context , database_type
2638 )
2739 self .messages .append ({"role" : "user" , "content" : prompt })
2840 completion_result = completion (
2941 model = Config .COMPLETION_MODEL ,
3042 messages = self .messages ,
3143 temperature = 0 ,
32- top_p = 1 ,
3344 )
3445
3546 response = completion_result .choices [0 ].message .content
@@ -158,7 +169,8 @@ def _format_foreign_keys(self, foreign_keys: dict) -> str:
158169
159170 def _build_prompt ( # pylint: disable=too-many-arguments, too-many-positional-arguments
160171 self , user_input : str , formatted_schema : str ,
161- db_description : str , instructions , memory_context : str | None = None
172+ db_description : str , instructions , memory_context : str | None = None ,
173+ database_type : str | None = None ,
162174 ) -> str :
163175 """
164176 Build the prompt for Claude to analyze the query.
@@ -169,6 +181,7 @@ def _build_prompt( # pylint: disable=too-many-arguments, too-many-positional-a
169181 db_description: Description of the database
170182 instructions: Custom instructions for the query
171183 memory_context: User and database memory context from previous interactions
184+ database_type: Target database type (sqlite, postgresql, mysql, etc.)
172185
173186 Returns:
174187 The formatted prompt for Claude
@@ -196,6 +209,8 @@ def _build_prompt( # pylint: disable=too-many-arguments, too-many-positional-a
196209 prompt = f"""
197210 You must strictly follow the instructions below. Deviations will result in a penalty to your confidence score.
198211
212+ TARGET DATABASE: { database_type .upper () if database_type else 'UNKNOWN' }
213+
199214 MANDATORY RULES:
200215 - Always explain if you cannot fully follow the instructions.
201216 - Always reduce the confidence score if instructions cannot be fully applied.
0 commit comments