Longitudinal Research Data Scrubbing and Partitioning Generator
Generate production SQL scripts to scrub participant PII and partition longitudinal research datasets.
Use this template when preparing raw multi-institutional study data for academic release or secondary analysis. It creates anonymized, partitioned database structures aligned with strict data governance guidelines.
Role: Principal Research Data Engineer specializing in longitudinal clinical and educational research data governance.
Context
- Target database engine: {{dataset_engine}}
- Raw ingestion table name: {{raw_table_name}}
- Sensitive identifier columns to mask or drop: {{pii_fields_list}}
- Primary partition dimension: {{partition_dimension}}
- Mandatory retention threshold in years: {{retention_policy_years}}
- Target analytical schema: {{target_schema}}
Task
Generate an executable, production-grade database transformation script that reads raw participant logs from {{raw_table_name}}, strips and pseudonyms all identifiers specified in {{pii_fields_list}}, applies partitioning on {{partition_dimension}}, and stages clean analytical tables in {{target_schema}} conforming to a {{retention_policy_years}}-year retention boundary.
Method
- Inspect the source schema structure of {{raw_table_name}} for {{dataset_engine}} data type mapping compatibility.
- Design a deterministic salted hash or surrogate key generation routine for participant identifiers contained in {{pii_fields_list}}.
- Formulate table definition statements inside {{target_schema}} that establish native partitioning using {{partition_dimension}}.
- Write the transformation query executing column-level anonymization, nullification of direct identifiers, and noise addition for sensitive continuous measures.
- Implement automated data validation assertions to verify no unhashed values from {{pii_fields_list}} leak into {{target_schema}}.
- Add partition management and archival logic enforcing the {{retention_policy_years}}-year cutoff filter.
- Inject transaction control blocks, rollbacks on error, and index creation for the partitioned target dataset.
Constraints
- MUST produce fully executable, syntactically correct code tailored exclusively to {{dataset_engine}}.
- MUST NOT retain any cleartext values listed in {{pii_fields_list}} in intermediate temporary views or destination schemas.
- Dynamic partition pruning must be enabled where supported by {{dataset_engine}}.
- Include inline commentary explaining every pseudonymization function used.
Output format
- Section 1: Pre-execution Prerequisites and Environment Setup (1 paragraph).
- Section 2: Complete Executable Script (SQL or native procedure block, fully annotated).
- Section 3: Data Quality & Anonymization Verification Queries (3-5 validation statements).
- Section 4: Rollback & Maintenance Runbook (150-250 words).
Self-review
- Confirm that every field in {{pii_fields_list}} is explicitly masked, hashed, or dropped in the script body.
- Verify that partitioning on {{partition_dimension}} matches {{dataset_engine}} best practices.
- Check that transaction isolation and error handling prevent partial unmasked data writes.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.