SQL
AuraScore 81/100

Last-Mile Route Efficiency and SLA Deviation Data Model Specification

Define SQL dimensional models and windowing logic to track route deviations, dwell times, and delivery SLA breaches.

Use this template when architecting dbt or SQL transformation layers for last-mile delivery tracking. It creates an auditable technical spec for calculating operational metrics across dynamic delivery dispatch runs.

Template

Role: Staff Logistics Analytics Engineer specialising in last-mile operational modeling and dimensional data architecture.

Context

  • Logistics Network: {{logistics_network_name}}
  • Warehouse Platform: {{target_data_warehouse}}
  • SLA Margin: {{sla_threshold_minutes}}
  • Event Feed: {{tracking_event_granularity}}
  • Dwell Delay Threshold: {{dwell_time_outlier_threshold}}
  • Driver History Schema: {{driver_assignment_schema_type}}

Task

Produce an enterprise SQL data modeling specification defining dimensional tables, fact tables, and incremental CTE transformations that calculate planned vs. actual route variances, stop-level dwell time outliers, and driver SLA compliance rates.

Method

  1. Map the grain of the dimensional model at the individual delivery stop attempt level, linking orders, routes, and drivers.
  2. Architect an incremental fact table tracking delivery lifecycle state transitions based on {{tracking_event_granularity}}.
  3. Write robust window-function CTEs using LEAD and LAG to compute travel legs, actual stop arrival offsets, and stop duration.
  4. Formulate the conditional logic defining SLA breach categorization against {{sla_threshold_minutes}} and root cause classification.
  5. Design dwell time calculation logic that isolates valid deliveries from operational bottlenecks exceeding {{dwell_time_outlier_threshold}}.
  6. Integrate {{driver_assignment_schema_type}} structures to ensure historical driver-vehicle assignments preserve accurate point-in-time attribution.
  7. Provide testing and data quality assertions (uniqueness, referential integrity, non-negative interval checks) in dbt-compatible syntax.

Constraints

  • MUST handle out-of-order and duplicated delivery event timestamps gracefully via deterministic window sorting.
  • MUST NOT hardcode timezone adjustments; use dynamic UTC conversions relative to the delivery hub's local timezone attribute.
  • SQL code must be production-ready and fully compatible with {{target_data_warehouse}}.
  • Dimension surrogate keys must be generated using deterministic hashing rather than auto-incrementing integers.

Output format

    1. Conceptual and Physical Entity-Relationship Specification
    1. Staging and Transformation SQL Logic (Documented CTEs with inline comments)
    1. SLA Breach and Dwell Time Metric Calculation Layer (Full SQL View Definitions)
    1. Data Quality, Anomaly Handling, and Unit Test Assertions Length must be between 900 and 1300 words.

Self-review

  • Confirm that stop dwell calculations exclude transit intervals between consecutive waypoints.
  • Ensure the SLA breach classification correctly incorporates the {{sla_threshold_minutes}} tolerance window.
  • Verify all surrogate keys conform to deterministic MD5 or SHA256 hashing standards.
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-sql
transport-logistics
sql
last-mile
data-modeling