Events

Record GuardrailEvent rows: the audit trail of guardrails.

For the pii and secrets categories, the excerpt is masked, so that the event does not store the personal data or secret that the guardrail detected: personal data keeps its last four characters, and secrets only their length.

smarter.apps.guardrail.services.events.excerpt(finding, segment_text)[source]

Return the excerpt of a finding, for its event: its matches, or the segment, masked for.

the pii and secrets categories.

Return type:

Optional[str]

smarter.apps.guardrail.services.events.mask(text, category)[source]

Mask a match, for an event’s excerpt.

Parameters:
  • text (str) – The matched text.

  • category (str) – The guardrail’s category.

Return type:

str

Returns:

For secrets, only the length; for personal data, the last four characters; otherwise the text.

smarter.apps.guardrail.services.events.record_event(*, guardrail, stage, disposition, finding=None, segment_text=None, error=None, llmclient=None, session_key=None)[source]

Record a guardrail event.

A failure to record is logged, and does not fail the prompt.

Return type:

Optional[GuardrailEvent]

Returns:

The event, or None if it could not be recorded.

smarter.apps.guardrail.services.events.stage_name(stage)[source]

Return the Guardrail stage of a pipeline stage: input or output.

Return type:

str