PluginDataStatic Model

class smarter.apps.plugin.models.PluginDataStatic(*args, **kwargs)[source]

Bases: PluginDataBase

Stores the configuration and static data set for a Smarter plugin which is based on static data.

This model is used for plugins that return static (predefined) data to the LLM. The static_data field holds the JSON data that will be returned when the plugin is invoked. This enables plugins to provide consistent, deterministic responses without external dependencies.

PluginDataStatic provides methods for:
  • Returning sanitized static data, either as a dictionary or a list, with optional truncation for large datasets.

  • Extracting and caching all keys present in the static data, supporting both flat and nested structures.

  • Ensuring that the static data conforms to the expected structure and is compatible with the plugin’s parameter schema.

This model is a concrete subclass of PluginDataBase, and is referenced by PluginMeta to provide the data payload for static-type plugins. It is also used in conjunction with PluginSelector and PluginPrompt to enable full plugin lifecycle management.

Typical use cases include plugins that serve reference data, lookup tables, or any information that does not require dynamic computation or remote queries.

See also:

Parameters:
  • id (BigAutoField) – Primary key: ID

  • created_at (DateTimeField) – Created at

  • updated_at (DateTimeField) – Updated at

  • description (TextField) – Description. A brief description of what this plugin returns. Be verbose, but not too verbose.

  • parameters (JSONField) –

    Parameters. A JSON dict containing parameter names and data types. Example: {‘required’: [], ‘properties’: {‘max_cost’: {‘type’: ‘float’, ‘description’: ‘the maximum cost that a student is willing to pay for a course.’}, ‘description’: {‘enum’: [‘AI’, ‘mobile’, ‘web’, ‘database’, ‘network’, ‘neural networks’], ‘type’: ‘string’, ‘description’: ‘areas of specialization for courses in the catalogue.’}}}

    A JSON dict containing parameter names and data types. Example: {‘required’: [], ‘properties’: {‘max_cost’: {‘type’: ‘float’, ‘description’: ‘the maximum cost that a student is willing to pay for a course.’}, ‘description’: {‘enum’: [‘AI’, ‘mobile’, ‘web’, ‘database’, ‘network’, ‘neural networks’], ‘type’: ‘string’, ‘description’: ‘areas of specialization for courses in the catalogue.’}}}

  • test_values (JSONField) –

    Test values. A JSON dict containing test values for each parameter. Example: {‘city’: ‘San Francisco’}

    A JSON dict containing test values for each parameter. Example: {‘city’: ‘San Francisco’}

  • static_data (JSONField) –

    Static data. The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.

    The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.

Relationship fields:

Parameters:
exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

data(params=None)[source]

Return the static data as a dictionary. This method attempts to parse and return the static_data field as a dictionary.

Parameters:

params (Optional[dict]) – Optional parameters for future extensibility (currently unused).

Returns:

The static data as a dictionary, or None if parsing fails.

Return type:

Optional[dict]

classmethod get_cached_data_by_plugin(plugin, invalidate=False)[source]

Return a single instance of PluginDataStatic by plugin.

This method caches the results to improve performance.

Parameters:

plugin (PluginMeta) – The plugin whose data should be retrieved.

Returns:

A PluginDataStatic instance if found, otherwise None.

Return type:

Union[PluginDataStatic, None]

classmethod get_cached_object(invalidate=False, pk=None, plugin=None)[source]

Retrieve a model instance by primary key, using caching to optimize performance. This method is selectively overridden in models that inherit from MetaDataModel to provide class-specific function parameters.

Example usage:

# Retrieve by primary key
instance = MyModel.get_cached_object(pk=1)
Parameters:
  • invalidate (bool) – If True, invalidate the cache for this query before retrieving the object.

  • pk (int) – The primary key of the model instance to retrieve.

  • plugin (PluginMeta) – The PluginMeta instance associated with the data to retrieve.

Returns:

The model instance if found, otherwise None.

Return type:

Optional[“PluginDataBase”]

plugindatabase_ptr

OneToOneField to PluginDataBase

Primary key: Plugindatabase ptr (related name: plugindatastatic)

Type:

Type

plugindatabase_ptr_id

Internal field, use plugindatabase_ptr instead.

property return_data_keys: list[str] | None

Return all keys present in the static_data attribute.

This property extracts, caches and returns a list of all keys found in the static_data field, supporting both dictionary and list formats:

  • If static_data is a dictionary, all nested keys are recursively collected and returned as a flat list.

  • If static_data is a list of dictionaries, the keys are extracted from each dictionary and returned as a list, truncated to smarter_settings.plugin_max_data_results items if necessary.

  • If static_data is neither a dictionary nor a list, a SmarterValueError is raised.

Returns:

A list of all keys in the static data, or None if not applicable.

Return type:

Optional[list[str]]

Raises:

SmarterValueError – If static_data is not a dict or list.

Example:

# If static_data is a dict:
static_data = {"a": 1, "b": {"c": 2}}
return_data_keys  # ['a', 'b', 'c']

# If static_data is a list of dicts:
static_data = [{"name": "Alice"}, {"name": "Bob"}]
return_data_keys  # ['Alice', 'Bob']
sanitized_return_data(params=None)[source]

Return the static data for this plugin, either as a dictionary or a list.

This method returns the value of self.static_data in a sanitized form:

  • If static_data is a dictionary, it is returned as-is.

  • If static_data is a list, it is truncated to smarter_settings.plugin_max_data_results items (if necessary) and converted to a dictionary using list_of_dicts_to_dict().

  • If static_data is neither a dictionary nor a list, a SmarterValueError is raised.

Parameters:

params (Optional[dict]) – Optional parameters for future extensibility (currently unused).

Returns:

The sanitized static data as a dictionary or list.

Return type:

Optional[Union[dict, list]]

Raises:

SmarterValueError – If static_data is not a dict or list.

static_data

JSONField

Static data. The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.

The JSON data that this plugin returns to OpenAI API when invoked by the user prompt.

Type:

Type