DetectorRegistry#

class scikitplot.cleanprompt.DetectorRegistry(detectors=None)[source]#

An ordered, immutable-by-convention collection of detectors.

Parameters:
detectorsiterable of Detector, optional

Initial detectors.

Raises:
PolicyError

If two detectors share a name.

Parameters:

detectors (Iterable[Detector] | None)

Notes

Developer notes. add returns self for chaining but mutates, so a registry is a builder, not a value. The engine never mutates one; it reads the registry once per pass. Names must be unique because arbitration uses the detector name as its final, deterministic tie-break — two detectors sharing a name would make the outcome depend on insertion order.

add(detector)[source]#

Append a detector.

Parameters:
detectorDetector

The detector to add.

Returns:
DetectorRegistry

This registry, for chaining.

Raises:
PolicyError

If a detector of the same name is already registered.

Parameters:

detector (Detector)

Return type:

DetectorRegistry

detect_all(text, policy, detectors=None)[source]#

Run detectors and collect every span.

Parameters:
textstr

The original text.

policyRedactionPolicy

The active policy; supplies Limits.max_spans and RedactionPolicy.min_confidence.

detectorssequence of Detector, optional

Override the registry’s own detectors.

Returns:
list of Span

Unresolved spans, which may overlap.

Raises:
DetectorError

If a detector raises. The detector name is carried on the error.

LimitExceededError

If more than Limits.max_spans spans are produced.

Parameters:
Return type:

list[Span]

Notes

Developer notes. The span cap is checked while collecting, not afterwards, so a pathological detector cannot exhaust memory before the bound is noticed.

kinds()[source]#

Return every kind this registry can produce.

Returns:
tuple of str

Sorted, deduplicated kinds.

Return type:

tuple[str, …]

select(kinds)[source]#

Return the detectors whose kind is in kinds.

Parameters:
kindsiterable of str

Kinds to keep.

Returns:
tuple of Detector

In registration order.

Parameters:

kinds (Iterable[str])

Return type:

tuple[Detector, …]