Pydantic Models
Smarter API Guardrail Manifest Constants.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_EMBEDDING_MODEL = 'text-embedding-3-small'
Default model of the semantic strategy.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_JUDGE_MODEL = 'gpt-6-luna'
Default model of the llm_judge strategy.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_MESSAGE = 'This request was blocked by a guardrail.'
Default user-facing message of a block action.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_MODERATION_MODEL = 'omni-moderation-latest'
Default model of the moderation strategy.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_PRIORITY = 100
Default evaluation order of a Guardrail.
Lower runs first.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_PROVIDER = 'openai'
Default LLM provider of the semantic, moderation and llm_judge strategies.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_REPLACEMENT = '[REDACTED]'
Default text that replaces the matches of a redact action.
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_SEVERITY = 3
Default severity of a Guardrail, from 1 (low) to 5 (critical).
- smarter.apps.guardrail.manifest.models.guardrail.const.DEFAULT_THRESHOLD = 0.8
Default confidence threshold of the scored strategies.
Smarter API Manifest - Guardrail.metadata.
- class smarter.apps.guardrail.manifest.models.guardrail.metadata.SAMGuardrailMetadata(*, name, description, version, tags=<factory>, annotations=<factory>)[source]
Bases:
AbstractSAMMetadataBaseSmarter API Guardrail Manifest - Metadata class.
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
Smarter API Manifest - Guardrail.spec.
A Guardrail protects the prompts of the LLMClients that list it in their spec.guardrails.
It checks the user’s message before it is sent to the LLM (stage: input), and/or the
LLM’s reply before it is returned to the user (stage: output), with one detection
strategy, and takes an action when it triggers.
spec:
config:
stage: input # input, output or both
category: pii # the risk it addresses, for reporting
strategy: detector # regex, keyword, detector, semantic, moderation or llm_judge
detectors: # the detector strategy's built-in detectors
- credit_card
- us_ssn
action: redact # log, flag, redact, transform, block or escalate
replacement: "[REDACTED]" # what redact and transform replace matches with
message: null # what block returns to the user
severity: 4 # 1 (low) to 5 (critical)
mode: enforce # enforce, or monitor to only record what it would do
failClosed: false # block if the check itself fails, e.g. an LLM provider error
priority: 10 # lower runs first
isActive: true
Each strategy has its own fields:
regex:pattern, and optionalflags.keyword:keywords, and optionalcaseSensitiveandwholeWord.detector:detectors.semantic:referenceTexts, and optionalthreshold,modelandprovider.moderation: optionalcategories,threshold,modelandprovider.llm_judge:judgePrompt, with a{text}placeholder, and optionalthreshold,modelandprovider.
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.manifest.models.guardrail.spec.REGEX_FLAGS = ('IGNORECASE', 'MULTILINE', 'DOTALL')
The regex flags that
flagsmay contain.('IGNORECASE', 'MULTILINE', 'DOTALL')
- class smarter.apps.guardrail.manifest.models.guardrail.spec.SAMGuardrailSpec(*, config)[source]
Bases:
AbstractSAMSpecBaseSmarter API Guardrail Manifest Guardrail.spec.
- config: SAMGuardrailSpecConfig
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- class smarter.apps.guardrail.manifest.models.guardrail.spec.SAMGuardrailSpecConfig(*, stage, category='custom', strategy, pattern=None, flags=<factory>, keywords=<factory>, caseSensitive=False, wholeWord=True, detectors=<factory>, referenceTexts=<factory>, categories=<factory>, judgePrompt=None, threshold=None, model=None, provider=None, action, replacement=None, message=None, severity=3, mode='enforce', failClosed=False, priority=100, isActive=True)[source]
Bases:
AbstractSAMSpecBaseSmarter API Guardrail Manifest Guardrail.spec.config.
- category: Literal['pii', 'secrets', 'prompt_injection', 'jailbreak', 'toxicity', 'self_harm', 'hallucination', 'off_topic', 'compliance', 'formatting', 'custom']
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- classmethod validate_action(v)[source]
Lower case
actionand check that it is one ofSAMGuardrailAction’s values.- Parameters:
v (
str) – The raw value.- Return type:
- Returns:
The lower cased value.
- Raises:
SAMValidationError – when it is not a valid action.
- validate_action_fields()[source]
Validate that the action is possible with the strategy.
- Return type:
- classmethod validate_categories(v)[source]
Lower case each of
categoriesand check that it is aSAMGuardrailModerationCategoryvalue.
- classmethod validate_category(v)[source]
Lower case
categoryand check that it is one ofSAMGuardrailCategory’s values.- Parameters:
v (
str) – The raw value.- Return type:
- Returns:
The lower cased value.
- Raises:
SAMValidationError – when it is not a valid category.
- classmethod validate_detectors(v)[source]
Lower case each of
detectorsand check that it is aSAMGuardrailDetectorvalue.
- classmethod validate_flags(v)[source]
Upper case the regex
flagsand check that each is inREGEX_FLAGS.
- classmethod validate_message(v)[source]
Check the length of
message, and turn an empty message into None.- Parameters:
v (
str|None) – The message shown when the guardrail blocks, or None.- Return type:
- Returns:
The message, or None when it is empty.
- Raises:
SAMValidationError – when it is longer than
MAX_MESSAGE_LENGTH.
- classmethod validate_mode(v)[source]
Lower case
modeand check that it is one ofSAMGuardrailMode’s values.- Parameters:
v (
str) – The raw value.- Return type:
- Returns:
The lower cased value.
- Raises:
SAMValidationError – when it is not a valid mode.
- classmethod validate_stage(v)[source]
Lower case
stageand check that it is one ofSAMGuardrailStage’s values.- Parameters:
v (
str) – The raw value.- Return type:
- Returns:
The lower cased value.
- Raises:
SAMValidationError – when it is not a valid stage.
- classmethod validate_strategy(v)[source]
Lower case
strategyand check that it is one ofSAMGuardrailStrategy’s values.- Parameters:
v (
str) – The raw value.- Return type:
- Returns:
The lower cased value.
- Raises:
SAMValidationError – when it is not a valid strategy.
- smarter.apps.guardrail.manifest.models.guardrail.spec.choice(value, choices, field)[source]
Return a lower cased value, if it is one of
choices.- Parameters:
- Return type:
- Returns:
The value, stripped and lower cased.
- Raises:
SAMValidationError – when the value is not one of
choices.
- smarter.apps.guardrail.manifest.models.guardrail.spec.compile_flags(flags)[source]
Return the combined
reflags for a list of flag names.- Return type:
Smarter API Manifest - Guardrail.status.
- class smarter.apps.guardrail.manifest.models.guardrail.status.SAMGuardrailStatus(*, recordLocator, created, modified, dependencies=None, accountNumber, username, triggered=None, blocked=None, errors=None, lastTriggered=None)[source]
Bases:
AbstractSAMStatusBaseSmarter API Guardrail Manifest - Status class.
Read only. Besides ownership, it reports the guardrail’s events of the last 30 days. The LLMClients that use it are reported in
dependencies.- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
Smarter API Guardrail Manifest.
- class smarter.apps.guardrail.manifest.models.guardrail.model.SAMGuardrail(*, apiVersion, kind, metadata, spec, status=None)[source]
Bases:
AbstractSAMBaseSmarter API Manifest - Guardrail.
- metadata: SAMGuardrailMetadata
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- spec: SAMGuardrailSpec
- status: SAMGuardrailStatus | None