Django ORM
All models for the Guardrail app.
- class smarter.apps.guardrail.models.Guardrail(*args, **kwargs)[source]
Bases:
MetaDataWithOwnershipModelA guardrail: a protection of LLM prompts.
The fields are set by the Guardrail manifest’s
spec.config.configholds the fields of the guardrail’s strategy, with their manifest names, e.g.keywords,detectorsandjudgePrompt.- 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
- category
-
Category
Choices:
piisecretsprompt_injectionjailbreaktoxicityself_harmhallucinationoff_topiccomplianceformattingcustom
- Type:
Type
- config
-
Config. The strategy’s other fields: flags, keywords, detectors, referenceTexts, categories, judgePrompt, etc.
- Type:
Type
- created_at
-
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
-
Description. A brief description of this resource. Be verbose, but not too verbose.
- Type:
Type
- events
Reverse
ForeignKeyfromGuardrailEventAll events of this guardrail (related name of
guardrail)- Type:
Type
- fail_closed
-
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. Seeget_FOO_display()for more information.
- get_category_display(*, field=<django.db.models.CharField: category>)
Shows the label of the
category. Seeget_FOO_display()for more information.
- get_mode_display(*, field=<django.db.models.CharField: mode>)
Shows the label of the
mode. Seeget_FOO_display()for more information.
- get_stage_display(*, field=<django.db.models.CharField: stage>)
Shows the label of the
stage. Seeget_FOO_display()for more information.
- get_strategy_display(*, field=<django.db.models.CharField: strategy>)
Shows the label of the
strategy. Seeget_FOO_display()for more information.
- id
-
Primary key: ID
- Type:
Type
- is_active
-
Is active
- Type:
Type
- llmclient_guardrails
Reverse
ForeignKeyfromLLMClientGuardrailsAll llmclient guardrails of this guardrail (related name of
guardrail)- Type:
Type
- priority
-
Priority. The order in which guardrails run; lower runs first.
- Type:
Type
- severity
-
Severity. 1 (low) to 5 (critical).
- Type:
Type
- strategy
-
Strategy
Choices:
regexkeyworddetectorsemanticmoderationllm_judge
- Type:
Type
- tagged_items
Reverse
GenericRelationfromGuardrailAll + of this tagged item (related name of
tagged_items)- Type:
Type
- tags = <taggit.managers._TaggableManager object>
- threshold
-
Threshold. The minimum confidence at which the semantic, moderation and llm_judge strategies trigger.
- Type:
Type
- updated_at
-
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
-
User profile (related name:
guardrail)- Type:
Type
- user_profile_id
Internal field, use
user_profileinstead.
- class smarter.apps.guardrail.models.GuardrailAction(*values)[source]
Bases:
TextChoicesWhat 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:
TextChoicesThe 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:
TextChoicesWhat 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:
TimestampedModelA 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,
excerptis 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
- category
-
Category
Choices:
piisecretsprompt_injectionjailbreaktoxicityself_harmhallucinationoff_topiccomplianceformattingcustom
- Type:
Type
- confidence
-
Confidence
- Type:
Type
- created_at
-
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
-
Disposition
Choices:
loggedflaggedredactedtransformedblockedescalatedmonitorederror
- Type:
Type
- get_action_display(*, field=<django.db.models.CharField: action>)
Shows the label of the
action. Seeget_FOO_display()for more information.
- get_category_display(*, field=<django.db.models.CharField: category>)
Shows the label of the
category. Seeget_FOO_display()for more information.
- get_disposition_display(*, field=<django.db.models.CharField: disposition>)
Shows the label of the
disposition. Seeget_FOO_display()for more information.
- get_mode_display(*, field=<django.db.models.CharField: mode>)
Shows the label of the
mode. Seeget_FOO_display()for more information.
- get_stage_display(*, field=<django.db.models.CharField: stage>)
Shows the label of the
stage. Seeget_FOO_display()for more information.
- get_strategy_display(*, field=<django.db.models.CharField: strategy>)
Shows the label of the
strategy. Seeget_FOO_display()for more information.
- guardrail
-
Guardrail (related name:
events)- Type:
Type
- id
-
Primary key: ID
- Type:
Type
- llmclient
-
Llmclient (related name:
guardrail_events)- Type:
Type
- objects = <django.db.models.Manager object>
- reviewed
-
Reviewed
- Type:
Type
- severity
-
Severity
- Type:
Type
- strategy
-
Strategy
Choices:
regexkeyworddetectorsemanticmoderationllm_judge
- Type:
Type
- updated_at
-
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:
TextChoicesWhether a guardrail acts, or only records what it would do.
- ENFORCE = 'enforce'
- MONITOR = 'monitor'