Signal Receivers

Django Signal Receivers for guardrail.

Note

Experimental. The Guardrail was designed and coded by Claude Code (Anthropic’s Claude Opus 5.5), with Lawrence McDaniel as co-author. It is experimental, and will be documented.

smarter.apps.guardrail.receivers.guardrail_deleted(sender, instance, **kwargs)[source]

Log a Guardrail that is about to be deleted.

Parameters:
  • sender – The model class, Guardrail.

  • instance (Guardrail) – The Guardrail being deleted.

  • kwargs – The other pre_delete arguments.

smarter.apps.guardrail.receivers.guardrail_saved(sender, instance, created, **kwargs)[source]

Log a created or updated Guardrail, with its name and id.

Its serialized fields are not logged: they include the owner’s user profile, whose email address is personal data.

Parameters:
  • sender – The model class, Guardrail.

  • instance (Guardrail) – The saved Guardrail.

  • created (bool) – True if the Guardrail was created, False if it was updated.

  • kwargs – The other post_save arguments.

smarter.apps.guardrail.receivers.handle_guardrail_blocked(sender, guardrail, stage, message, **kwargs)[source]

Log a blocked message or reply.

Parameters:
  • sender – The object that sent the signal.

  • guardrail (Guardrail) – The Guardrail that blocked it.

  • stage (str) – The stage it ran at, e.g. input or output.

  • message (str) – The message shown to the user in place of the blocked content.

  • kwargs – The other signal arguments.

smarter.apps.guardrail.receivers.handle_guardrail_escalated(sender, guardrail, stage, event=None, **kwargs)[source]

Log an escalation to human review.

Its event awaits review in the Smarter admin.

smarter.apps.guardrail.receivers.handle_guardrail_failed(sender, guardrail, stage, error, fail_closed, **kwargs)[source]

Log a guardrail that failed to run.

Parameters:
  • sender – The object that sent the signal.

  • guardrail (Guardrail) – The Guardrail that failed.

  • stage (str) – The stage it ran at.

  • error (str) – The error message.

  • fail_closed (bool) – True if the failure blocked the content, False if it was let through.

  • kwargs – The other signal arguments.

smarter.apps.guardrail.receivers.handle_guardrail_triggered(sender, guardrail, stage, disposition, **kwargs)[source]

Log a triggered guardrail.

What it matched is not logged, because it may be personal data.