General engineering
AuraScore 81/100

Pipeline Cathodic Protection Voltage Diagnostic Script

Generate a Python diagnostic script to audit natural gas pipeline rectifier test points against NACE standards.

Use this prompt when deploying automated cathodic protection compliance monitoring for pipeline infrastructure. It polls rectifier telemetry, flags under-protection or hydrogen embrittlement risks, and logs audit-ready reports.

Template

Role: Senior Pipeline Integrity Automation Specialist specializing in cathodic protection (CP) regulatory compliance.

Context

  • Infrastructure Segment: {{pipeline_segment_id}}
  • Telemetry Interface: {{rectifier_telemetry_endpoint}}
  • Minimum Negative Potential Bound: {{min_protective_potential_mv}} mV CSE
  • Overprotection Safety Threshold: {{max_overprotection_potential_mv}} mV CSE
  • Polling Cycle Frequency: {{scan_interval_seconds}} seconds
  • Audit Log Destination: {{incident_log_file}}

Task

Author a production-ready Python automation script that continuously audits cathodic protection voltage telemetry from field rectifiers along a pipeline asset, classifies corrosion risks against industry thresholds, and records tamper-resistant compliance logs.

Method

  1. Initialize polling loops hitting {{rectifier_telemetry_endpoint}} every {{scan_interval_seconds}} seconds with HTTP session pooling.
  2. Ingest instant-off and on-potential DC pipe-to-soil voltage metrics across active test stations on {{pipeline_segment_id}}.
  3. Validate voltage polarity conventions ensuring negative potentials are evaluated relative to copper-copper sulfate electrodes (CSE).
  4. Compare instant-off readings against {{min_protective_potential_mv}} mV to detect inadequate corrosion protection.
  5. Evaluate readings against {{max_overprotection_potential_mv}} mV to identify coating disbondment and hydrogen overvoltage hazards.
  6. Assign status categories per test point (Normal Protection, Under-Protected, Over-Protected, Sensor Open Circuit).
  7. Write structured JSON log lines for every detected violation directly to {{incident_log_file}} with atomic file locking.

Constraints

  • MUST handle negative voltage integer comparisons correctly where -800 mV is less protective than -850 mV.
  • MUST NOT terminate execution loop if a single rectifier test station returns a timeout or null payload.
  • Output script must rely strictly on standard library modules or common industrial drivers (urllib3, json, logging).
  • File writes to {{incident_log_file}} MUST use POSIX non-blocking file locks to avoid race conditions.

Output format

Format the response into three distinct parts:

  1. Script Setup: Brief summary of polling parameters and expected telemetry JSON schemas.
  2. Diagnostic Python Script: The complete, runnable Python audit script in a code block.
  3. Sample Log Output: An exact three-line mock of the JSON log entries generated inside {{incident_log_file}}.

Self-review

  • Confirm that negative voltage thresholds ({{min_protective_potential_mv}} and {{max_overprotection_potential_mv}}) are compared with correct polarity math.
  • Ensure {{pipeline_segment_id}} is included in all alert logging schemas.
  • Verify that timing sleeps strictly match {{scan_interval_seconds}}.
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.

developers
developers-general
energy-utilities
pipeline
utilities
corrosion