People Analytics Monthly Headcount and Attrition ETL Script Generator
Generate an automated Python data extraction and aggregation script for monthly HR headcount and turnover reporting.
Use this template when configuring automated pipelines to calculate HR metrics from raw HRIS event logs. It generates production-grade ETL scripts tailored to leadership headcount review cadences.
Role: Staff People Analytics Engineer specializing in automated workforce reporting pipelines.
Context
- HRIS data structure: {{hris_source_format}}
- Target cadence: {{target_reporting_cadence}}
- Organization grouping: {{business_unit_hierarchy}}
- Turnover calculation logic: {{attrition_calculation_rule}}
- Storage destination: {{output_storage_destination}}
- Threshold alert trigger: {{alert_threshold_turnover}}
Task
Write a self-contained, modular Python reporting script that ingests HRIS transaction records, computes monthly active headcount and annualized voluntary/involuntary turnover across organizational tiers, flags departments exceeding baseline churn thresholds, and publishes the summarized metric table to the designated storage destination.
Method
- Ingest raw log data based on {{hris_source_format}} with strict column type validation and date parsing.
- Apply snapshot interval logic matching {{target_reporting_cadence}} to isolate active employee states on baseline measurement dates.
- Segment employee census counts across {{business_unit_hierarchy}} dimensions including tenure bands and job families.
- Calculate voluntary and involuntary separation rates strictly following {{attrition_calculation_rule}}.
- Flag any business unit or department that breaches {{alert_threshold_turnover}} during the reporting cycle.
- Format output dataset into normalized reporting schemas with standardized metric naming conventions.
- Implement destination push handlers to transfer aggregated data cleanly to {{output_storage_destination}} with error handling.
Constraints
- Code MUST be written in clean Python 3.10+ using pandas or polars with complete type hints.
- MUST NOT hardcode credentials or connection strings; load all secrets via environment variables.
- MUST handle missing termination reason codes gracefully by classifying them into an unmapped category.
- Include inline logging for every major transformation stage to facilitate pipeline observability.
Output format
Provide the response in the following sequence:
- Architecture Overview (1 brief paragraph describing data flow).
- Complete Python Script (single executable code block containing imports, config class, transformation functions, and main execution block).
- Operational Instructions (concise deployment checklist with required environment variables).
Self-review
- Confirm all 6 context variables are actively utilized in the code logic or configuration block.
- Verify the turnover rate formulas strictly adhere to {{attrition_calculation_rule}}.
- Ensure exception handling covers empty source batches and failed storage uploads.
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.