Actions

Apply a triggered guardrail’s action to the payload.

Each action returns an ActionOutcome: the payload, possibly changed; the pipeline disposition; the disposition to record in the GuardrailEvent; and, for block, the user-facing message.

A guardrail in monitor mode never changes the payload nor the disposition. Its event records monitored, i.e. what it would have done.

class smarter.apps.guardrail.services.actions.ActionOutcome(payload, disposition, event_disposition, message=None, halt_pipeline=False)[source]

Bases: object

The result of applying one guardrail’s action to one finding.

Variables:
  • payload – The payload, changed by redact and transform.

  • disposition – The pipeline disposition this action resolves to.

  • event_disposition – What to record in the guardrail’s event.

  • message – The user-facing message, for block.

  • halt_pipeline – True for block: no further guardrails run.

__init__(payload, disposition, event_disposition, message=None, halt_pipeline=False)
disposition: PipelineDisposition
event_disposition: str
halt_pipeline: bool = False
message: str | None = None
payload: dict[str, Any]
smarter.apps.guardrail.services.actions.apply_action(*, payload, finding, guardrail)[source]

Apply the guardrail’s action to the payload, for a triggered finding.

Parameters:
  • payload (dict[str, Any]) – The payload, as changed by the guardrails that ran before this one.

  • finding (GuardrailFinding) – The triggered finding.

  • guardrail (Guardrail) – The guardrail.

Return type:

ActionOutcome

Returns:

The outcome.

smarter.apps.guardrail.services.actions.replace_matches(text, matches, replacement)[source]

Replace each match in text, from the last to the first, so that the positions of the.

earlier matches remain valid. {label} in the replacement is the match’s label.

Return type:

str