Skip to content

factflow-hygiene

Content sanitization adapters that run upstream of LLM and synthesis stages: deterministic PII redaction, LLM-based sensitivity classification, an LLM-based broken-access-control gate, and label-driven redaction. Built to hold one invariant — no Norwegian PII reaches a model — and to keep strictly-confidential and access-control-violating content out of synthesis.

Adapters are consumed by type name in pipeline YAML (auto-discovered and registered), not imported. The package exposes no flat public API; each adapter lives in its own module.

TypeClassKindinjectable deps
pii_redactorPIIRedactorAdapter (pii/adapter.py)deterministic
sensitivity_classifierSensitivityClassifierAdapter (sensitivity/classifier.py)LLM-basedstorage, llm_factory, db_pool
anti_bac_gateAntiBacGateAdapter (anti_bac/detector.py)LLM-basedllm_factory, db_pool
sc_redactorSCRedactorAdapter (sensitivity/sc_redactor.py)deterministicdb_pool

They run as a fixed chain — pii_redactor → sensitivity_classifier → anti_bac_gate → sc_redactor — ahead of knowledge_diff. See the Hygiene workflow for the ordering rationale and the residency invariant.

  • pii_redactor — regex/pattern detection (Norwegian national IDs, IBANs, …) in two passes, then redaction. Reproducible: same input, same output.
  • sensitivity_classifier — reads data["sensitivity"]; if empty, classifies the redacted body via the llm_factory (llm_profile), writes the label into both the in-flight data and the storage sidecar, and persists a pipeline_sensitivity_findings row keyed by content hash for cross-run cache reuse.
  • anti_bac_gate — assesses the content for org-wide-invariant (broken-access-control) violations via the llm_factory; on a violation, replaces the body in place with [REDACTED:BROKEN_ACCESS_CONTROL] and persists a pipeline_anti_bac_findings row keyed by content hash + model profile.
  • sc_redactor — when the resolved label is STRICTLY_CONFIDENTIAL, replaces the document body with a placeholder so SC content never reaches synthesis; the label itself survives, so SC sources travel on as labelled-but-bodyless markers.
  • Workspace: factflow-protocols, factflow-foundation, factflow-engine; the sensitivity_classifier and anti_bac_gate also use factflow-llm.
  • External services: an LLM provider (sensitivity and anti-BAC assessment) and PostgreSQL (the content-hash caches and findings tables).

Tests at backend/packages/workflows/factflow-hygiene/tests/. Config-wiring tests assert the adapters register and run in order before knowledge_diff; the classifier is tested with mocked LLM clients — see .claude/skills/backend/llm-unit-testing/.