Skip to content

PIIDetection / PIIDetectionResult

llmfy.guardrails.pii.pii_result

PIIDetection

Bases: BaseModel

A single PII finding within a text.

Attributes:

Name Type Description
id str

Unique identifier for this detection.

pii_type Union[PIIType, str]

The category of PII detected.

value str

The original PII string found in the text.

start int

Start character index (inclusive) in the original text.

end int

End character index (exclusive) in the original text.

placeholder str

The string used to replace this PII in processed_text.

Source code in llmfy/guardrails/pii/pii_result.py
class PIIDetection(BaseModel):
    """A single PII finding within a text.

    Attributes:
        id: Unique identifier for this detection.
        pii_type: The category of PII detected.
        value: The original PII string found in the text.
        start: Start character index (inclusive) in the original text.
        end: End character index (exclusive) in the original text.
        placeholder: The string used to replace this PII in processed_text.
    """

    model_config = ConfigDict(extra="forbid")

    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    pii_type: Union[PIIType, str]
    value: str
    start: int
    end: int
    placeholder: str

model_config = ConfigDict(extra='forbid') class-attribute instance-attribute

id = Field(default_factory=(lambda: str(uuid.uuid4()))) class-attribute instance-attribute

pii_type instance-attribute

value instance-attribute

start instance-attribute

end instance-attribute

placeholder instance-attribute

PIIDetectionResult

Bases: BaseModel

Overall result from a PII detection pass.

Attributes:

Name Type Description
id str

Unique identifier for this result.

original_text str

The input text, unchanged.

processed_text str

The text with all detected PII replaced.

detections List[PIIDetection]

List of individual PII findings.

has_pii bool

True when at least one detection exists (computed).

strategy PIIStrategy

The PIIStrategy applied during processing.

Source code in llmfy/guardrails/pii/pii_result.py
class PIIDetectionResult(BaseModel):
    """Overall result from a PII detection pass.

    Attributes:
        id: Unique identifier for this result.
        original_text: The input text, unchanged.
        processed_text: The text with all detected PII replaced.
        detections: List of individual PII findings.
        has_pii: True when at least one detection exists (computed).
        strategy: The PIIStrategy applied during processing.
    """

    model_config = ConfigDict(extra="forbid")

    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    original_text: str
    processed_text: str
    detections: List[PIIDetection] = Field(default_factory=list)
    has_pii: bool = False
    strategy: PIIStrategy

    @model_validator(mode="after")
    def _compute_has_pii(self) -> "PIIDetectionResult":
        self.has_pii = len(self.detections) > 0
        return self

model_config = ConfigDict(extra='forbid') class-attribute instance-attribute

id = Field(default_factory=(lambda: str(uuid.uuid4()))) class-attribute instance-attribute

original_text instance-attribute

processed_text instance-attribute

detections = Field(default_factory=list) class-attribute instance-attribute

has_pii = False class-attribute instance-attribute

strategy instance-attribute