HomeRoadmapsPyTest & SQL AI QE Day 3
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.

⚑ Runtime: Python 3.10+ Β· PyTest Β· Built-in SQLite3πŸ—„οΈ Python & SQL AI QE Engineer
SQLite3Schema IntegrityForeign KeysStratificationLeakage Detection
πŸ“¦Sample Codebase & Working Solution (Day 3)Available Now
View on GitHub

The 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:day3
Step 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?