Skip to content

latent.guardrails.events

Classes

GuardrailEvent

GuardrailEvent(event_type: Literal['scan_result', 'blocked', 'violation', 'error'], rule_name: str, mode: Mode, timestamp_utc: str = (lambda: datetime.now(UTC).isoformat())(), trace_id: str | None = None, session_id: str | None = None, score: float | None = None, passed: bool | None = None, input_text: str | None = None, output_text: str | None = None, latency_ms: float | None = None, metadata: dict[str, Any] = dict())

Structured event emitted to sinks on every scan decision.

GuardrailViolation

GuardrailViolation(rule_name: str = '', timing: Timing = 'post', outcome: Outcome = 'passive', score: float = 0.0, input_text: str = '', output_text: str | None = None, message: str = '', retraction: bool = False, scrub_history: bool = False)

Yielded from stream when a guardrail fires.

For outcome="active": - timing="pre": stream never started, message is the response. scrub_history=True — app should remove bad input from history. - timing="post": content already streamed, retraction=True — frontend should replace visible content with message. scrub_history=True — app should remove response from history.

For outcome="passive": informational only, no blocking.

Methods

GuardrailEvent.to_dict

to_dict() -> dict[str, Any]

GuardrailEvent.to_json

to_json() -> str