> ## Documentation Index
> Fetch the complete documentation index at: https://vijil-dome-ui.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Guardrail

> Configurable pipelines that orchestrate Guards into complete protection policies.

A Guardrail is a configured pipeline of [Guards](/concepts/defense/guard) that implements your protection policy. If Guards are the individual security checks, Guardrails are the security checkpoint they define which checks happen, in what order, and what to do with the results.

Vijil Dome allows users to assemble and configure Guardrails, which are designed to scan data exchanged with LLMs, knowledge bases, or other agents. Dome supports several types of Guardrails:

* **Input Guardrails**: For scanning inputs to a foundation model.
* **Output Guardrails**: For scanning outputs from a foundation model.
* **Retrieval Guardrails** (coming soon): To protect requests to and from retrievers.
* **Execution Guardrails** (coming soon): To protect requests to and from external agents and tools.

<Info>
  The Vijil Console currently configures Input and Output Guards from the selected Agent's **Protect** view. Retrieval and Execution Guardrails are broader concepts and are not sections in the current Console.
</Info>

```mermaid actions={false} theme={null}
%%{init: {'theme':'base', 'themeVariables': {'fontFamily':'Futura Medium, Futura, sans-serif','fontSize':'13px'}, 'flowchart': {'nodeSpacing':25,'rankSpacing':35,'padding':6}}}%%
flowchart TD
    App[Application Code]

    subgraph Platform[" "]
        InputGR[Input Guardrail]
        OutputGR[Output Guardrail]
        FM((Foundational Models))
        RetrievalGR[Retrieval Guardrail]
        ExecutionGR[Execution Guardrail]
    end

    Retriever[Retriever]
    Agents[Agents]

    App --> InputGR
    InputGR --> FM
    FM --> OutputGR
    OutputGR --> App
    FM <--> RetrievalGR
    FM <--> ExecutionGR
    RetrievalGR <--> Retriever
    ExecutionGR <--> Agents

    classDef guardrail fill:#0247A9,stroke:#2B0C0C,color:#FFFFFF,stroke-width:1px;
    classDef model     fill:#DE1616,stroke:#2B0C0C,color:#FFFFFF,stroke-width:1px;
    classDef external  fill:#FFFFFF,stroke:#2B0C0C,color:#2B0C0C,stroke-width:1.5px;
    classDef platform  fill:none,stroke:#2B0C0C,stroke-width:1px,stroke-dasharray:5 5;

    class InputGR,OutputGR,RetrievalGR,ExecutionGR guardrail;
    class FM model;
    class App,Retriever,Agents external;
    class Platform platform;
```

Guardrails consist of a set of [Guards](/concepts/defense/guard) and how they should be executed. These Guards are fully configurable and customizable.

## Setting Up Guards and Detectors

Users can configure Guards by selecting and combining different [Detectors](/concepts/evaluation-components/detector) based on their specific needs. This customization allows for flexible and robust Guardrails that cater to diverse application requirements.

```mermaid actions={false} theme={null}
%%{init: {'theme':'base', 'themeVariables': {'fontFamily':'Futura Medium, Futura, sans-serif','fontSize':'13px'}, 'flowchart': {'nodeSpacing':25,'rankSpacing':55,'padding':6}}}%%
flowchart LR
    InputGR[Input Guardrail]
    OutputGR[Output Guardrail]

    SecGuard[Security Guard]
    ModGuard1[Moderation Guard]
    PrivGuard[Privacy Guard]
    ModGuard2[Moderation Guard]

    PIModel[Prompt Injection Model]
    PIEmbed[Prompt Injection Embeddings Detector]
    KeyBan[Keyword Banlist]
    PII[PII Detector]
    ToxModel[Toxic Content Model]
    PromptEng[Prompt Engineering-based Detector]

    InputGR --> SecGuard
    InputGR --> ModGuard1
    SecGuard --> PIModel
    SecGuard --> PIEmbed
    ModGuard1 --> KeyBan

    OutputGR --> PrivGuard
    OutputGR --> ModGuard2
    PrivGuard --> PII
    ModGuard2 --> ToxModel
    ModGuard2 --> PromptEng

    classDef guardrail fill:#0247A9,stroke:#2B0C0C,color:#FFFFFF,stroke-width:1px;
    classDef guard     fill:#DE1616,stroke:#2B0C0C,color:#FFFFFF,stroke-width:1px;
    classDef detector  fill:#FFFFFF,stroke:#2B0C0C,color:#2B0C0C,stroke-width:1.5px;

    class InputGR,OutputGR guardrail;
    class SecGuard,ModGuard1,PrivGuard,ModGuard2 guard;
    class PIModel,PIEmbed,KeyBan,PII,ToxModel,PromptEng detector;
```

### Example Configuration

Here is an example based on the predefined Console Guards and Detectors (see the [Configuring Dome section](/owner-guide/protect-in-production/configuring-guardrails) for more details):

<CodeGroup>
  ```python title="Python" icon="python" theme={null}

   config = {
      ########################
      # Setup Guardrails from Guards
      ########################
      # Input Guardrail
      "input-guards": ["security-guard", "moderation-guard"],

      # Output Guardrail
      "output-guards": ["moderation-guard", "privacy-guard"],

      ##########################
      # Assemble and configure Guards
      ##########################

      # Security input Guard
      "security-guard": {
          "type": "security",
          "methods": ["encoding-heuristics", "prompt-injection-mbert"],
      },

      # Moderation input and output Guard
      "moderation-guard": {
          "type": "moderation",
          "methods": ["moderation-flashtext", "moderation-mbert"],
      },

      # Privacy output Guard
      "privacy-guard": {
          "type": "privacy",
          "methods": ["privacy-presidio"],
      },
  }
  ```
</CodeGroup>

### Scan Results

The output from Dome's `scan` functions is a `ScanResult` object. It contains the following fields

* `flagged`: boolean value that indicates if the Guardrail has flagged the data that was passed through it. If this is true, it means the input is in violation of the policy the Guardrail aims to enforce. This value will always be the opposite of the value returned from the ScanResult's `.is_safe()` method.
* `response_string`: a string that contains the Guardrail's response message. This can be the original input if there was nothing wrong with it, a sanitized version of the input, or a message indicating that the input was blocked, along with the methods that blocked it.
* `exec_time`: float. the time it took for the Guardrail to scan the input, measured in milliseconds
* `trace`: a dictionary. This contains the execution information for every Guard in the Guardrail. This includes whether or not they were flagged, their individual execution times, and debugging information for each Detector in the Guard.

## Next Steps

<CardGroup cols={2}>
  <Card title="Guard" icon="shield" href="/concepts/defense/guard">
    Understand individual protection types
  </Card>

  <Card title="Detector" icon="microscope" href="/concepts/defense/detector">
    The detection engines inside Guards
  </Card>

  <Card title="Configure Guardrails" icon="sliders-horizontal" href="/owner-guide/protect-in-production/configuring-guardrails">
    Set up Dome for your agent
  </Card>
</CardGroup>
