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
30 changes: 30 additions & 0 deletions .changeset/fit-check-contact-details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@launchstack/pipelines": patch
---

The distribution pipeline's fit check after research no longer sends email
addresses or phone numbers to the chat model. `enrichCandidate` asks the fit
judge about each researched company with the company's name and listing
description, the dossier's summary, its risks and up to 20 evidence claims.
With the keyless site reader those claims are sentences from the company's own
website, and they carry its mailboxes and sometimes a phone number. Each of
those texts now passes through `withoutContactDetails` (new, in
`distribution/redact.ts`) before it is joined and cut to length: an email
address becomes `[email]` and a phone number `[phone]`.

What is stored and shown is unchanged: the dossier, its contact channels, the
evidence and the published profile still hold every address and number. No
other call changes.

A phone number is told from the other numbers in a text. Digits are a phone
number when the text says so (a `+` country code, or "tel", "mobil", "fax" in
front of them), or when there are eight or more of them, written the way
phone numbers are, and they do not read as something else. Years, dates,
opening hours, amounts (a currency, a percent sign, thousands in threes),
a street number beside a postcode, and numbers the text calls a registration,
VAT or customs number ("Org.nr.", "MVA", "KvK", "Company No.", "HS") stay. A
number that could be either goes: a bare nine digits in threes is how Spanish,
Portuguese, Polish and Czech phone numbers are written, and also a Norwegian
organisation number with nothing beside it to say so. Not caught: a local
number of fewer than eight digits with no label and no country code, digits
glued to letters, and an address or number spelled out in words.
251 changes: 251 additions & 0 deletions pipelines/src/distribution/redact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/**
* What leaves a text and what stays. Every address and number here is made
* up: reserved example domains, zeros, counting runs, and the phone ranges
* set aside for fiction.
*/
import { describe, expect, it } from "vitest";

import { EMAIL_PLACEHOLDER, PHONE_PLACEHOLDER, withoutContactDetails } from "./redact";

/** The text with its one contact detail gone and nothing else touched. */
function redacted(before: string, detail: string, after: string, placeholder: string): void {
expect(withoutContactDetails(`${before}${detail}${after}`)).toBe(
`${before}${placeholder}${after}`
);
}

describe("withoutContactDetails: email addresses", () => {
it.each([
"someone@example.com",
"some.one+offers@mail.example.co.uk",
"SOMEONE@EXAMPLE.COM",
"post@bakeri.example",
"mailto:someone@example.com",
"someone [at] example [dot] com",
"someone (at) example.com",
"someone(a)example.com",
])("removes %s", email => {
redacted("Example Bakery publishes a named mailbox: ", email, ".", EMAIL_PLACEHOLDER);
redacted("Write to ", email, " to order", EMAIL_PLACEHOLDER);
});

it("removes every address in a text", () => {
expect(withoutContactDetails("Sales: sales@example.com, press: press@example.org.")).toBe(
"Sales: [email], press: [email]."
);
});

it.each([
"Find us @ Eksempelgata 12",
"Follow @examplebakery for news",
"Option (a) is the bakery, option (b) the café",
])("leaves %s alone", text => {
expect(withoutContactDetails(text)).toBe(text);
});
});

describe("withoutContactDetails: phone numbers", () => {
it.each([
// With a country code.
"+47 000 00 000",
"+4700000000",
"(+47) 00 00 00 00",
"0047 00 00 00 00",
"+44 20 7946 0000",
"+44 (0)20 7946 0000",
"+1 (555) 010-0100",
"+31 6 00000000",
"+49 30 0000000",
"+49 30 - 0000000",
"+49 (0) 30 000000-0",
"+34 000 000 000",
// As written inside a country.
"000 00 000",
"12 34 56 78",
"12345678",
"12.34.56.78",
"(555) 010-0100",
"555-010-0100",
"555.010.0100",
"020 7946 0000",
"07700 900000",
"030 0000000",
"030/0000000",
"030 / 0000000",
"030 - 00 00 00 0",
"06-00000000",
"01 00 00 00 00",
"0400.00.00.00",
"0400.000000",
"333/1234567",
"123 456 789",
"1234 5678",
"12345 67890",
"12-34-56-78",
"(12) 34 56 78",
])("removes %s", phone => {
redacted("Call ", phone, " to order.", PHONE_PLACEHOLDER);
redacted("Example Bakery, ", phone, "", PHONE_PLACEHOLDER);
});

it.each([
["Tlf 00000", "Tlf [phone]"],
["Tel.: 555 0100", "Tel.: [phone]"],
["Telefon: 123 456", "Telefon: [phone]"],
["Phone number: 555-0100", "Phone number: [phone]"],
["Mobil 123 45 678", "Mobil [phone]"],
["Fax: 030 000000", "Fax: [phone]"],
])("removes a short number the text calls a phone number: %s", (text, expected) => {
expect(withoutContactDetails(text)).toBe(expected);
});

it("removes each of two numbers and keeps what is beside them", () => {
expect(
withoutContactDetails(
"Tlf: 12 34 56 78 / 87 65 43 21. Open 08.00-16.00 since 01.02.2024, call 000 00 000."
)
).toBe("Tlf: [phone] / [phone]. Open 08.00-16.00 since 01.02.2024, call [phone].");
});

it("leaves the brackets around a number balanced", () => {
expect(withoutContactDetails("Reception (12 34 56 78) is open.")).toBe(
"Reception ([phone]) is open."
);
expect(withoutContactDetails("Call +47 000 00 000 (9-16).")).toBe("Call [phone] (9-16).");
});

it("finds a number beside a date, a postcode or an organisation number", () => {
expect(withoutContactDetails("Updated 27.11.2024 12 34 56 78")).toBe(
"Updated 27.11.2024 [phone]"
);
expect(withoutContactDetails("Eksempelgata 12, 0155 Oslo 12 34 56 78")).toBe(
"Eksempelgata 12, 0155 Oslo [phone]"
);
expect(withoutContactDetails("Org.nr. 987 654 321, tlf 12 34 56 78")).toBe(
"Org.nr. 987 654 321, tlf [phone]"
);
});

it("removes both of two numbers joined by a comma", () => {
expect(withoutContactDetails("12 34 56 78,87 65 43 21")).toBe("[phone],[phone]");
});

it("takes a number with a country code for a phone number whatever it is called", () => {
expect(withoutContactDetails("Company number: +44 20 7946 0000")).toBe(
"Company number: [phone]"
);
});

it("does not take a word that only starts like a label for one", () => {
expect(withoutContactDetails("Registrer deg og ring nr 12 34 56 78")).toBe(
"Registrer deg og ring nr [phone]"
);
});

it("does not take a company's name for a label", () => {
// "HS" before a number is a customs code; "HS AS" is a company.
expect(withoutContactDetails("Example HS AS 12 34 56 78")).toBe("Example HS AS [phone]");
});
});

describe("withoutContactDetails: numbers that are not phone numbers", () => {
it.each([
// Years.
"Founded in 1987, family-run since 2004.",
"In business 1998-2024.",
"In business 1998–2024.",
"Won the award in the 2019/2020 season.",
"Prize winner 2021 2022 and 2023.",
// Prices and amounts.
"Turnover of kr 12 500 000 last year.",
"Turnover of 12 500 000 kr last year.",
"Turnover of NOK 125 430 210.",
"Turnover of 125 430 210 kroner.",
"Turnover of € 12.500.000 last year.",
"Turnover of 12.500.000,00 last year.",
"Turnover of 125 430 210,50 last year.",
"Turnover of $1,250,000 last year.",
"Turnover of 125 000 000 last year.",
"Orders from 1 250 000,- and up.",
"Sells 10 000-12 000 loaves a week.",
"Roasts 12 500 000 cups' worth of beans a year.",
"Turnover 2023 12 500 000",
"Founded 2015 - 120 000 customers since.",
// Postcodes.
"Eksempelgata 12, 0155 Oslo",
"Eksempelgata 123 0155 Oslo",
"Voorbeeldstraat 123, 1015 CJ Amsterdam",
"Beispielstraße 123 10115 Berlin",
"100 Example Street, Baltimore, MD 21201",
"100 Example Street, Baltimore, MD 21201-1234",
"1 Example Road, London SW1A 1AA",
// Organisation and registration numbers.
"Org.nr. 987 654 321",
"Org.nr: 987654321 MVA",
"Org. nr.: NO 987 654 321 MVA",
"NO 987 654 321 MVA",
"Organisasjonsnummer 987 654 321",
"Organisation number: 987654321",
"Vårt org.nr. er 987 654 321",
"Our company number is 01234567",
"VAT: NO 987 654 321",
"VAT Reg No. 123 4567 89",
"CHE-123.456.789 MWST",
"KvK 12345678",
"KvK-nummer: 12345678",
"CVR-nr. 12 34 56 78",
"VAT NL123456789B01",
"Company No. 01234567",
"Registered in England and Wales No. 01234567",
"SIRET 123 456 789 00012",
"HS code 0901.21.00",
// Percentages.
"45% of sales are wholesale.",
"Grew 12,5 % last year, 100 % organic.",
// Dates and opening hours.
"Opened on 27.11.2024.",
"Opened on 2024-11-27.",
"Opened on 11/27/2024.",
"Closed 01.01.2024-31.12.2024 for rebuilding.",
"Open 08.00-16.00.",
"Open Mon-Fri 0800-1600.",
// Other everyday numbers.
"Certified to ISO 9001:2015.",
"A team of 12 in 1 500 m² of bakery, open 24/7.",
"Found at 59.913868, 10.752245.",
])("leaves %s alone", text => {
expect(withoutContactDetails(text)).toBe(text);
});

it("removes a nine-digit number in threes when nothing says what it is", () => {
// Spanish, Portuguese, Polish and Czech phone numbers and Norwegian
// organisation numbers are written alike; unlabelled, it goes.
expect(withoutContactDetails("Example Bakery, 987 654 321.")).toBe(
"Example Bakery, [phone]."
);
expect(withoutContactDetails("Tel. 987 654 321")).toBe("Tel. [phone]");
});
});

describe("withoutContactDetails: whole sentences", () => {
it("takes the contact details out of a site's own sentence and keeps the rest", () => {
expect(
withoutContactDetails(
"Kontakt oss på post@bakeri.example eller ring 12 34 56 78 for bestilling. " +
"Example Bakeri AS, org.nr. 987 654 321, Eksempelgata 12, 0155 Oslo, har bakt brød siden 1987."
)
).toBe(
"Kontakt oss på [email] eller ring [phone] for bestilling. " +
"Example Bakeri AS, org.nr. 987 654 321, Eksempelgata 12, 0155 Oslo, har bakt brød siden 1987."
);
});

it("changes nothing in a text with no contact details, and nothing the second time", () => {
const plain = "Wholesale bakery supplying cafés and hotels in Oslo since 1987.";
expect(withoutContactDetails(plain)).toBe(plain);
expect(withoutContactDetails("")).toBe("");
const once = withoutContactDetails("Call +47 000 00 000 or write to someone@example.com.");
expect(once).toBe("Call [phone] or write to [email].");
expect(withoutContactDetails(once)).toBe(once);
});
});
Loading
Loading