Django ORM

All models for the Guardrail app.

class smarter.apps.guardrail.models.Guardrail(*args, **kwargs)[source]

Bases: MetaDataWithOwnershipModel

A guardrail: a protection of LLM prompts.

The fields are set by the Guardrail manifest’s spec.config. config holds the fields of the guardrail’s strategy, with their manifest names, e.g. keywords, detectors and judgePrompt.

Parameters:
  • id (Unknown) – Primary key: ID

  • created_at (Unknown) – Created at

  • updated_at (Unknown) – Updated at

  • name (Unknown) – Name. Name in camelCase, e.g., ‘apiKey’, no special characters.

  • description (Unknown) – Description. A brief description of this resource. Be verbose, but not too verbose.

  • version (Unknown) – Version. Semantic version in the format MAJOR.MINOR.PATCH, e.g., ‘1.0.0’.

  • annotations (Unknown) – Annotations. Key-value pairs for annotating this resource.

  • stage (Unknown) – Stage

  • category (Unknown) – Category

  • strategy (Unknown) – Strategy

  • pattern (Unknown) – Pattern. The regex strategy’s regular expression.

  • config (Unknown) – Config. The strategy’s other fields: flags, keywords, detectors, referenceTexts, categories, judgePrompt, etc.

  • threshold (Unknown) – Threshold. The minimum confidence at which the semantic, moderation and llm_judge strategies trigger.

  • action (Unknown) – Action

  • replacement (Unknown) – Replacement. What redact and transform replace each match with.

  • message (Unknown) – Message. What block returns to the user.

  • severity (Unknown) – Severity. 1 (low) to 5 (critical).

  • mode (Unknown) – Mode

  • fail_closed (Unknown) – Fail closed. Block if the check itself fails, e.g. because the LLM provider is unavailable.

  • priority (Unknown) – Priority. The order in which guardrails run; lower runs first.

  • is_active (Unknown) – Is active

Relationship fields:

Parameters:
  • user_profile (Unknown) – User profile (related name: guardrail)

  • tags (Unknown) – Tags. Tags for categorizing and organizing this resource. (related name: guardrail)

  • tagged_items (Unknown) – Tagged items (related name: +)

Reverse relationships:

Parameters:
  • events (Unknown) – All events of this guardrail (related name of guardrail)

  • llmclient_guardrails (Unknown) – All llmclient guardrails of this guardrail (related name of guardrail)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

action

CharField

Action

Choices:

  • log

  • flag

  • redact

  • transform

  • block

  • escalate

Type:

Type

annotations

JSONField

Annotations. Key-value pairs for annotating this resource.

Type:

Type

category

CharField

Category

Choices:

  • pii

  • secrets

  • prompt_injection

  • jailbreak

  • toxicity

  • self_harm

  • hallucination

  • off_topic

  • compliance

  • formatting

  • custom

Type:

Type

config

JSONField

Config. The strategy’s other fields: flags, keywords, detectors, referenceTexts, categories, judgePrompt, etc.

Type:

Type

created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created.

This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

description

TextField

Description. A brief description of this resource. Be verbose, but not too verbose.

Type:

Type

property effective_message: str

What block returns to the user.

property effective_replacement: str

What redact and transform replace each match with.

events

Reverse ForeignKey from GuardrailEvent

All events of this guardrail (related name of guardrail)

Type:

Type

fail_closed

BooleanField

Fail closed. Block if the check itself fails, e.g. because the LLM provider is unavailable.

Type:

Type

get_action_display(*, field=<django.db.models.CharField: action>)

Shows the label of the action. See get_FOO_display() for more information.

get_category_display(*, field=<django.db.models.CharField: category>)

Shows the label of the category. See get_FOO_display() for more information.

get_mode_display(*, field=<django.db.models.CharField: mode>)

Shows the label of the mode. See get_FOO_display() for more information.

get_stage_display(*, field=<django.db.models.CharField: stage>)

Shows the label of the stage. See get_FOO_display() for more information.

get_strategy_display(*, field=<django.db.models.CharField: strategy>)

Shows the label of the strategy. See get_FOO_display() for more information.

id

BigAutoField

Primary key: ID

Type:

Type

is_active

BooleanField

Is active

Type:

Type

llmclient_guardrails

Reverse ForeignKey from LLMClientGuardrails

All llmclient guardrails of this guardrail (related name of guardrail)

Type:

Type

message

TextField

Message. What block returns to the user.

Type:

Type

mode

CharField

Mode

Choices:

  • enforce

  • monitor

Type:

Type

name

CharField

Name. Name in camelCase, e.g., ‘apiKey’, no special characters.

Type:

Type

pattern

TextField

Pattern. The regex strategy’s regular expression.

Type:

Type

priority

PositiveSmallIntegerField

Priority. The order in which guardrails run; lower runs first.

Type:

Type

replacement

TextField

Replacement. What redact and transform replace each match with.

Type:

Type

runs_on(stage)[source]

Return whether the guardrail runs on stage, input or output.

Return type:

bool

property settings: dict[str, Any]

The strategy’s fields, from config.

severity

PositiveSmallIntegerField

Severity. 1 (low) to 5 (critical).

Type:

Type

stage

CharField

Stage

Choices:

  • input

  • output

  • both

Type:

Type

strategy

CharField

Strategy

Choices:

  • regex

  • keyword

  • detector

  • semantic

  • moderation

  • llm_judge

Type:

Type

tagged_items

Reverse GenericRelation from Guardrail

All + of this tagged item (related name of tagged_items)

Type:

Type

tags = <taggit.managers._TaggableManager object>
threshold

FloatField

Threshold. The minimum confidence at which the semantic, moderation and llm_judge strategies trigger.

Type:

Type

updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated.

This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type

user_profile

ForeignKey to UserProfile

User profile (related name: guardrail)

Type:

Type

user_profile_id

Internal field, use user_profile instead.

version

CharField

Version. Semantic version in the format MAJOR.MINOR.PATCH, e.g., ‘1.0.0’.

Type:

Type

class smarter.apps.guardrail.models.GuardrailAction(*values)[source]

Bases: TextChoices

What a guardrail does when it triggers.

BLOCK = 'block'
ESCALATE = 'escalate'
FLAG = 'flag'
LOG = 'log'
REDACT = 'redact'
TRANSFORM = 'transform'
class smarter.apps.guardrail.models.GuardrailCategory(*values)[source]

Bases: TextChoices

The risk that a guardrail addresses.

COMPLIANCE = 'compliance'
CUSTOM = 'custom'
FORMATTING = 'formatting'
HALLUCINATION = 'hallucination'
JAILBREAK = 'jailbreak'
OFF_TOPIC = 'off_topic'
PII = 'pii'
PROMPT_INJECTION = 'prompt_injection'
SECRETS = 'secrets'
SELF_HARM = 'self_harm'
TOXICITY = 'toxicity'
class smarter.apps.guardrail.models.GuardrailDisposition(*values)[source]

Bases: TextChoices

What a guardrail did, as recorded in a GuardrailEvent.

BLOCKED = 'blocked'
ERROR = 'error'
ESCALATED = 'escalated'
FLAGGED = 'flagged'
LOGGED = 'logged'
MONITORED = 'monitored'
REDACTED = 'redacted'
TRANSFORMED = 'transformed'
class smarter.apps.guardrail.models.GuardrailEvent(*args, **kwargs)[source]

Bases: TimestampedModel

A guardrail that triggered, or failed to run, on a prompt.

Events are the audit trail of guardrails: flagged and escalated events await review in the Smarter admin. For the pii and secrets categories, excerpt is masked, so that the event does not store the personal data or secret that the guardrail detected.

Parameters:
  • id (Unknown) – Primary key: ID

  • created_at (Unknown) – Created at

  • updated_at (Unknown) – Updated at

  • guardrail_name (Unknown) – Guardrail name. The guardrail’s name, in case it is deleted.

  • session_key (Unknown) – Session key. The prompt’s session key.

  • stage (Unknown) – Stage

  • category (Unknown) – Category

  • strategy (Unknown) – Strategy

  • action (Unknown) – Action

  • mode (Unknown) – Mode

  • disposition (Unknown) – Disposition

  • severity (Unknown) – Severity

  • confidence (Unknown) – Confidence

  • excerpt (Unknown) – Excerpt. What triggered the guardrail, masked for pii and secrets.

  • rationale (Unknown) – Rationale

  • error (Unknown) – Error. Why the guardrail failed to run, if it did.

  • reviewed (Unknown) – Reviewed

Relationship fields:

Parameters:
  • guardrail (Unknown) – Guardrail (related name: events)

  • llmclient (Unknown) – Llmclient (related name: guardrail_events)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

action

CharField

Action

Choices:

  • log

  • flag

  • redact

  • transform

  • block

  • escalate

Type:

Type

category

CharField

Category

Choices:

  • pii

  • secrets

  • prompt_injection

  • jailbreak

  • toxicity

  • self_harm

  • hallucination

  • off_topic

  • compliance

  • formatting

  • custom

Type:

Type

confidence

FloatField

Confidence

Type:

Type

created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created.

This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

disposition

CharField

Disposition

Choices:

  • logged

  • flagged

  • redacted

  • transformed

  • blocked

  • escalated

  • monitored

  • error

Type:

Type

error

TextField

Error. Why the guardrail failed to run, if it did.

Type:

Type

excerpt

TextField

Excerpt. What triggered the guardrail, masked for pii and secrets.

Type:

Type

get_action_display(*, field=<django.db.models.CharField: action>)

Shows the label of the action. See get_FOO_display() for more information.

get_category_display(*, field=<django.db.models.CharField: category>)

Shows the label of the category. See get_FOO_display() for more information.

get_disposition_display(*, field=<django.db.models.CharField: disposition>)

Shows the label of the disposition. See get_FOO_display() for more information.

get_mode_display(*, field=<django.db.models.CharField: mode>)

Shows the label of the mode. See get_FOO_display() for more information.

get_stage_display(*, field=<django.db.models.CharField: stage>)

Shows the label of the stage. See get_FOO_display() for more information.

get_strategy_display(*, field=<django.db.models.CharField: strategy>)

Shows the label of the strategy. See get_FOO_display() for more information.

guardrail

ForeignKey to Guardrail

Guardrail (related name: events)

Type:

Type

guardrail_id

Internal field, use guardrail instead.

guardrail_name

CharField

Guardrail name. The guardrail’s name, in case it is deleted.

Type:

Type

id

BigAutoField

Primary key: ID

Type:

Type

llmclient

ForeignKey to LLMClient

Llmclient (related name: guardrail_events)

Type:

Type

llmclient_id

Internal field, use llmclient instead.

mode

CharField

Mode

Choices:

  • enforce

  • monitor

Type:

Type

objects = <django.db.models.Manager object>
rationale

TextField

Rationale

Type:

Type

reviewed

BooleanField

Reviewed

Type:

Type

session_key

CharField

Session key. The prompt’s session key.

Type:

Type

severity

PositiveSmallIntegerField

Severity

Type:

Type

stage

CharField

Stage

Choices:

  • input

  • output

  • both

Type:

Type

strategy

CharField

Strategy

Choices:

  • regex

  • keyword

  • detector

  • semantic

  • moderation

  • llm_judge

Type:

Type

updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated.

This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type

class smarter.apps.guardrail.models.GuardrailMode(*values)[source]

Bases: TextChoices

Whether a guardrail acts, or only records what it would do.

ENFORCE = 'enforce'
MONITOR = 'monitor'
class smarter.apps.guardrail.models.GuardrailStage(*values)[source]

Bases: TextChoices

When a guardrail runs.

BOTH = 'both'
INPUT = 'input'
OUTPUT = 'output'
class smarter.apps.guardrail.models.GuardrailStrategy(*values)[source]

Bases: TextChoices

How a guardrail detects what it guards against.

DETECTOR = 'detector'
KEYWORD = 'keyword'
LLM_JUDGE = 'llm_judge'
MODERATION = 'moderation'
REGEX = 'regex'
SEMANTIC = 'semantic'