Skip to main content

Setup

To begin with, let’s set up and initialize a Dome object in your Python environment. This may install models and perform some initial setup the first time it is invoked.
Note that we load a default config shipped with the Dome library to initialize the Dome class. Later in this example we show how to create your own configurations.

Scan strings

The default configuration blocks prompt injection and jailbreak attacks in inputs, and toxic content in inputs and outputs. Let’s pass a prompt injection string to the input Guard in our initialized Dome and see if it gets detected.
Looks like the input Guard successfully detected the prompt injection. Specifically, the prompt injection classifier flagged this input as insafe. For debugging, you can view the entire trace of the Guardrail history.
In addition to the traceback() string and the is_safe() flag, Dome provides a guarded_response() method that you can use to obtain an output from Dome. Depending on your Guard’s configuration, this is either a blocked message, the original string that was passed through the Guard, or possibly a santized version of the string passed to the Guard.

Configuring Dome

Dome can be initialized via dictionaries or TOML files. A full guide on configuring Dome can be found here.

Initialization via a dict

As an example, let’s initialize a Dome using an input Guard comprising of a single Guard which enforces a phrase banlis, and an output Guard that detects toxicity and PII. For PII, you customize the privacy-presidio Guard using
  • anonymize that results in the PII Guard obfuscating PII,
  • allow_list_files which is a list of allowlisted files that has data not to be obfuscated.
Let’s see how this config does in catching different undesirable information.

Banlist

The following query is not caught by larger models, but is caught via our banlist Guard.

Personally Identifiabile Infomration (PII)

The following is a sample PII query that gets censored.

Allowlisted Personally Identifiabile Infomration (PII)

The PII allowlist enabled in the config allows us to customize what terms we can exclude from being classified as PII. Currently this contains the strings help@ally.com, ally.com, (877) 247-2559. Here is what happens when text containing the above strings is scanned using Dome.

Initialization via a TOML file

Finally, you initialize the same Dome as above, but loading the config from a TOML file saved in the disk. After loading, you scan a sample prompt injection input, which is successfully blocked.
Last modified on July 16, 2026