Conversation
This PR improves the SQL generation and execution flow by tightening instructions given to the LLM and reinforcing runtime query validation. The goal is to reduce unsafe outputs, make SQL generation more deterministic, and ensure only read-only queries are executed. What Changed Prompt hardening in prompt.py Clarified that schema context is the single source of truth. Enforced stricter output format: SQL only, no markdown, no comments, no extra text. Strengthened constraints to allow only SELECT queries and explicitly block DML/DDL operations. Added conservative behavior guidance for ambiguous questions. Execution guardrails in sqlquerys.py Kept SQL sanitization and validation as a second protection layer after prompt generation. Enforced non-empty query validation. Prevented multi-statement execution. Required SELECT-first queries. Blocked forbidden keywords like INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE, and REPLACE.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughTwo modules were enhanced: SQL query validation now includes stricter syntax checks, comment removal, and whitespace normalization while modifying transaction behavior, and prompt generation was expanded to accept a database type parameter with restructured instructions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This PR improves the SQL generation and execution flow by tightening instructions given to the LLM and reinforcing runtime query validation. The goal is to reduce unsafe outputs, make SQL generation more deterministic, and ensure only read-only queries are executed.
What Changed
Prompt hardening in prompt.py
Clarified that schema context is the single source of truth. Enforced stricter output format: SQL only, no markdown, no comments, no extra text. Strengthened constraints to allow only SELECT queries and explicitly block DML/DDL operations. Added conservative behavior guidance for ambiguous questions. Execution guardrails in sqlquerys.py
Kept SQL sanitization and validation as a second protection layer after prompt generation. Enforced non-empty query validation.
Prevented multi-statement execution.
Required SELECT-first queries.
Blocked forbidden keywords like INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE, and REPLACE.
Summary by CodeRabbit
Bug Fixes
New Features