Phield raises an alert when a PII count is well above that source’s usual level. What “well above” means depends on the trend method. percentage_delta, the default, alerts when a count is more than a fixed percentage over the recent average. z_score alerts when a count is far outside the source’s own normal variation.
Neither fits every source. A batch job whose counts swing widely trips a fixed percentage on ordinary days, and a steady service can change in a way that matters without ever crossing it. This guide explains how each method decides, runs both on the same counts, and shows how to test a choice with the simulation script and with replay before you change a live setting.
How each method decides
A series is one combination of source_id, organization, context, and PII type. Both methods judge each new count against that series alone, and both alert only on increases.
percentage_delta averages the series’ counts from the last PHIELD_WINDOW_SIZE hours (default 24) and alerts when the new count is more than PHIELD_ALERT_THRESHOLD (default 0.2, 20 percent) above that average.
- The average includes the count being judged, so a spike raises its own baseline a little.
- A count from the same source, organization, and context that does not include this PII type counts as 0 in the average.
- There is no warm-up. A series can alert on its second count.
- When the average is 0, nothing alerts.
z_score keeps the mean and standard deviation of every count the series has reported, and alerts when the new count is more than PHIELD_SENSITIVITY (default 3.0) standard deviations above the mean.
- It does not alert until the series has
PHIELD_WARMUP_COUNTcounts (default20). - The baseline is all of the series’ history, not a time window, so it adapts slowly to a lasting change in level.
- Every count joins the baseline, spikes included, except counts in a muted context, which 1.0.0 leaves out. After a spike, the standard deviation is larger and later spikes score lower.
- A series whose counts have never varied has a standard deviation of 0 and does not alert.
Cooldown, mutes, and the notification channels apply under both methods. One difference: a cooldown ends early after three counts back near normal, and “normal” means within half the threshold of the series mean under percentage_delta and a z-score under 1 under z_score.
Compare them on the same counts
Run two local instances, one per method. Both use in-memory storage and serve plain HTTP so the commands stay short, which is fine for a throwaway test and not for production. PHIELD_COOLDOWN_MINUTES=0 turns off the cooldown so every breach is reported. Leave it at the default in production.
docker run -d --name phield-pct -p 8081:8080 \
-e PHIELD_CERT_FILE= -e PHIELD_KEY_FILE= -e PHIELD_PORT=8080 \
-e PHIELD_TREND_METHOD=percentage_delta \
-e PHIELD_COOLDOWN_MINUTES=0 \
philterd/phield:1.0.0
docker run -d --name phield-z -p 8082:8080 \
-e PHIELD_CERT_FILE= -e PHIELD_KEY_FILE= -e PHIELD_PORT=8080 \
-e PHIELD_TREND_METHOD=z_score \
-e PHIELD_COOLDOWN_MINUTES=0 \
philterd/phield:1.0.0
Setting PHIELD_CERT_FILE and PHIELD_KEY_FILE to empty values stops the image from generating a certificate and starting HTTPS.
Save this as compare.sh. It sends the same counts to both instances: a bursty batch job, then a steady service.
#!/bin/bash
# Send the same series to a percentage_delta instance and a z_score instance.
send() { # source type count
for url in "$PCT_URL" "$Z_URL"; do
curl -s -o /dev/null -X POST "$url/ingest" -H "Content-Type: application/json" \
-d "{\"source_id\": \"$1\", \"organization\": \"example-corp\", \"context\": \"production\", \"pii_types\": {\"$2\": $3}}"
done
}
# A bursty batch job: counts swing between 60 and 150.
for c in 80 140 95 60 150 110 70 130 90 120 100 85 145 65 115 105 75 135 95 125 110 60 140 100; do
send batch-exporter email $c
done
send batch-exporter email 160 # a little above its usual swing
send batch-exporter email 400 # a real jump
# A steady service: counts stay between 38 and 42.
for c in 40 42 41 39 40 41 40 38 42 40 41 39 40 41 40 42 39 40 41 40 40 41 39 40; do
send claims-intake ssn $c
done
send claims-intake ssn 47 # small in percent, unusual for this source
Run it and read each instance’s breaches from its log:
chmod +x compare.sh
PCT_URL=http://localhost:8081 Z_URL=http://localhost:8082 ./compare.sh
docker logs phield-pct 2>&1 | grep '^20.*TREND BREACH'
docker logs phield-z 2>&1 | grep '^20.*TREND BREACH'
percentage_delta raises eight alerts, all for the batch job. Six are ordinary swings in its range:
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 140, Avg: 110.00, Increase: 27.27%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 150, Avg: 105.00, Increase: 42.86%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 130, Avg: 104.38, Increase: 24.55%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 145, Avg: 105.77, Increase: 37.09%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 135, Avg: 103.89, Increase: 29.95%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 140, Avg: 104.35, Increase: 34.17%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 160, Avg: 106.40, Increase: 50.38%
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 400, Avg: 117.69, Increase: 239.87%
z_score raises two, one per source:
2026/12/01 17:55:53 [TREND BREACH] Source: batch-exporter, Organization: example-corp, Context: production, PII Type: email, Current: 400, Mean: 106.40, StdDev: 28.72, Z-Score: 10.22
2026/12/01 17:55:53 [TREND BREACH] Source: claims-intake, Organization: example-corp, Context: production, PII Type: ssn, Current: 47, Mean: 40.25, StdDev: 1.01, Z-Score: 6.68
| Count | percentage_delta (0.2) | z_score (3.0) |
|---|---|---|
| Batch job, ordinary swings up to 150 | 6 alerts | none |
| Batch job, 160 | alert | none |
| Batch job, 400 | alert | alert |
| Steady service, 47 | none: 16 percent over its average | alert: 6.68 standard deviations over its mean |
Each breach is written twice: to standard output without a timestamp, and to standard error with one. The 2>&1 merges the two, and grep '^20' keeps the timestamped copy.
Check a choice against your own history with replay
To see what a method and setting would have done on stored counts, use /replay on an instance that has stored real counts. It reruns detection over a time range using the instance’s configured method and the test_threshold you pass: the threshold for percentage_delta, the sensitivity for z_score. It sends no notifications and does not change stored baselines. Alerting on PII spikes with Phield covers the request in full.
Against the two instances above, before running the simulation in the next section. Replay covers every source with counts in the time range, so run it first, or the simulated counts appear in its results too. Set start_time and end_time to the day you sent the counts; these ran on December 1, 2026.
for t in 0.2 1.0; do curl -s -X POST http://localhost:8081/replay -H "Content-Type: application/json" \
-d "{\"start_time\": \"2026-12-01T00:00:00Z\", \"end_time\": \"2026-12-02T00:00:00Z\", \"test_threshold\": $t}" \
| jq -c "{test_threshold: $t, breaches: .virtual_breaches_detected, counts: [.breach_details[].count]}"; done
for t in 3 2; do curl -s -X POST http://localhost:8082/replay -H "Content-Type: application/json" \
-d "{\"start_time\": \"2026-12-01T00:00:00Z\", \"end_time\": \"2026-12-02T00:00:00Z\", \"test_threshold\": $t}" \
| jq -c "{test_threshold: $t, breaches: .virtual_breaches_detected, counts: [.breach_details[].count]}"; done
{"test_threshold":0.2,"breaches":9,"counts":[140,150,130,145,135,125,140,160,400]}
{"test_threshold":1.0,"breaches":1,"counts":[400]}
{"test_threshold":3,"breaches":2,"counts":[400,47]}
{"test_threshold":2,"breaches":3,"counts":[160,400,47]}
Raising the percentage_delta threshold to 1.0 (100 percent) quiets the batch job but would still miss the steady service’s 47. Under percentage_delta, replay’s average leaves out the count being judged, while live detection includes it, and it averages only the counts that include the type, while live detection counts a missing type as 0. So replay can report a few more breaches than the live run did: nine here against eight.
Test with the simulation script
Simulation tests the mechanics. The Phield repository has simulate_data.sh, which sends randomized counts for four PII types from one source: ITERATIONS baseline counts, then ten counts with spikes in credit-card and ssn. Run it from a checkout of the repository. For z_score, set ITERATIONS above PHIELD_WARMUP_COUNT so the series is past its warm-up when the spike starts:
PHIELD_URL=http://localhost:8082 ITERATIONS=25 SLEEP_INTERVAL=0 ./simulate_data.sh
docker logs phield-z 2>&1 | grep '^20.*TREND BREACH' | grep simulated
The counts are random, so yours will differ. One run:
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: credit-card, Current: 216, Mean: 23.64, StdDev: 2.51, Z-Score: 76.57
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: ssn, Current: 65, Mean: 4.04, StdDev: 1.31, Z-Score: 46.50
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: credit-card, Current: 222, Mean: 31.04, StdDev: 37.07, Z-Score: 5.15
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: email, Current: 128, Mean: 108.08, StdDev: 6.23, Z-Score: 3.20
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: ssn, Current: 68, Mean: 6.38, StdDev: 11.79, Z-Score: 5.22
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: credit-card, Current: 243, Mean: 38.11, StdDev: 51.23, Z-Score: 4.00
2026/12/01 17:56:01 [TREND BREACH] Source: simulated-server-01, Organization: demo-org, Context: context1, PII Type: ssn, Current: 69, Mean: 8.67, StdDev: 16.41, Z-Score: 3.68
Two things show up here. The credit-card scores fall from 76.57 to 4.00 across the spike, because each spike joins the baseline and widens the standard deviation, and some later spike counts score below 3.0 and do not alert. The email count of 128 alerts even though the script calls email stable, because the spike phase sends 110 to 129 against a baseline of 100 to 119, and on a series that steady, 128 is more than three standard deviations out. The script sends plain HTTP without -k, so point it at an instance that serves HTTP, as these do.
Which to choose
- Use
percentage_deltawhen a source’s counts are stable from batch to batch and any rise of a given size should be looked at. It alerts from the second count, which suits a new source. - Use
z_scorewhen counts vary widely from one batch to the next, or when a small change on a steady source matters. Expect no alerts for each series until it hasPHIELD_WARMUP_COUNTcounts. - The method is set per instance with
PHIELD_TREND_METHOD, not per source. To use both, run one instance per method and send each source to the one that fits it. - After a planned change moves a source’s normal level,
percentage_deltaadjusts withinPHIELD_WINDOW_SIZEhours, as the old counts leave the window.z_scorekeeps judging the new level against the whole history, so it takes much longer to adjust.
Both methods describe how counts move, not whether a given document contains PII. Treat an alert as a prompt to look at what changed in the source, and validate the settings against your own history.