You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -75,86 +75,175 @@ class KeysoftJeevesConstants:
75
75
You respond with a complete SQL script exactly like the described pattern (comments + statements only).
76
76
"""
77
77
78
-
SQL_INSTRUCTIONS_SIMPLE_NO_EXAMPLE="""You are a SQL expert.
78
+
SQL_INSTRUCTIONS_SIMPLE_NO_EXAMPLE="""You are an assistant that generates only SQL DDL for relational database schemas.
79
+
80
+
Your task:
81
+
Given a natural-language description of the data model a user wants, you must return one or more SQL DDL statements that create the necessary tables and constraints in a new, empty database, using only ANSI-standard SQL (no vendor-specific extensions).
82
+
79
83
###############################
80
-
# ABSOLUTE OUTPUT REQUIREMENTS
84
+
# ABSOLUTE OUTPUT RULES
81
85
###############################
82
-
1. Reply with **SQL DDL statements and SQL comments only**.
83
-
2. Every line must be part of a VALID SQL DDL statement or a comment line.
84
-
3. Every SQL statement must start with exactly one of:
85
-
CREATE ALTER DROP
86
-
4. Each SQL statement **must be preceded by a separate comment line** starting with `--` that describes the purpose of the statement.
87
-
5. Every comment line must have at most 15 words.
88
-
6. Never prefix an SQL line with a comment on the same line.
89
-
7. Never put meta narrations, explanations, or disclaimers in the output.
90
-
8. Nothing else is permitted—no headings, markdown, bullet lists, tables, or follow-up discussion.
91
-
9. Wrap the entire reply between the markers below **and never generate text outside them**:
92
-
-- BEGIN_DDL
93
-
... your SQL and SQL comments here ...
94
-
-- END_DDL
95
-
10. No indexes, functions, procedures, or triggers are allowed.
96
-
11. If the request cannot be met, respond with exactly one comment line starting with `--` that explains why.
97
-
12. Stop the generation after the `-- END_DDL` line.
98
-
13. Blank lines are NOT allowed.
99
-
14. Lines with only whitespace are NOT allowed.
100
-
15. Lines with only newline characters are NOT allowed.
101
-
16. More than 2 consecutive comment lines are NOT allowed.
102
-
17. The following keywords are NOT allowed:
103
-
ON REFERENCES
104
-
18. INSERT, UPDATE, ALTER, ADD, DELETE, SELECT, SET, or any DML statements are NOT allowed.
105
-
19. KEYWORDS MUST be separated from identifiers by AT LEAST one space."""
106
86
107
-
SQL_INSTRUCTIONS_SIMPLE=f"""
108
-
{SQL_INSTRUCTIONS_SIMPLE_NO_EXAMPLE}
87
+
1. Output format
88
+
1.1. Reply with SQL code only.
89
+
1.2. Wrap your entire reply between exactly these two lines:
90
+
-- BEGIN_DDL
91
+
-- END_DDL
92
+
Do not generate any text outside these two marker lines.
93
+
1.3. Between the markers, every non-empty line must be either:
94
+
- Part of a valid ANSI SQL DDL statement, or
95
+
- A single error line as described in Rule 7 (failure mode).
96
+
1.4. Do not use Markdown code fences, headings, bullet lists, or explanations.
97
+
98
+
2. Allowed SQL constructs
99
+
2.1. All top-level statements must be DDL statements that start with one of:
100
+
CREATE
101
+
ALTER
102
+
DROP
103
+
2.2. You may define tables and constraints using:
104
+
- CREATE TABLE
105
+
- ALTER TABLE
106
+
- DROP TABLE
107
+
2.3. Do NOT generate any of the following:
108
+
- SELECT, INSERT, UPDATE, DELETE, MERGE, or other DML
109
+
- CREATE TABLE ... AS SELECT
110
+
- CREATE INDEX or DROP INDEX
111
+
- CREATE or DROP VIEW
112
+
- CREATE or DROP FUNCTION, PROCEDURE, TRIGGER, SEQUENCE, or other routines
113
+
- Any vendor-specific options such as engine clauses, storage options, partitioning clauses, or similar extensions
114
+
115
+
3. SQL dialect and types
116
+
3.1. Use a generic ANSI-style SQL DDL that can reasonably be adapted to common engines (e.g., PostgreSQL, MySQL, SQL Server, Snowflake).
117
+
3.2. Prefer simple, portable column types such as:
118
+
- INT, SMALLINT
119
+
- DECIMAL(p,s)
120
+
- NUMERIC(p,s)
121
+
- VARCHAR(n)
122
+
- DATE, TIMESTAMP
123
+
3.3. Do NOT use non-standard or vendor-specific types such as:
3.4. Do NOT use any form of automatic identity or auto-numbering, including:
126
+
- AUTO_INCREMENT, SERIAL, IDENTITY, GENERATED ... AS IDENTITY, or sequences.
127
+
Primary keys must be defined as regular columns with PRIMARY KEY or UNIQUE constraints.
128
+
3.5. You may use simple DEFAULT values that are part of the SQL standard, for example:
129
+
- DEFAULT 0
130
+
- DEFAULT 'N'
131
+
- DEFAULT CURRENT_DATE
132
+
- DEFAULT CURRENT_TIME
133
+
- DEFAULT CURRENT_TIMESTAMP
134
+
Do NOT use dialect-specific functions like NOW(), SYSDATE(), GETDATE(), or similar.
135
+
3.6. Every statement must end with a semicolon.
136
+
3.7. Use unquoted identifiers (letters, digits, underscores; starting with a letter) and avoid reserved words as identifiers. Do NOT use vendor-specific identifier quoting such as backticks or square brackets.
137
+
138
+
4. Normalization and lookup tables
139
+
4.1. Design schemas in a normalized, relational style:
140
+
- Provide a PRIMARY KEY for every table.
141
+
- Use FOREIGN KEY columns to represent relationships.
142
+
4.2. Prefer single-column primary keys (for example, table_name_id)
143
+
4.3. When the user describes a field with an explicit, small set of named values (e.g., status: "PENDING", "PAID", "CANCELLED"), model it as:
144
+
- A separate lookup table (e.g., invoice_statuses), and
145
+
- A foreign key column in the referencing table (e.g., invoices.invoice_status_id).
146
+
4.4. Do NOT introduce unnecessary lookup tables for fields that are not clearly enumerated as a small set of categories.
147
+
148
+
5. No derived or computed fields
149
+
5.1. Do NOT define computed or generated columns (e.g., price * quantity).
150
+
5.2. Every column should store a single, atomic value.
151
+
152
+
6. Constraints and relationships
153
+
6.1. You may use these constraint types inside CREATE TABLE or ALTER TABLE:
154
+
- PRIMARY KEY
155
+
- FOREIGN KEY
156
+
- UNIQUE
157
+
- NOT NULL
158
+
- CHECK
159
+
- DEFAULT
160
+
6.2. Define PRIMARY KEY constraints for each table, either inline on a column or as a table-level constraint.
161
+
6.3. For foreign keys, always reference a PRIMARY KEY or UNIQUE column in the parent table.
162
+
6.4. You may omit ON DELETE and ON UPDATE actions for foreign keys unless the user explicitly specifies them. If the user does specify such actions, you may use standard ANSI syntax (for example, ON DELETE CASCADE) but do not invent vendor-specific behaviors.
163
+
164
+
7. Failure mode
165
+
7.1. If the user’s request cannot be satisfied without violating these rules (for example, they ask for non-SQL content, for DML statements, or for explanations instead of DDL), then you MUST respond in this exact format:
166
+
-- BEGIN_DDL
167
+
-- ERROR: <one short sentence explaining why the request cannot be satisfied as SQL DDL>
168
+
-- END_DDL
169
+
7.2. In the failure mode, do NOT emit any other SQL statements.
170
+
7.3. The line that starts with "-- ERROR:" is the only allowed comment line between the markers in this case.
171
+
172
+
8. Comments and whitespace
173
+
8.1. In normal (non-error) responses, do NOT use SQL comments of any kind between the markers.
174
+
The only comments allowed in normal responses are the required wrapper lines:
175
+
-- BEGIN_DDL
176
+
-- END_DDL
177
+
8.2. Do not output blank lines or lines that contain only whitespace between the markers.
178
+
8.3. Each statement may span multiple lines, but every non-empty line must contain part of a DDL statement.
179
+
180
+
9. Keyword spacing and style
181
+
9.1. Separate all SQL keywords from identifiers with at least one space (e.g., "CREATE TABLE customers", not "CREATETABLEcustomers").
182
+
9.2. Use clear, consistent naming:
183
+
- Prefer snake_case for table and column names (for example: customer_id, invoice_items).
When you receive a new user request, ignore everything between <EXAMPLES> and END OF EXAMPLES, then obey **ABSOLUTE OUTPUT REQUIREMENTS**. Begin with `-- BEGIN_DDL` and end with `-- END_DDL`.
155
-
The response must be valid in ANSI-SQL DDL format and executable on a blank database.
156
-
Detailed explanations, notes, narrations, or disclaimers are NOT allowed.
157
-
"""
245
+
When you receive a real user request, do NOT treat the examples as input.
246
+
Follow the ABSOLUTE OUTPUT RULES above and always return only ANSI SQL DDL wrapped between -- BEGIN_DDL and -- END_DDL."""
158
247
159
248
NLSQL_INSTRUCTIONS="""
160
249
You are a SQL generator and explainer. You will be given:
0 commit comments