Skip to content

Septum — Custom Recognizer Rules ​

Septum ships 17 regulation packs out of the box. Custom rules let you extend detection without forking the codebase: add a regex, a context-anchored keyword list, or an LLM-prompt rule and it joins the active sanitization pipeline immediately. Rules live under Settings → Regulations → Custom Rules in the dashboard and are stored in the local database.

E-mail addresses are always masked, even if a custom ruleset does not list them. To exempt a specific address through an allow list, use a regex rule when the address may appear glued to other text, because a token rule compares the whole detected value (for example contact=bob@x.com).

This page is a working reference. Each detection method has a worked example plus a copy-paste test recipe.

Detection methods ​

Septum supports three detection methods. Pick the one that matches the shape of the data:

MethodWhen to useCost
regexStructural identifiers with a stable shape (codes, prefixed numbers, formatted IDs).Microseconds
keyword_listA short, finite list of literal strings that should always be redacted (project codenames, internal team names).Microseconds
llm_promptFree-text categories that defy regex (medical conditions, sensitive opinions, slang aliases).~Seconds via local Ollama

Every rule has these common fields:

  • Name — short label that appears in the audit log and detection list.
  • Entity type — e.g. STUDY_PROTOCOL_CODE, STAFF_BADGE. Free-form; the placeholder format becomes [<ENTITY_TYPE>_N].
  • Placeholder label (optional) — overrides the placeholder shown in the masked text (default is the entity type).
  • Active — toggles the rule without deleting it.
  • Sample text — the in-panel test field used by the Test button.

Method 1 — Regex ​

A regex rule scans the document text and emits a span for every match. This is the fastest detection method and the one you should reach for first.

Example: clinical study protocol code ​

A research site tags every study protocol with STUDY-<year>-<5 digit code>, e.g. STUDY-2026-00417. These appear in discharge follow-up letters, trial enrolment forms and invoices.

FieldValue
NameClinical study protocol code
Entity typeSTUDY_PROTOCOL_CODE
Detection methodregex
Pattern\bSTUDY-\d{4}-\d{5}\b
Placeholder labelSTUDY_PROTOCOL_CODE
Sample textEnrolment confirmed for STUDY-2026-00417.

After saving, click Test. The Test button calls POST /api/regulations/custom/{recognizer_id}/test with the sample, and a passing test reports 1 match — STUDY-2026-00417.

Tip — context anchoring Wrap the pattern in \b...\b (word boundaries) and put any keyword in front of the actual ID ((?:Study|STUDY)[-\s:]*(\d{4}-\d{5})). Boundary anchors stop the regex from matching inside larger strings.

Example: staff badge with checksum ​

If your IDs include a checksum, the regex still does the matching but you can add the checksum check via a follow-up keyword rule that filters by context, or write the recognizer in code. Pure-regex rules cannot validate checksums.

Method 2 — Keyword list ​

A keyword rule emits a span for every literal hit. Each keyword is matched as a word-boundary substring; case-insensitive by default.

Example: codename redaction ​

A team uses internal codenames (Project Bluebird, Operation Halcyon, Goldfish Initiative) in design docs. None of them is PII per any regulation, but the company wants them redacted before any cloud LLM call.

FieldValue
NameInternal codenames
Entity typeINTERNAL_CODENAME
Detection methodkeyword_list
KeywordsProject Bluebird, Operation Halcyon, Goldfish Initiative
Placeholder labelINTERNAL_CODENAME
Sample textThe Project Bluebird launch is delayed.

After saving, Test confirms 1 match — Project Bluebird.

Tip — keyword density Keep the list under ~50 entries. Long lists slow ingestion linearly and the entire list is loaded into memory per recognizer. For a sweep across hundreds of terms, generate a regex with alternation instead.

Method 3 — LLM prompt ​

LLM-prompt rules pass the document text, in slices, plus an instruction to a local Ollama model and parse the JSON response into spans. This is the right tool for categories that defy regex — medical conditions, opinions, sensitive cultural markers, informal aliases — at the cost of ~1–5s per slice under llama3.2:3b and proportionally more for larger models.

Example: medication mentions ​

A clinical document set carries free-text mentions of medications (brand names, generic names, dose forms) that no Presidio recognizer covers.

FieldValue
NameMedication mentions
Entity typeMEDICATION
Detection methodllm_prompt
LLM promptFind every medication mention (brand or generic name, with or without dose). Return JSON: [{"text": "<mention>"}].
Placeholder labelMEDICATION
Sample textPatient has been on Coumadin 5 mg daily and ibuprofen as needed.

The Test button sends the prompt and the sample to the local Ollama model and lists the matches the model returns, for example 2 matches — Coumadin 5 mg, ibuprofen. If Ollama cannot be reached, or the model does not return a parseable JSON list, the test shows no matches. The endpoint returns an empty match list in that case and gives no error.

Tip — keep the JSON contract minimal Prompts that ask for many fields (severity, dose, etc.) get less reliable JSON back. The recognizer only needs the matched text; everything else is noise that increases parse failures.

Tip — context window Rules run on the whole document before it is chunked, so chunk_size does not affect them. Septum sends the text to the model one slice at a time: at most 2,000 characters, fewer if the model's context window requires it, with neighbouring slices sharing 200 characters. Phrase the prompt to operate on a "block of text" rather than "the whole document" so the model behaves consistently across slices. A value longer than 200 characters that crosses a slice boundary can still be missed.

Common fields & test loop ​

Every custom rule shares this set of secondary controls:

  • Context words (optional) — regex and keyword rules only. A match is kept only when at least one of these words appears in the match itself or within 100 characters before or after it. Use this to suppress a rule that otherwise produces too many false positives. Example: a rule for 11-digit identifiers can require Patient in context.
    • Matching ignores case and accents and needs whole words: ID is not found inside IDEA, and a word cut off at the window edge does not count. Whitespace runs inside a multi-word context word are ignored, so patient id also matches across a line break.
    • An empty list means the rule fires on every match.
    • A word that starts or ends with punctuation (No:, Tel.) matches as typed at that end; letters and digits at an edge still need a whole-word boundary.
    • The gate applies only to document text (ingestion, reprocessing) and the rule's Test button. Everything else ignores context words, so the rule masks every match: everything a user types (chat questions, text edited or added in the approval step, chunk edits, column labels, ruleset names) and chunks re-masked in chat because their document is outdated.
    • Limits: at most 100 context words, each at most 128 characters.
    • LLM-prompt rules ignore context words and the form hides the field for them; put that context in the prompt instead.
    • Changing the context words marks documents processed under the rule as stale; reprocess them to apply the change.
  • Active — toggles without deleting.
  • Sample text + Test — the inline regression check. Use this for every edit; it persists no data and is a fast way to verify both positive and negative cases.

The test endpoint internally calls the same code path that ingestion uses, so "works in test" implies "works on real documents" assuming the document text looks like the sample.

Audit & debugging ​

Every detection produced by a custom recognizer:

  1. Lands in the document's entity_detections table with the rule's entity_type and placeholder — visible in Document preview → Detected entities.
  2. Surfaces as a row on Settings → Audit Log when ingestion completes, tagged with the rule's name in the extra field.
  3. Goes through the standard absorption + dedup passes — a custom rule does not override built-in regulation detections. Span priority is decided by the same _HIGH_PRIORITY_ENTITY_TYPES table the rest of Septum uses.

If a rule fires in test but not on a real document, open the document preview and check the extracted text — PDF extraction sometimes breaks a target across lines or pages, so it no longer matches the rule. Chunk size and overlap do not change what a rule detects; adjust the rule's pattern or prompt instead.

Changelog · Released under the MIT License.