pii

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeOff       = "off"
	ModeCustomers = "customers"
	ModeAll       = "all"
)
View Source
const RedactTextNotice = `[redacted — run "hs pii-model install" for content]`

RedactTextNotice is shown for freeform text when NER is not installed.

Variables

This section is empty.

Functions

func EffectiveMode

func EffectiveMode(mode string, allowUnredacted bool, unredacted bool) (string, error)

EffectiveMode applies per-request override policy.

func IsEnabled

func IsEnabled(mode string) bool

func IsValidMode

func IsValidMode(v string) bool

func NormalizeMode

func NormalizeMode(v string) string

NormalizeMode normalizes configured mode values.

func ShouldRedactType

func ShouldRedactType(mode, entityType string) bool

ShouldRedactType decides whether an entity type should be redacted for mode. entityType is expected to be "customer" or "user". Unknown types are only redacted in "all" mode.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(mode, secret string, opts ...EngineOption) *Engine

func (*Engine) Enabled

func (e *Engine) Enabled() bool

func (*Engine) Mode

func (e *Engine) Mode() string

func (*Engine) RedactEmail

func (e *Engine) RedactEmail(email string) string

func (*Engine) RedactJSON

func (e *Engine) RedactJSON(data json.RawMessage) (json.RawMessage, error)

func (*Engine) RedactPerson

func (e *Engine) RedactPerson(first, last, email string) (string, string, string)

func (*Engine) RedactPhone

func (e *Engine) RedactPhone(phone string) string

func (*Engine) RedactText

func (e *Engine) RedactText(text string, known []KnownIdentity) string

RedactText redacts free-form text using known identities followed by regex sweeps. When NER is available, names are detected via ML. Without NER, freeform text is hidden entirely (structured field redaction still works).

In mode-restricted operation (e.g. "customers"), only identities whose Type matches the mode are redacted; other known identities are "protected" so neither redactKnown nor NER replaces them.

func (*Engine) ShouldRedactType

func (e *Engine) ShouldRedactType(entityType string) bool

type EngineOption added in v0.2.0

type EngineOption func(*Engine)

EngineOption configures optional Engine behaviour.

func WithNER added in v0.2.0

func WithNER(d NameDetector) EngineOption

WithNER attaches a name detector for freeform text redaction.

type KnownIdentity

type KnownIdentity struct {
	Type  string
	First string
	Last  string
	Email string
	Phone string
}

type NameDetector added in v0.2.0

type NameDetector interface {
	DetectNames(text string) ([]NameSpan, error)
}

NameDetector detects person names in free-form text.

type NameSpan added in v0.2.0

type NameSpan struct {
	Text  string
	Start int
	End   int
	Score float32
}

NameSpan represents a detected name in text.

Directories

Path Synopsis
Package ner provides ML-based named entity recognition for PII redaction.
Package ner provides ML-based named entity recognition for PII redaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL