Swedish PII guard (preview)
A Swedish fine-tune of openai/privacy-filter. It finds personal data in Swedish text so the data can be masked before the text is sent to an LLM, written to a log or passed on by a tool.
Status: a starting point. We release the weights, the training data and the full recipe (the recipe/ folder of this repository) so others can build
better Swedish and Nordic guards. Read Known gaps before you rely on it.
What it masks
11 labels: the base model's 8 plus national_id, id_number and ip_address.
| Label | Examples |
|---|---|
private_person | full names, first or last name alone, initials, genitives ("Annas") |
national_id | personnummer, samordningsnummer |
id_number | passport, ID card, patient/journal numbers |
private_address | home addresses, postcode + town of a person |
private_phone | personal and direct numbers |
private_email | personal and named work addresses |
account_number | bank account, bankgiro/plusgiro of a person, card, IBAN, customer numbers |
private_date | birth dates and dates tied to one person (injury, move-in, employment start) |
private_url | personal profiles and pages |
secret | passwords, API keys, tokens, PINs, one-time codes |
ip_address | IPv4 and IPv6 addresses |
Deliberately not masked:
- organisations, authorities and places;
- org numbers, case and diary numbers;
- switchboards and role mailboxes (info@, registrator@);
- public dates (meetings, deadlines, decisions);
- order and booking references.
An LLM usually needs these, and they don't identify a private person. The full policy is in recipe/POLICY.md.
How to use
The model uses the same runtime as the base model (opf):
from opf._api import OPF
guard = OPF(model="kognitiv-ai/swedish-pii-guard", device="cuda")
res = guard.redact("Hej, jag heter Karin Berg och mitt personnummer är 19121212-1212.")
for s in res.detected_spans:
print(s.label, s.text)
We recommend snapping span edges to word boundaries (recipe/eval/postproc.py).
Training
- Data: 100% synthetic. No real documents or personal data were used.
- Open-weight LLMs (Qwen3.6-35B-A3B, Qwen3.8-27B, DeepSeek-V4.1-Flash, GLM-5.2) wrote about 100k Swedish texts with typed slots instead of values.
- The slots were filled from name and address pools, with valid check digits.
- Programmatic rows cover records, signatures, name-first texts and contrast pairs (e.g. an injury date vs a meeting date).
- Negative slots (organisations, switchboards, public dates) are present but unlabelled.
- Recipe:
opf train, 2 epochs, lr 5e-5, batch 16, about 340k rows. - Final weights: a uniform average ("model soup") of three runs with different data-order seeds. It beat every single run.
Evaluation
All sets are Swedish, word-snapped, and none were used for training.
- GPT test set: about 300 texts per split (business, tool output, chat, news), written and labelled by a GPT model; the reported split was never inspected.
- Webbnyheter and SUCX3: public Swedish NER corpora (CC BY 4.0). Recall is measured on gold persons, and gold organisations and places count as must-not-mask.
| Model | GPT test F1 | Person recall, news (Webbnyheter) | Person recall, SUCX3 | Orgs / places wrongly masked, SUCX3 |
|---|---|---|---|---|
| openai/privacy-filter (base) | 0.70 | 0.56 | 0.41 | |
| OpenMed/privacy-filter-multilingual-v2 † | 0.69 | 0.84 | 0.75 | 30% / 31% |
| emiemimi/privacy-filter-multilingual-500 † | 0.73 | 0.79 | 0.68 | 33% / 46% |
| this model | 0.92 | 0.90 | 0.80 | 23% / 13% |
† Decoded with plain argmax and with labels mapped to ours. Their policies differ (for example, OpenMed masks all dates), so treat these rows as indicative.
By type, on a GPT dev set:
- About 100% recall: personnummer, bank/card/IBAN numbers, phone numbers, e-mail addresses, URLs, addresses, birth dates, IP addresses.
- Secrets, including PINs: about 98%.
- Names: about 91%. Person-tied dates: about 84%. Passport/ID/patient numbers: about 72%.
Known gaps
- Names in running prose are missed about 10–20% of the time, especially short or word-like names (Sol, Ek, Lo) and surnames used alone.
- Organisations and places in news text are still masked too often (13–23%).
- ID document numbers (passport, ID card, patient numbers) are the weakest type (about 72% on our dev set).
- Ambiguous words are sometimes masked: the pronoun "Hans" (his) as a name, or a public date written without a year ("den 1 januari").
- Not a GDPR special-category detector. Health, ethnicity, religion and the like are context, not spans, and are not masked.
- Evaluated on synthetic and news text only. No real business documents were used for testing. Check its output before you rely on it, and test it on your own data first.
Acknowledgement
Thanks to AI Factory Sweden, through AI Göteborg, for pointing us to the EuroHPC AI Factories access programme.
We acknowledge EuroHPC JU for awarding the project ID EHPC-AIF-2026FL01-1143 access to the Arrhenius GPU partition hosted by NAISS at Linköping University, Sweden. All training and evaluation of this model ran on that allocation. Some template-writing calls used hosted APIs (DeepSeek-V4.1-Flash, GLM-5.2).
Licence
Apache 2.0, the same as the base model.