Skip to content

base_ruleset_driver

BaseRulesetDriver

Bases: SerializableMixin, ABC

Base class for ruleset drivers.

Attributes:

Name Type Description
raise_not_found bool

Whether to raise an error if the ruleset is not found. Defaults to True.

Source code in griptape/drivers/ruleset/base_ruleset_driver.py
@define
class BaseRulesetDriver(SerializableMixin, ABC):
    """Base class for ruleset drivers.

    Attributes:
        raise_not_found: Whether to raise an error if the ruleset is not found. Defaults to True.
    """

    raise_not_found: bool = field(default=True, kw_only=True, metadata={"serializable": True})

    @abstractmethod
    def load(self, ruleset_name: str) -> tuple[list[BaseRule], dict[str, Any]]: ...

    def _from_ruleset_dict(self, params_dict: dict[str, Any]) -> tuple[list[BaseRule], dict[str, Any]]:
        return [
            self._get_rule(rule["value"], rule.get("meta", {})) for rule in params_dict.get("rules", [])
        ], params_dict.get("meta", {})

    def _get_rule(self, value: Any, meta: dict[str, Any]) -> BaseRule:
        from griptape.rules import JsonSchemaRule, Rule

        return JsonSchemaRule(value=value, meta=meta) if isinstance(value, dict) else Rule(value=str(value), meta=meta)

raise_not_found: bool = field(default=True, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

load(ruleset_name) abstractmethod

Source code in griptape/drivers/ruleset/base_ruleset_driver.py
@abstractmethod
def load(self, ruleset_name: str) -> tuple[list[BaseRule], dict[str, Any]]: ...