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: str, description: str | None, version: str | None, tags: List[str] | None = <factory>, annotations: List[dict[str, str | int | float | bool | ~datetime.date | ~datetime.datetime | ~decimal.Decimal | ~uuid.UUID | bytes | list | dict]] | None=<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: SAMGuardrailSpecConfig)[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: ~typing.Literal['input', 'output', 'both'], category: ~typing.Literal['pii', 'secrets', 'prompt_injection', 'jailbreak', 'toxicity', 'self_harm', 'hallucination', 'off_topic', 'compliance', 'formatting', 'custom'] = 'custom', strategy: ~typing.Literal['regex', 'keyword', 'detector', 'semantic', 'moderation', 'llm_judge'], pattern: str | None = None, flags: list[str] | None = <factory>, keywords: list[str] | None = <factory>, caseSensitive: bool = False, wholeWord: bool = True, detectors: list[str] | None = <factory>, referenceTexts: list[str] | None = <factory>, categories: list[str] | None = <factory>, judgePrompt: str | None = None, threshold: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0.0), ~annotated_types.Le(le=1.0)] = None, model: str | None = None, provider: str | None = None, action: ~typing.Literal['log', 'flag', 'redact', 'transform', 'block', 'escalate'], replacement: str | None = None, message: str | None = None, severity: ~typing.Annotated[int, ~annotated_types.Ge(ge=1), ~annotated_types.Le(le=5)] = 3, mode: ~typing.Literal['enforce', 'monitor'] = 'enforce', failClosed: bool = False, priority: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 100, isActive: bool = 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.
- validate_action_fields()[source]
Validate that the action is possible with the strategy.
- Return type:
- smarter.apps.guardrail.manifest.models.guardrail.spec.choice(value, choices, field)[source]
Return a lower cased value, if it is one of
choices.- Return type:
- 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: str, created: datetime, modified: datetime, dependencies: List[SAMDependency] | None = None, accountNumber: str, username: str, triggered: int | None = None, blocked: int | None = None, errors: int | None = None, lastTriggered: datetime | None = 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: str, kind: str, metadata: SAMGuardrailMetadata, spec: SAMGuardrailSpec, status: SAMGuardrailStatus | None = 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