Skip to content

Ruleset Drivers

Overview

Ruleset Drivers can be used to load rules in from external sources.

Ruleset Drivers

Local

The LocalRulesetDriver allows you to load a Ruleset from a local JSON file. The persist_dir parameter is used to specify a local directory where one or more Ruleset files are located. If no persist_dir parameter is given, the .load method is a no-op.

import json
import os
from pathlib import Path

from griptape.drivers import LocalRulesetDriver
from griptape.rules import Ruleset

ruleset_dir = "path/to/ruleset/dir"
ruleset_name = "my_local_ruleset.json"
ruleset_path = Path(os.path.join(ruleset_dir, ruleset_name))

os.makedirs(ruleset_dir, exist_ok=True)

ruleset_path.write_text(json.dumps({"rules": [{"value": "Always talk like a pirate."}]}))

ruleset = Ruleset(
    name=ruleset_name,
    ruleset_driver=LocalRulesetDriver(persist_dir=ruleset_dir),
)

Griptape Cloud

The GriptapeCloudRulesetDriver allows you to load a Griptape Cloud Ruleset resource. Ruleset.name is used to try and find a Griptape Cloud Ruleset with that alias.

from griptape.drivers import GriptapeCloudRulesetDriver
from griptape.rules import Ruleset

rulset = Ruleset(
    name="my_griptape_cloud_ruleset_alias",
    ruleset_driver=GriptapeCloudRulesetDriver(),
)