Sponsored Research Grant Reconciliation SQL Query Specification
Build a financial SQL query specification to reconcile sponsor grant spending, effort allocations, and compliance rules.
Use this template when preparing audit-ready database views and queries for sponsored research grant accounting. It guides the creation of reconciliation CTEs, effort certification joins, and variance detection scripts.
Role: Principal Research Analytics Architect with deep expertise in sponsored project financial compliance and audit data modeling.
Context
- Sponsoring institution: {{research_institution}}
- Granting body / sponsor: {{funding_agency}}
- Active reporting period: {{grant_fiscal_year}}
- Regulatory audit standard: {{compliance_framework}}
- Target relational engine: {{sql_engine}}
- Expense transaction level: {{ledger_granularity}}
Task
Construct a rigorous SQL specification that details ledger reconciliation views, effort certification joins, and variance detection logic for sponsored academic research grants at {{research_institution}} under {{compliance_framework}} guidelines.
Method
- Identify transaction boundaries across general ledger and sponsored program sub-ledgers for {{grant_fiscal_year}}.
- Normalize project expenditure line items down to {{ledger_granularity}} granularity.
- Construct temporal join predicates aligning faculty effort percentages with payroll disbursement periods.
- Define direct versus indirect cost calculations adhering to {{funding_agency}} recovery guidelines.
- Build CTE-driven reconciliation views to flag unallowable expense codes and milestone budget overruns.
- Apply window functions to track cumulative burn rates against awarded milestone budgets.
- Optimize query execution for {{sql_engine}} using partition pruning on grant account keys.
- Establish deterministic audit logging views that record historical modifications to allocation ratios.
Constraints
- MUST use standard, deterministic SQL syntax compatible with {{sql_engine}}.
- MUST calculate variance down to the exact monetary unit specified by {{ledger_granularity}}.
- MUST NOT drop or coalesce historical adjustment records that provide necessary audit trails.
- All CTEs and interim temp tables MUST include explicit column typing and zero-safe arithmetic.
Output format
- Architectural Scope & Audit Objective (1 concise section)
- Source Mapping & Entity Relationship Table (Markdown table of entities and foreign keys)
- Production SQL View Definitions (Commented SQL code blocks for ledger reconciliation and effort tracking)
- Audit Trail & Variance Validation Suite (3-5 validation queries with expected outputs)
Self-review
- Ensure all 6 context variables appear correctly in the prompt body.
- Verify that calculations for direct and indirect costs comply with {{funding_agency}} requirements.
- Check that audit immutability constraints are satisfied across all view definitions.
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.