Python, PyTest & SQL Foundations for AI QE Β· Day 3 Β· 20 min
SQL Golden Dataset Curation & Leakage
Python, PyTest & SQL Foundations for AI QE β Day 3
Validate golden-dataset schema constraints, SQLite3 foreign-key referential integrity, class-balance stratification, normalized duplicate prompt detection, and train/eval leakage checks.
π¦Sample Codebase & Working Solution (Day 3)Available Now
View on GitHubThe official reference codebase for Day 3 is hosted in the repository. Clone the repository and navigate to day-3-sql-data-curation/test_day3_sql_curation.py to run the working solution.
Git Clone β Working Solution
git clone https://github.com/777abhi/pytest-sql-ai-qe-roadmap.git
cd pytest-sql-ai-qe-roadmap/day-3-sql-data-curation/test_day3_sql_curation.pyπProduction Context & Enterprise Implementation
π‘ Why We Are Doing This: Duplicate prompts, skewed evaluation splits, and train/eval data leakage silently inflate benchmark pass rates and create false release confidence.
π’ Real-World Production Usecase: Automated SQL quality gates validating golden prompt catalogs and evaluation run history tables before model scoring begins.
βοΈ How Implemented in Production: EvalDatabase uses SQLite3 CHECK constraints, PRAGMA foreign_keys = ON, normalized SHA-256 prompt hashes, GROUP BY duplicate queries, and self-joins across train/eval splits.
Phase 1
Run SQLite3 Integrity, Stratification & Leakage Tests
Step 1.1: Execute Day 3 SQL Curation Suite
Terminal β Run Day 3
npm run test:day3Step 1.2: SQL Train/Eval Leakage Self-Join Query
aiqelab/sql_store.py
SELECT DISTINCT t.prompt_hash
FROM golden_prompts t
INNER JOIN golden_prompts e
ON t.prompt_hash = e.prompt_hash
WHERE t.split = 'train' AND e.split IN ('eval', 'holdout');Day 3 Key Learnings
- Enforced database-level CHECK constraints and PRAGMA foreign_keys = ON to block invalid splits and orphan eval logs.
- Verified stratified class balance across happy_path, edge_case, vulnerable_user, and foreseeable_misuse slices.
- Caught subtle case/whitespace-variant duplicates and train-to-eval prompt leakage using normalized SHA-256 hashes.
π§ Knowledge Check
Why should golden-dataset leakage checks hash whitespace- and case-normalized prompt text before joining train and eval splits in SQL?