Time-Tracking and Billing Pipeline Anomaly Diagnostic Script
Generate a diagnostic script to isolate currency rounding and rate mismatches in professional services billing sync pipelines.
Use this template when timecard entries across multi-currency client engagements fail to reconcile accurately between timesheet platforms and ERP ledgers.
Role: Senior Revenue Systems Architect specializing in ERP integrations for professional services firms.
Context
- Target enterprise ERP: {{client_erp_system}}
- Raw anomaly log dump: {{discrepancy_sample_log}}
- Contractual rate calculation rules: {{billing_rate_rules}}
- Financial ledger rounding precision: {{target_currency_precision}}
- Ledger database schema definition: {{database_schema}}
- Critical alert threshold percentage: {{failure_threshold_pct}}
Task
Author a standalone Python diagnostic and remediation script that ingests the discrepancy log, parses billing events against the schema, validates precision rounding edge cases, and outputs structured repair patches alongside a diagnostic summary report.
Method
- Ingest {{discrepancy_sample_log}} and map unparsed event payloads against {{database_schema}}.
- Reconstruct billing calculation trees evaluating rate multipliers from {{billing_rate_rules}}.
- Identify floating-point arithmetic drift and multi-currency rounding errors against {{target_currency_precision}}.
- Correlate missing invoice line items and orphaned timecard IDs between {{client_erp_system}} and local staging records.
- Flag batches exceeding the error tolerance defined by {{failure_threshold_pct}} for quarantine.
- Generate idempotent SQL/API mutation payloads to patch corrupt ledger entries.
- Implement a dry-run execution harness with rollback mechanisms to safely test fixes.
Constraints
- MUST implement strict decimal arithmetic using Python's
decimalmodule; standard floats MUST NOT be used. - MUST NOT perform live database writes without an explicit
--commitflag. - The script MUST log execution telemetry in JSON-L format to standard error.
- Output code must be self-contained with zero third-party dependencies outside standard library and
pytest.
Output format
- Executive RCA Summary (Markdown block, max 200 words)
- Diagnostic Python Script (Complete code block with docstrings and argparse CLI)
- Unit Test Suite (Pytest block with at least 3 edge cases)
Self-review
- Ensure all variables ({{client_erp_system}}, {{discrepancy_sample_log}}, {{billing_rate_rules}}, {{target_currency_precision}}, {{database_schema}}, {{failure_threshold_pct}}) are explicitly handled.
- Confirm idempotent dry-run behavior is enforced by default.
- Verify decimal precision handles sub-cent rounding differentials accurately.
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.