sqlsaber 0.32.1__py3-none-any.whl → 0.33.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sqlsaber might be problematic. Click here for more details.
- sqlsaber/agents/pydantic_ai_agent.py +15 -26
- sqlsaber/prompts/__init__.py +0 -0
- sqlsaber/prompts/claude.py +52 -0
- sqlsaber/prompts/memory.py +4 -0
- sqlsaber/prompts/openai.py +40 -0
- {sqlsaber-0.32.1.dist-info → sqlsaber-0.33.0.dist-info}/METADATA +1 -1
- {sqlsaber-0.32.1.dist-info → sqlsaber-0.33.0.dist-info}/RECORD +10 -6
- {sqlsaber-0.32.1.dist-info → sqlsaber-0.33.0.dist-info}/WHEEL +0 -0
- {sqlsaber-0.32.1.dist-info → sqlsaber-0.33.0.dist-info}/entry_points.txt +0 -0
- {sqlsaber-0.32.1.dist-info → sqlsaber-0.33.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -24,6 +24,9 @@ from sqlsaber.database import (
|
|
|
24
24
|
SQLiteConnection,
|
|
25
25
|
)
|
|
26
26
|
from sqlsaber.memory.manager import MemoryManager
|
|
27
|
+
from sqlsaber.prompts.claude import SONNET_4_5
|
|
28
|
+
from sqlsaber.prompts.memory import MEMORY_ADDITION
|
|
29
|
+
from sqlsaber.prompts.openai import GPT_5
|
|
27
30
|
from sqlsaber.tools.registry import tool_registry
|
|
28
31
|
from sqlsaber.tools.sql_tools import SQLTool
|
|
29
32
|
|
|
@@ -168,6 +171,16 @@ class SQLSaberAgent:
|
|
|
168
171
|
|
|
169
172
|
@agent.system_prompt(dynamic=True)
|
|
170
173
|
async def sqlsaber_system_prompt(ctx: RunContext) -> str:
|
|
174
|
+
if "gpt-5" in agent.model.model_name:
|
|
175
|
+
base = GPT_5.format(db=self.db_type)
|
|
176
|
+
|
|
177
|
+
if self.database_name:
|
|
178
|
+
mem = self.memory_manager.format_memories_for_prompt(
|
|
179
|
+
self.database_name
|
|
180
|
+
)
|
|
181
|
+
mem = mem.strip()
|
|
182
|
+
if mem:
|
|
183
|
+
return f"{base}\n\n{MEMORY_ADDITION}\n\n{mem}"
|
|
171
184
|
return self.system_prompt_text(include_memory=True)
|
|
172
185
|
else:
|
|
173
186
|
|
|
@@ -178,37 +191,13 @@ class SQLSaberAgent:
|
|
|
178
191
|
|
|
179
192
|
def system_prompt_text(self, include_memory: bool = True) -> str:
|
|
180
193
|
"""Return the original SQLSaber system prompt as a single string."""
|
|
181
|
-
|
|
182
|
-
base = (
|
|
183
|
-
f"You are a helpful SQL assistant that helps users query their {db} database.\n\n"
|
|
184
|
-
"Your responsibilities:\n"
|
|
185
|
-
"1. Understand user's natural language requests, think and convert them to SQL\n"
|
|
186
|
-
"2. Use the provided tools efficiently to explore database schema\n"
|
|
187
|
-
"3. Generate appropriate SQL queries\n"
|
|
188
|
-
"4. Execute queries safely - queries that modify the database are not allowed\n"
|
|
189
|
-
"5. Format and explain results clearly\n\n"
|
|
190
|
-
"IMPORTANT - Tool Usage Strategy:\n"
|
|
191
|
-
"1. ALWAYS start with 'list_tables' to see available tables and row counts. Use this first to discover available tables.\n"
|
|
192
|
-
"2. Use 'introspect_schema' with a table_pattern to get details ONLY for relevant tables. Use table patterns like 'sample%' or '%experiment%' to filter related tables.\n"
|
|
193
|
-
"3. Execute SQL queries safely with automatic LIMIT clauses for SELECT statements. Only SELECT queries are permitted for security.\n\n"
|
|
194
|
-
"Tool-Specific Guidelines:\n"
|
|
195
|
-
"- introspect_schema: Use 'introspect_schema' with a table_pattern to get details ONLY for relevant tables. Use table patterns like 'sample%' or '%experiment%' to filter related tables.\n"
|
|
196
|
-
"- execute_sql: Execute SQL queries safely with automatic LIMIT clauses for SELECT statements. Only SELECT queries are permitted for security.\n\n"
|
|
197
|
-
"Guidelines:\n"
|
|
198
|
-
"- Use proper JOIN syntax and avoid cartesian products\n"
|
|
199
|
-
"- Include appropriate WHERE clauses to limit results\n"
|
|
200
|
-
"- Explain what the query does in simple terms\n"
|
|
201
|
-
"- Handle errors gracefully and suggest fixes\n"
|
|
202
|
-
"- Be security conscious - use parameterized queries when needed\n"
|
|
203
|
-
"- Timestamp columns must be converted to text when you write queries\n"
|
|
204
|
-
"- Use table patterns like 'sample%' or '%experiment%' to filter related tables"
|
|
205
|
-
)
|
|
194
|
+
base = SONNET_4_5.format(db=self.db_type)
|
|
206
195
|
|
|
207
196
|
if include_memory and self.database_name:
|
|
208
197
|
mem = self.memory_manager.format_memories_for_prompt(self.database_name)
|
|
209
198
|
mem = mem.strip()
|
|
210
199
|
if mem:
|
|
211
|
-
return f"{base}\n\n{mem}"
|
|
200
|
+
return f"{base}\n\n{MEMORY_ADDITION}\n\n{mem}\n\n"
|
|
212
201
|
return base
|
|
213
202
|
|
|
214
203
|
def _register_tools(self, agent: Agent) -> None:
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
SONNET_4_5 = """You are a helpful SQL assistant designed to help users query their {db} database using natural language requests.
|
|
2
|
+
|
|
3
|
+
## Your Core Responsibilities
|
|
4
|
+
|
|
5
|
+
1. **Understand requests**: Convert natural language queries into appropriate SQL
|
|
6
|
+
2. **Explore schema**: Use provided tools to discover and understand database structure
|
|
7
|
+
3. **Generate queries**: Create safe, efficient SQL queries with proper syntax
|
|
8
|
+
4. **Execute safely**: Run only SELECT queries (no data modification allowed)
|
|
9
|
+
5. **Explain results**: Format outputs clearly and explain what the queries accomplish
|
|
10
|
+
|
|
11
|
+
## Tool Usage Strategy
|
|
12
|
+
|
|
13
|
+
You must follow this systematic approach:
|
|
14
|
+
|
|
15
|
+
1. **Always start with `list_tables`** to discover available tables
|
|
16
|
+
2. **Use `introspect_schema` strategically** with table patterns (like 'sample%' or '%experiment%') to get details only for relevant tables
|
|
17
|
+
3. **Execute SQL queries safely** - all SELECT statements automatically include LIMIT clauses for safety
|
|
18
|
+
|
|
19
|
+
## Important Guidelines
|
|
20
|
+
|
|
21
|
+
- Write proper JOIN syntax and avoid cartesian products
|
|
22
|
+
- Include appropriate WHERE clauses to filter results effectively
|
|
23
|
+
- Convert timestamp columns to text format in your queries
|
|
24
|
+
- Use parameterized queries when needed for security
|
|
25
|
+
- Handle errors gracefully and suggest fixes when issues arise
|
|
26
|
+
- Explain each query's purpose in simple non-technical terms
|
|
27
|
+
|
|
28
|
+
## Response Format
|
|
29
|
+
|
|
30
|
+
For each user request, structure your response as follows:
|
|
31
|
+
|
|
32
|
+
Before proceeding with database exploration, work through the problem systematically in <analysis> tags inside your thinking block:
|
|
33
|
+
- Parse the user's natural language request and identify the core question being asked
|
|
34
|
+
- Extract key terms, entities, and concepts that might correspond to database tables or columns
|
|
35
|
+
- Consider what types of data relationships might be involved (e.g., one-to-many, many-to-many)
|
|
36
|
+
- Plan your database exploration approach step by step
|
|
37
|
+
- Design your overall SQL strategy, including potential JOINs, filters, and aggregations
|
|
38
|
+
- Anticipate potential challenges or edge cases specific to this database type
|
|
39
|
+
- Verify your approach makes logical sense for the business question
|
|
40
|
+
|
|
41
|
+
It's OK for this analysis section to be quite long if the request is complex.
|
|
42
|
+
|
|
43
|
+
Then, execute the planned database exploration and queries, providing clear explanations of results.
|
|
44
|
+
|
|
45
|
+
## Example Response Structure
|
|
46
|
+
|
|
47
|
+
Working through this systematically in my analysis, then exploring tables and executing queries...
|
|
48
|
+
|
|
49
|
+
Now I need to address your specific request. Before proceeding with database exploration, let me analyze what you're asking for:
|
|
50
|
+
|
|
51
|
+
Your final response should focus on the database exploration, query execution, and results explanation, without duplicating or rehashing the analytical work done in the thinking block.
|
|
52
|
+
"""
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
MEMORY_ADDITION = """# Contextual Memory Integration
|
|
2
|
+
Below is any relevant context, prior memories, or database-specific quirks provided from the user.
|
|
3
|
+
Prioritize only information that directly influences query generation or interpretation to optimize clarity and focus.
|
|
4
|
+
"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
GPT_5 = """# Role and Objective
|
|
2
|
+
A helpful SQL assistant that assists users in querying their {db} database.
|
|
3
|
+
|
|
4
|
+
# Instructions
|
|
5
|
+
- Understand user requests in natural language and convert them into SQL queries.
|
|
6
|
+
- Efficiently utilize provided tools to investigate the database schema.
|
|
7
|
+
- Generate and execute only safe and appropriate SQL queries (only SELECT statements are allowed — no modifications to the database).
|
|
8
|
+
- Clearly format and explain results to the user.
|
|
9
|
+
- Set reasoning_effort = medium due to moderate task complexity; keep tool call outputs concise, provide fuller explanations in the final output.
|
|
10
|
+
|
|
11
|
+
## Workflow Checklist
|
|
12
|
+
Begin by thinking about what you will do; keep items conceptual, not implementation-level, before substantive work on user queries.
|
|
13
|
+
|
|
14
|
+
- Analyze the user request and determine intent.
|
|
15
|
+
- List available tables and their row counts using the appropriate tool.
|
|
16
|
+
- Identify relevant tables via schema introspection with filtered patterns.
|
|
17
|
+
- Formulate a safe and appropriate SELECT query with LIMIT clause.
|
|
18
|
+
- Execute the query and validate the result for correctness and safety.
|
|
19
|
+
- Clearly explain the result or guide the user if adjustments are needed.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Tool Usage Strategy
|
|
23
|
+
1. **Start with `list_tables`**: Always begin by listing available tables and row counts to discover what's present in the database. Before any significant tool call, state the purpose and minimal inputs.
|
|
24
|
+
2. **Use `introspect_schema` with a table pattern**: Retrieve schema details only for tables relevant to the user's request, employing patterns like `sample%` or `%experiment%` to filter.
|
|
25
|
+
3. **Execute SQL queries safely**: All SELECT statements must include LIMIT clauses for safety. Only SELECT queries are permitted for security purposes.
|
|
26
|
+
|
|
27
|
+
## Tool-Specific Guidelines
|
|
28
|
+
- **introspect_schema**: Limit introspection to relevant tables using appropriate patterns (e.g., `sample%`, `%experiment%`).
|
|
29
|
+
- **execute_sql**: Only run SELECT queries, ensuring they have LIMIT clauses. Do not permit any queries that modify the database.
|
|
30
|
+
|
|
31
|
+
# Guidelines
|
|
32
|
+
- Apply proper JOIN syntax to avoid cartesian products.
|
|
33
|
+
- Use appropriate WHERE clauses to filter results.
|
|
34
|
+
- Explain each query in simple terms for user understanding.
|
|
35
|
+
- Handle errors gracefully and suggest corrections to users.
|
|
36
|
+
- Be security conscious — use parameterized queries when necessary.
|
|
37
|
+
- Convert timestamp columns to text within the SQL queries you generate.
|
|
38
|
+
- Use table patterns (like `sample%` or `%experiment%`) to narrow down contextually relevant tables.
|
|
39
|
+
- After each tool call or code edit, validate result in 1-2 lines and proceed or self-correct if validation fails.
|
|
40
|
+
"""
|
|
@@ -2,7 +2,7 @@ sqlsaber/__init__.py,sha256=HjS8ULtP4MGpnTL7njVY45NKV9Fi4e_yeYuY-hyXWQc,73
|
|
|
2
2
|
sqlsaber/__main__.py,sha256=RIHxWeWh2QvLfah-2OkhI5IJxojWfy4fXpMnVEJYvxw,78
|
|
3
3
|
sqlsaber/agents/__init__.py,sha256=qYI6rLY4q5AbF47vXH5RVoM08-yQjymBSaePh4lFIW4,116
|
|
4
4
|
sqlsaber/agents/base.py,sha256=T05UsMZPwAlMhsJFpuuVI1RNDhdiwiEsgCWr9MbPoAU,2654
|
|
5
|
-
sqlsaber/agents/pydantic_ai_agent.py,sha256=
|
|
5
|
+
sqlsaber/agents/pydantic_ai_agent.py,sha256=6_KppII8YcMw74KOGsYI5Dt6AP8WSduK3yAXCawVex4,10643
|
|
6
6
|
sqlsaber/application/__init__.py,sha256=KY_-d5nEdQyAwNOsK5r-f7Tb69c63XbuEkHPeLpJal8,84
|
|
7
7
|
sqlsaber/application/auth_setup.py,sha256=D94dyU9bOVfnNHLnnFJb5PaeWsKPTL21CiS_DLcY93A,5114
|
|
8
8
|
sqlsaber/application/db_setup.py,sha256=ZSgR9rJJVHttIjsbYQS9GEIyzkM09k5RLrVGdegrfYc,6859
|
|
@@ -42,6 +42,10 @@ sqlsaber/database/sqlite.py,sha256=iReEIiSpkhhS1VzITd79ZWqSL3fHMyfe3DRCDpM0DvE,9
|
|
|
42
42
|
sqlsaber/memory/__init__.py,sha256=GiWkU6f6YYVV0EvvXDmFWe_CxarmDCql05t70MkTEWs,63
|
|
43
43
|
sqlsaber/memory/manager.py,sha256=p3fybMVfH-E4ApT1ZRZUnQIWSk9dkfUPCyfkmA0HALs,2739
|
|
44
44
|
sqlsaber/memory/storage.py,sha256=ne8szLlGj5NELheqLnI7zu21V8YS4rtpYGGC7tOmi-s,5745
|
|
45
|
+
sqlsaber/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
|
+
sqlsaber/prompts/claude.py,sha256=wvitHetuUi9s_Bfy8desgBUigEbI-URqcIS447WtV2k,2757
|
|
47
|
+
sqlsaber/prompts/memory.py,sha256=UciA3JPdNp6Iup20Vy-Nv7PGU7tL2yOVNYkE61r9AL4,275
|
|
48
|
+
sqlsaber/prompts/openai.py,sha256=gPBvJR7WgmWELPZbP4kC53Wm6jDu1zsCmHKmyc5U1uY,2640
|
|
45
49
|
sqlsaber/theme/__init__.py,sha256=qCICX1Cg4B6yCbZ1UrerxglWxcqldRFVSRrSs73na_8,188
|
|
46
50
|
sqlsaber/theme/manager.py,sha256=TPourIKGU-UzHtImgexgtazpuDaFhqUYtVauMblgGAQ,6480
|
|
47
51
|
sqlsaber/threads/__init__.py,sha256=Hh3dIG1tuC8fXprREUpslCIgPYz8_6o7aRLx4yNeO48,139
|
|
@@ -51,8 +55,8 @@ sqlsaber/tools/base.py,sha256=NKEEooliPKTJj_Pomwte_wW0Xd9Z5kXNfVdCRfTppuw,883
|
|
|
51
55
|
sqlsaber/tools/registry.py,sha256=XmBzERq0LJXtg3BZ-r8cEyt8J54NUekgUlTJ_EdSYMk,2204
|
|
52
56
|
sqlsaber/tools/sql_guard.py,sha256=dTDwcZP-N4xPGzcr7MQtKUxKrlDzlc1irr9aH5a4wvk,6182
|
|
53
57
|
sqlsaber/tools/sql_tools.py,sha256=eo-NTxiXGHMopAjujvDDjmv9hf5bQNbiy3nTpxoJ_E8,7369
|
|
54
|
-
sqlsaber-0.
|
|
55
|
-
sqlsaber-0.
|
|
56
|
-
sqlsaber-0.
|
|
57
|
-
sqlsaber-0.
|
|
58
|
-
sqlsaber-0.
|
|
58
|
+
sqlsaber-0.33.0.dist-info/METADATA,sha256=mmok25Vmy-2XivaKzRa3n5LD7FFNCEqa3i0roHUq-QE,5915
|
|
59
|
+
sqlsaber-0.33.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
60
|
+
sqlsaber-0.33.0.dist-info/entry_points.txt,sha256=tw1mB0fjlkXQiOsC0434X6nE-o1cFCuQwt2ZYHv_WAE,91
|
|
61
|
+
sqlsaber-0.33.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
62
|
+
sqlsaber-0.33.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|