General analytics
AuraScore 81/100

Nonprofit Donor Cohort Retention and Decay Pipeline Builder

Builds a production-ready SQL and Python data pipeline to calculate donor retention curves and churn rates across campaign tiers.

Use this template when developing recurring analytical workflows to evaluate non-profit donor decay, multi-year retention rates, and gift size transitions across historical fundraising drives.

Template

Role: Lead Nonprofit Analytics Architect with deep expertise in donor lifetime modeling and CRM warehousing.

Context

  • Mission Sector: {{nonprofit_cause_sector}}
  • Source Platform: {{primary_crm_platform}}
  • Historical Analysis Range: {{historical_window_years}}
  • Sustaining Gift Cutoff: {{recurring_gift_threshold}}
  • Time Granularity: {{cohort_granularity}}
  • Target SQL Engine: {{reporting_database_dialect}}

Task

Create a dual SQL and Python data pipeline script that transforms transactional giving history from {{primary_crm_platform}} into cohort-based donor retention matrices, churn indicators, and multi-year donor survival curves.

Method

  1. Formulate a Common Table Expression (CTE) in {{reporting_database_dialect}} to aggregate individual transaction logs by unique donor ID and acquisition date.
  2. Bucket each donor into an initial acquisition cohort based on {{cohort_granularity}} across {{historical_window_years}}.
  3. Calculate activity flags for subsequent periods by checking giving events against {{recurring_gift_threshold}}.
  4. Write a pivot query to compute active retention percentages per cohort index period.
  5. Develop a Python wrapper script using sqlalchemy to execute the database query and extract the cohort matrix.
  6. Compute average cohort decay rates, year-over-year retention velocity, and lapse probabilities using pandas.
  7. Format the resulting retention matrix into an exportable summary table and log key attrition metrics.

Constraints

  • MUST write dialect-specific SQL conforming precisely to {{reporting_database_dialect}} syntax standards.
  • MUST NOT rely on proprietary third-party libraries outside of standard open-source Python analytics packages.
  • Database queries MUST account for recurring vs. one-time gifts using {{recurring_gift_threshold}} logic.
  • Calculations must handle dormant donor reactivation without artificially inflating new acquisition cohorts.

Output format

Deliver the solution in the following sequence:

  1. SQL Query Specification: Formatted, documented SQL CTEs ready for database deployment.
  2. Python Pipeline Script: End-to-end Python script containing query execution, matrix calculation, and cohort exports.
  3. Operational Notes: Instructions on parameterizing cohort timeframes and interpreting calculated decay metrics.

Self-review

  • Ensure SQL window functions correctly partition by donor identifier without duplicate counts.
  • Confirm that Python transformations handle sparse matrices where older cohorts lack recent activity.
  • Verify all 6 provided variables are explicitly referenced within the queries or pipeline code.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-general
public-sector-nonprofit
sql
python
nonprofit