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: AbstractSAMMetadataBase

Smarter API Guardrail Manifest - Metadata class.

class_identifier: ClassVar[str] = 'Guardrail.metadata'
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

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 optional flags.

  • keyword: keywords, and optional caseSensitive and wholeWord.

  • detector: detectors.

  • semantic: referenceTexts, and optional threshold, model and provider.

  • moderation: optional categories, threshold, model and provider.

  • llm_judge: judgePrompt, with a {text} placeholder, and optional threshold, model and provider.

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 flags may contain.

('IGNORECASE', 'MULTILINE', 'DOTALL')
class smarter.apps.guardrail.manifest.models.guardrail.spec.SAMGuardrailSpec(*, config: SAMGuardrailSpecConfig)[source]

Bases: AbstractSAMSpecBase

Smarter API Guardrail Manifest Guardrail.spec.

class_identifier: ClassVar[str] = '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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

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: AbstractSAMSpecBase

Smarter API Guardrail Manifest Guardrail.spec.config.

action: Literal['log', 'flag', 'redact', 'transform', 'block', 'escalate']
caseSensitive: bool
categories: list[str] | None
category: Literal['pii', 'secrets', 'prompt_injection', 'jailbreak', 'toxicity', 'self_harm', 'hallucination', 'off_topic', 'compliance', 'formatting', 'custom']
class_identifier: ClassVar[str] = 'Guardrail.spec.config'
detectors: list[str] | None
failClosed: bool
flags: list[str] | None
isActive: bool
judgePrompt: str | None
keywords: list[str] | None
message: str | None
mode: Literal['enforce', 'monitor']
model: str | None
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

pattern: str | None
priority: int
provider: str | None
referenceTexts: list[str] | None
replacement: str | None
severity: int
stage: Literal['input', 'output', 'both']
strategy: Literal['regex', 'keyword', 'detector', 'semantic', 'moderation', 'llm_judge']
threshold: float | None
classmethod validate_action(v)[source]
Return type:

str

validate_action_fields()[source]

Validate that the action is possible with the strategy.

Return type:

SAMGuardrailSpecConfig

classmethod validate_categories(v)[source]
Return type:

list[str]

classmethod validate_category(v)[source]
Return type:

str

classmethod validate_detectors(v)[source]
Return type:

list[str]

classmethod validate_flags(v)[source]
Return type:

list[str]

classmethod validate_message(v)[source]
Return type:

str | None

classmethod validate_mode(v)[source]
Return type:

str

classmethod validate_stage(v)[source]
Return type:

str

classmethod validate_strategy(v)[source]
Return type:

str

validate_strategy_fields()[source]

Validate the fields of the guardrail’s strategy.

Return type:

SAMGuardrailSpecConfig

classmethod validate_texts(v)[source]
Return type:

list[str]

wholeWord: bool
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:

str

smarter.apps.guardrail.manifest.models.guardrail.spec.compile_flags(flags)[source]

Return the combined re flags for a list of flag names.

Return type:

int

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: AbstractSAMStatusBase

Smarter 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.

accountNumber: str
blocked: int | None
class_identifier: ClassVar[str] = 'Guardrail.status'
errors: int | None
lastTriggered: datetime | None
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

triggered: int | None
username: str

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: AbstractSAMBase

Smarter API Manifest - Guardrail.

class_identifier: ClassVar[str] = '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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

spec: SAMGuardrailSpec
status: SAMGuardrailStatus | None