SAM Pydantic Base Classes
These are the base Pydantic models used as the foundations for all Smarter API Manifest (SAM) models.
Pydantic models for Smarter API Manifests.
- class smarter.lib.manifest.models.AbstractSAMBase(*, apiVersion, kind, metadata, spec, status=None)[source]
Bases:
SmarterBasePydanticModel,ABCAbstract base class for all Smarter API Manifest (SAM) models.
This class serves as the foundational Pydantic model for representing Smarter API manifests. It is intended to be subclassed by concrete manifest classes that define specific resource types within the Smarter API ecosystem.
The
AbstractSAMBaseclass provides a strongly-typed structure for manifest data, ensuring that all manifests adhere to a consistent schema and validation logic. It includes built-in validation for core manifest fields and supports structured access to manifest data.Subclasses should implement or extend this class to define the specific data and behaviors required for their respective manifest types. This design promotes code reuse, type safety, and robust validation across all Smarter API manifests.
The class also provides methods for validating manifest data and for representing the manifest as a string for debugging or logging purposes.
Note
Do not instantiate this class directly. Instead, create subclasses that define the required fields and any additional validation or methods specific to your manifest type.
- metadata: AbstractSAMMetadataBase
- 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: AbstractSAMSpecBase
- status: AbstractSAMStatusBase | None
- classmethod validate_apiVersion(v)[source]
Validates the
apiVersionfield for a manifest.This method ensures that the
apiVersionattribute is present and matches one of the supported API versions defined inSmarterApiVersions. If the value is missing or invalid, aSAMValidationErroris raised.- Parameters:
v (str) – The value of the
apiVersionfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the value is missing or not a supported version.
- Return type:
- Returns:
The validated
apiVersionstring.
- classmethod validate_metadata(v)[source]
Validates the
metadatafield for a manifest.This method ensures that the
metadataattribute is an instance ofAbstractSAMMetadataBase. If a dictionary is provided, it will be coerced into anAbstractSAMMetadataBaseobject. This guarantees that the manifest metadata is always properly structured and validated.- Parameters:
v (dict or AbstractSAMMetadataBase) – The value of the
metadatafield to validate.- Return type:
- Returns:
The validated
metadataobject.
- class smarter.lib.manifest.models.AbstractSAMMetadataBase(*, name, description, version, tags=<factory>, annotations=<factory>)[source]
Bases:
SmarterBasePydanticModel,ABCAbstract base class for manifest metadata in the Smarter API.
This class defines the required structure and validation logic for metadata associated with Smarter API manifests. It is designed to be subclassed by concrete manifest metadata classes, which may extend or customize the metadata fields as needed for specific resource types.
The
AbstractSAMMetadataBaseenforces strong typing and validation for core metadata fields, such as resource name, description, version, tags, and annotations. It ensures that all metadata adheres to expected formats and constraints, promoting consistency and reliability across all manifest definitions.Subclasses should inherit from this class to implement metadata for their specific manifest types. This approach encourages code reuse, enforces validation, and provides a unified interface for working with manifest metadata throughout the Smarter API ecosystem.
Note
This class is abstract and should not be instantiated directly. Instead, create subclasses that define any additional fields or validation required for your manifest’s 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.
- classmethod normalize_annotations(v)[source]
Validate the
annotationsfield, and return it as a map of strings to strings.Accepts a map, the list of one-key maps of older manifests, or either as a JSON string. See
smarter.lib.annotation.validation.normalize_annotations().- Parameters:
v (AnnotationsInput) – The value of the
annotationsfield.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If a key or value is invalid.
- Return type:
- Returns:
The annotations.
- classmethod validate_description(v)[source]
Validates the
descriptionfield for a manifest.A string is stripped of its whitespace. A missing or blank description is None: it is not an error.
- classmethod validate_name(v)[source]
Validates the
namefield for a manifest.Ensures the value is a non-empty string of at most 50 characters, without characters that are not URL friendly. A name that is not URL friendly, or not in snake_case, is converted, with a warning.
- Parameters:
v (str) – The value of the
namefield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the value is not a string, is empty, is longer than 50 characters, or has characters that are not URL friendly.
- Return type:
- Returns:
The validated, and possibly converted,
name.
- classmethod validate_tags(v)[source]
Validates the
tagsfield for a manifest.This method ensures that each tag in the
tagslist adheres to URL-friendly character rules. If any tag is invalid, aSAMValidationErroris raised.- Parameters:
v (Optional[List[str]]) – The value of the
tagsfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If any tag is invalid.
- Return type:
- Returns:
The validated list of tags.
- classmethod validate_version(v)[source]
Validates the
versionfield for a manifest.A version follows semantic versioning rules. A missing or empty version is None: it is not an error.
- Parameters:
v (str) – The value of the
versionfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the version is not a semantic version.
- Return type:
- Returns:
The validated
versionstring, or None if it is missing or empty.
- class smarter.lib.manifest.models.AbstractSAMSpecBase[source]
Bases:
SmarterBasePydanticModel,ABCPydantic Spec base class.
Expected to be subclassed by specific manifest classes.
- 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.lib.manifest.models.AbstractSAMStatusBase(*, recordLocator, created, modified, dependencies=None)[source]
Bases:
SmarterBasePydanticModel,ABCPydantic Status base class.
Expected to be subclassed by specific manifest classes.
- dependencies: List[SAMDependency] | 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.
- class smarter.lib.manifest.models.SAMDependency(*, kind, name)[source]
Bases:
SmarterBasePydanticModelA resource that depends on the resource that a manifest describes.
- 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.lib.manifest.models.SAMDependencyTreeNode(*, kind, icon, name=None, owner=None, recordLocator=None, url=None, detailUrl=None, readable=True, children=<factory>)[source]
Bases:
SmarterBasePydanticModelA resource in a dependency tree: the resource, and, recursively, every resource that it uses.
It is the opposite direction of
SAMDependency, which lists the resources that depend on a resource. An LLMClient’s tree has its Provider, its plugins, their Connections, and those Connections’ Secrets. Seesmarter.lib.manifest.broker.AbstractBroker.dependency_tree().A resource that the user may not read keeps its kind and record locator, so that the tree still shows that something is there, but not its name, owner or urls, or what it uses in turn.
Each readable resource has two urls:
url, its manifest page in the web console, where its manifest can be edited, anddetailUrl, the api of its detail (its manifest, what it uses and what uses it), which a resource’s detail dialog in the web console shows when its card is chosen.Example:
{ "kind": "LLMClient", "icon": "artificial-intelligence", "name": "stackademy_sql", "owner": "Ada Lovelace (ada)", "recordLocator": "llmclient-rMTAwMDAxMwx", "url": "/workbench/llm-clients/rMTAwMDAxMwx/manifest/", "detailUrl": "/api/web/dashboard/resource/LLMClient/llmclient-rMTAwMDAxMwx/", "readable": true, "children": [ { "kind": "SqlPlugin", "icon": "file-sheet", "name": "stackademy_sql", "owner": "Ada Lovelace (ada)", "recordLocator": "pluginmeta-rMTEx", "url": "/llm-tools/plugins/rMTEx/", "detailUrl": "/api/web/dashboard/resource/SqlPlugin/pluginmeta-rMTEx/", "readable": true, "children": [] } ] }
- children: List[SAMDependencyTreeNode]
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True, 'json_schema_serialization_defaults_required': 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.lib.manifest.models.SmarterBasePydanticModel[source]
Bases:
BaseModel,SmarterHelperMixinSmarter API Base Pydantic Model.
- __init__(**data)[source]
Initialize the model, with an optional owner that is kept in private attributes.
- Parameters:
data – The model’s fields, and optionally
user_profileoruser, which are not fields. A user profile sets bothuser_profileanduser. A user without a user profile sets them only if the user is authenticated, from the user’s cached user profile.
- classmethod coerce_none_strings(data)[source]
Replace the strings
"None"and""with None in the raw input, before validation.- Parameters:
data – The raw input; only a dict is changed, in place.
- Returns:
The input.
- 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.
- property user: User | None
Get the user associated with this manifest, if any.
- Returns:
The user of the model’s user profile, or None.
- property user_profile: UserProfile | None
Get the user profile associated with this manifest, if any.
- Returns:
The user profile that the model was initialized with, or the authenticated user’s, or None.
- smarter.lib.manifest.models.client_manifest_validation()[source]
Validate, inside this context, a manifest that a client sent, e.g. to apply or validate it.
Brokers validate a client’s manifest inside it. Models that they build from the database are validated outside of it. Validators that check something outside of the manifest, such as that a url is available, run only inside it (see
is_client_manifest()), so that describing a resource never depends on the network.A context variable is used rather than Pydantic’s validation context, because
SmarterBasePydanticModeloverrides__init__, through which Pydantic validates nested models without the validation context.Example:
with client_manifest_validation(): spec = SAMLLMClientSpec(**manifest["spec"])
- smarter.lib.manifest.models.is_client_manifest()[source]
Whether the manifest that is being validated is one that a client sent.
- Return type:
- Returns:
True inside
client_manifest_validation().