Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ All notable changes. Format based on Keep a Changelog. Versions are unreleased u
or more digits, places listed after a place, spoken IP addresses and emails, multi-word
passwords and read-back codes, URL paths, unit numbers and city/state tails of addresses,
and given names that are ordinary words when they sit next to person words.
- Spoken URLs: "find it online at acme dot test slash help" is a URL, not an email, so its
path is redacted too; path words joined by "dash", domain names spoken as two words and
newer endings such as ".health" are handled. URL recall on the evaluation sets is now 100%.
- Place names at Tier 0: a capitalised name redacted in part is redacted whole ("Port St.
Lucie", "Dana Point"); more words that end place names ("Gold Coast", "the Panhandle");
places in text without capitals ("orange county", "salt lake city").
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ The numbers below are for the default protection (personal data):

| Validation (56) / user set (8) | PII recall | PII-clean transcripts | Business context redacted or flagged | Text redacted |
| --- | --- | --- | --- | --- |
| Tier 0 (rules) | 98.0% / 88.2% | 80% / 25% | 90% / 80% | 15% / 21% |
| Tier 1 (+ NER ensemble) | 98.6% / 89.5% | 86% / 25% | 97% / 82% | 17% / 23% |
| Tier 2 (+ Phi-4-mini) | 98.6% / 89.5% | 86% / 25% | 97% / 83% | 18% / 25% |
| Tier 0 (rules) | 99.3% / 88.9% | 93% / 25% | 91% / 79% | 15% / 21% |
| Tier 1 (+ NER ensemble) | 99.8% / 90.2% | 98% / 25% | 97% / 82% | 17% / 24% |
| Tier 2 (+ Phi-4-mini) | 99.8% / 90.2% | 98% / 25% | 97% / 83% | 18% / 25% |
| Baseline: plain regexes | 14.2% / 7.2% | 0% / 0% | | |

The user set has only 8 transcripts, so its numbers are loose: the 95% interval for Tier 0
PII recall is 80.8-94.7% there (96.9-99.0% on validation), and its PII-clean rate could be
PII recall is 81.4-95.2% there (98.5-99.8% on validation), and its PII-clean rate could be
anywhere from 0% to 62%. `offrecord eval` prints these intervals.

Tier 2 does not change PII recall on these sets. What it adds is indirect identifiers: on 15
Expand Down
7 changes: 4 additions & 3 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ Every other command installs a network guard (see below) before doing any work.
### R2. Careless logging and error output
- No raw text in logs, exceptions, tracebacks or debug output. Errors carry a code, a position
(field, turn, line, offset) and a category, never content.
- The CLI catches every exception at the top level. For offrecord's own errors it prints the code and
position. For unexpected exceptions it prints only the exception *type* and the code location,
never the exception message (third-party messages, e.g. decode errors, can embed input bytes).
- The CLI catches every exception at the top level. For offrecord's own errors it prints the
code and position. For unexpected exceptions it prints only the exception *type* and the code
location, never the exception message (third-party messages, e.g. decode errors, can embed
input bytes).
- `--debug` prints stack frames (file, line, function) but never exception messages or locals.
- `sys.excepthook`, `threading.excepthook`, `sys.unraisablehook` and `warnings.showwarning`
are replaced with content-free versions; logging's last-resort handler is removed and the
Expand Down
8 changes: 4 additions & 4 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ <h2 id="accuracy-h">Accuracy</h2>
<caption class="sr-only">PII recall, PII-clean transcripts, business context redacted or flagged, and share of text redacted by tier on the validation and user sets</caption>
<thead><tr><th scope="col">Validation (56) / user set (8)</th><th scope="col" class="num">PII recall</th><th scope="col" class="num">PII-clean transcripts</th><th scope="col" class="num">Business context redacted or flagged</th><th scope="col" class="num">Text redacted</th></tr></thead>
<tbody>
<tr><th scope="row">Tier 0 (rules)</th><td class="num">98.0% / 88.2%</td><td class="num">80% / 25%</td><td class="num">90% / 80%</td><td class="num">15% / 21%</td></tr>
<tr><th scope="row">Tier 1 (+ NER ensemble)</th><td class="num">98.6% / 89.5%</td><td class="num">86% / 25%</td><td class="num">97% / 82%</td><td class="num">17% / 23%</td></tr>
<tr><th scope="row">Tier 2 (+ Phi-4-mini)</th><td class="num">98.6% / 89.5%</td><td class="num">86% / 25%</td><td class="num">97% / 83%</td><td class="num">18% / 25%</td></tr>
<tr><th scope="row">Tier 0 (rules)</th><td class="num">99.3% / 88.9%</td><td class="num">93% / 25%</td><td class="num">91% / 79%</td><td class="num">15% / 21%</td></tr>
<tr><th scope="row">Tier 1 (+ NER ensemble)</th><td class="num">99.8% / 90.2%</td><td class="num">98% / 25%</td><td class="num">97% / 82%</td><td class="num">17% / 24%</td></tr>
<tr><th scope="row">Tier 2 (+ Phi-4-mini)</th><td class="num">99.8% / 90.2%</td><td class="num">98% / 25%</td><td class="num">97% / 83%</td><td class="num">18% / 25%</td></tr>
<tr class="dim"><th scope="row">Baseline: plain regexes</th><td class="num">14.2% / 7.2%</td><td class="num">0% / 0%</td><td class="num"></td><td class="num"></td></tr>
</tbody>
</table>
</div>
<p class="note"><strong>Sealed set:</strong> 80 transcripts written blind and opened once, against targets fixed beforehand. Tier 0 missed two of them: PII recall 93.4% (target 95%) and PII-clean transcripts 46% (target 65%), almost entirely because of place names (84% caught). Names, account and card numbers, SSNs, IPs and URLs were all caught. Tier 1 reached 96.4% and 65%. Place handling has since been improved on new tuning data; the next release will be scored on a fresh sealed set.</p>
<p class="note">Read the PII-clean column first: in some transcripts a name or number still gets through, so you still read the output before sharing it. The user set has only 8 transcripts, so its numbers are loose (95% interval for Tier 0 PII recall: 80.8&ndash;94.7%). Tier 2 adds indirect identifiers rather than PII recall: on 15 held-back transcripts, descriptions of a person were redacted 63% of the time at Tier 0, 68% at Tier 1 and 78% at Tier 2. On Earnings-21 (44 real earnings calls, never tuned on) PII recall is 85.7% at Tier 0 and 89.8% at Tier 1.</p>
<p class="note">Read the PII-clean column first: in some transcripts a name or number still gets through, so you still read the output before sharing it. The user set has only 8 transcripts, so its numbers are loose (95% interval for Tier 0 PII recall: 81.4&ndash;95.2%). Tier 2 adds indirect identifiers rather than PII recall: on 15 held-back transcripts, descriptions of a person were redacted 63% of the time at Tier 0, 68% at Tier 1 and 78% at Tier 2. On Earnings-21 (44 real earnings calls, never tuned on) PII recall is 85.7% at Tier 0 and 89.8% at Tier 1.</p>
<div class="callout" role="note">
<p><strong>All evaluation data is synthetic</strong>: generated conversations with invented names. It cannot capture real speech-recognition errors, real names and their spelling variety, domain jargon, cross-talk, or the clients and codenames in your deny-list. Expect real-world recall to be lower than these numbers, and review the flagged spans.</p>
</div>
Expand Down
46 changes: 42 additions & 4 deletions src/offrecord/normalize/spoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,25 @@ def digit_runs(text: str) -> list[Edit]:
"eu", "tv", "xyz", "cloud", "tech", "example", "test", "invalid", "local", "internal",
"ie", "nz", "sg", "za", "br", "mx", "pl", "be", "at", "dk", "fi", "pt", "gr", "kr", "cn",
} # fmt: skip
# Newer endings that are also ordinary words: only after a literal "dot" ("acme dot health"),
# never "point" or "period" ("at this point today").
WORD_TLDS = {
"health", "care", "clinic", "dental", "law", "legal", "insurance", "bank", "finance",
"shop", "store", "online", "site", "agency", "studio", "solutions", "services", "network",
"digital", "media", "systems", "group", "academy", "school", "events", "travel", "energy",
"realty", "properties",
} # fmt: skip
_DOT = {"dot", "period", ".", "point"}
_AT = {"at", "@"}
_LOCAL_JOIN = {"dot": ".", "period": ".", ".": ".", "underscore": "_", "_": "_",
"dash": "-", "hyphen": "-", "-": "-"} # fmt: skip
_STOP_LOCAL = {"me", "us", "him", "her", "them", "is", "it's", "email", "mail", "address"}
# Words that never join a domain label spoken as two words ("acme health dot org").
_NOT_LABEL = {
"site", "website", "page", "link", "url", "visit", "go", "at", "to", "is", "on", "our",
"the", "their", "your", "my", "new", "web", "online", "check", "email",
} # fmt: skip
_PATH_JOIN = {"dash": "-", "hyphen": "-", "underscore": "_", "-": "-", "_": "_"}


_DOMAIN_TOKEN_RE = re.compile(r"[^\W_]+(?:-[^\W_]+)*(?:'s)?|[^\w\s]|_")
Expand All @@ -484,23 +498,39 @@ def spoken_email_url(text: str) -> list[Edit]:
used_until = -1
for k, t in enumerate(toks):
tld = _strip_possessive(t.low)
if k <= used_until or tld not in TLDS or k < 2 or toks[k - 1].low not in _DOT:
if k <= used_until or k < 2 or toks[k - 1].low not in _DOT:
continue
if tld not in TLDS and not (tld in WORD_TLDS and toks[k - 1].low == "dot"):
continue
# Only rewrite if at least one separator is spoken (otherwise it is already literal).
# Walk back over "label dot label dot tld".
j = k
domain = [_strip_possessive(t.text)]
spoken = toks[k - 1].low != "."
while j - 2 >= 0 and toks[j - 1].low in _DOT and _is_label(toks[j - 2]) and len(domain) < 6:
domain.insert(0, toks[j - 2].text)
label = toks[j - 2].text
spoken = spoken or toks[j - 1].low != "."
j -= 2
# Speech-to-text often splits a name: "acme health dot org" -> acmehealth.org.
if (
spoken
and j - 1 >= 0
and _is_label(toks[j - 1])
and toks[j - 1].low not in _NOT_LABEL
and toks[j - 1].low not in _STOP_LOCAL
and toks[j - 1].end + 1 == toks[j].start
):
label = toks[j - 1].text + label
j -= 1
domain.insert(0, label)
if len(domain) < 2:
continue
start_tok = j
result = ".".join(d.lower() for d in domain)
# Email: "local at domain"
if j - 2 >= 0 and toks[j - 1].low in _AT:
# Email: "local at domain". A path after the domain makes it a URL ("find it online at
# acme dot com slash help").
path_next = k + 1 < len(toks) and toks[k + 1].low in ("slash", "/")
if j - 2 >= 0 and toks[j - 1].low in _AT and not path_next:
spoken = spoken or toks[j - 1].low == "at"
local: list[str] = []
m = j - 2
Expand Down Expand Up @@ -529,6 +559,14 @@ def spoken_email_url(text: str) -> list[Edit]:
result += "/" + toks[end_tok + 2].low
spoken = True
end_tok += 2
# "slash pricing dash plans" -> /pricing-plans
while (
end_tok + 2 < len(toks)
and toks[end_tok + 1].low in _PATH_JOIN
and toks[end_tok + 2].low.isalnum()
):
result += _PATH_JOIN[toks[end_tok + 1].low] + toks[end_tok + 2].low
end_tok += 2
if not spoken:
continue
edits.append((toks[start_tok].start, toks[end_tok].end, result))
Expand Down
5 changes: 4 additions & 1 deletion src/offrecord/redact/detectors/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

TLDS = (
"com|org|net|io|co|edu|gov|mil|int|uk|us|de|fr|ca|au|in|biz|info|ai|app|dev|me|ly|nl|es|it|"
"jp|ch|se|no|eu|tv|xyz|cloud|tech|example|test|invalid|local|internal|corp|ie|nz|sg|za|br|mx"
"jp|ch|se|no|eu|tv|xyz|cloud|tech|example|test|invalid|local|internal|corp|ie|nz|sg|za|br|mx|"
"health|care|clinic|dental|law|legal|insurance|bank|finance|shop|store|online|site|agency|"
"studio|solutions|services|network|digital|media|systems|group|academy|school|events|"
"travel|energy|realty|properties"
)
EMAIL = re.compile(r"(?<![\w.+-])[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+")
PHONE_SEP = re.compile(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,23 @@ def test_places_in_text_without_capitals(line, hidden, visible):
out = body(redact(f"a: {line}\na: ok\n")[0])
assert not any(h in out for h in hidden)
assert all(v in out for v in visible)


@pytest.mark.parametrize(
("line", "hidden", "visible"),
[
("find it online at acme dot test slash help dash desk today", ["acme", "help", "desk"],
["today"]),
("go to zentrix dot com slash pricing dash plans for details", ["pricing", "plans"],
["details"]),
("visit portal dot acme health dot org to log in", ["portal", "acme", "health"],
["log in"]),
("check acme dot health slash intake", ["acme", "intake"], []),
("email dana at acme dot com please", ["dana", "acme"], ["please"]),
("at this point today we are fine", [], ["point today"]),
],
) # fmt: skip
def test_spoken_urls_with_paths_and_split_names(line, hidden, visible):
out = body(redact(f"A: {line}\nA: ok\n")[0])
assert not any(h in out for h in hidden)
assert all(v in out for v in visible)