> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deeprails.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Defend Overview

> Defend is the most powerful tool within DeepRails' API suite. It is the real-time correction layer that ensures every model output is hallucination-free before it ever reaches your users. By combining adaptive thresholds with automated improvement tools, Defend doesn't just detect low-quality or unsafe responses, it actively fixes or regenerates them, delivering safe, accurate, and reliable outputs at scale.

## Why Defend Exists

Generative AI is transformative, but enterprises are losing billions to hallucinations, compliance failures, and unreliable outputs. Most guardrail solutions only measure quality - they rarely enforce it. Defend was built to solve this gap. It continuously evaluates every response against rigorous guardrails, blocks failures at inference time, and applies automated remediation to protect both your brand and your customers.

## Key Definitions

* **Guardrail Metrics:** The heart of all of our APIs and Evaluations. Defend evaluates outputs against DeepRails' research-backed General-Purpose Guardrail Metrics for correctness, completeness, adherence (context, ground truth, instruction), and comprehensive safety, with full support for Custom Guardrail Metrics available for users on SME & Enterprise plans.
* **Workflow**: Defend requires you to define and create a workflow, which represents a specific LLM use case or task. A workflow bundles together the guardrails, thresholds, improvement strategy, and retry limits that will be applied consistently to every output of that use case.
* **Automatic & Custom Thresholds**: A threshold is the score cutoff below which an output is treated as a hallucination. Defend supports automatic thresholds, which adapt dynamically to your selected hallucination tolerance level (low, medium, or high), and custom thresholds, where you define explicit cutoff values for each guardrail for maximum flexibility.
* **Improvement Tools:** When an output fails to meet the thresholds defined in your workflow, Defend can automatically apply one of three improvement strategies:
  * **FixIt:** improves the flagged output using the failure rationale and surrounding context until it satisfies the workflow's guardrails or retry limits are reached.
  * **ReGen:** Regenerates a new output from the original prompt and parameters, introducing controlled variance to avoid repeating the same failure, and re-evaluates it against the workflow's guardrails.
  * **Do Nothing:** Records the failed output without attempting remediation, leaving handling of exceptions entirely to your workflow.
* **Run Modes:** Run modes give developers control over the trade-off between cost and accuracy. Fast uses budget models for maximum speed; Precision offers high accuracy analysis; and Precision Codex, Precision Max, and Precision Max Codex use advanced reasoning and codex models for maximum accuracy.
* **Extended AI Capabilities:** Many LLM applications have to go beyond model knowledge. DeepRails provides access to advanced tools like web and file search and context awareness for evaluations if needed.

## How Defend Works

Defend operates via a simple but robust lifecycle:

<Steps>
  <Step title="Workflow Setup">
    You define once how outputs will be judged and corrected — guardrails, thresholds, run mode, improvement tool, and retry limits.
  </Step>

  <Step title="Event Submission">
    Each model completion is submitted as an event with its input/output pair, model, and optional nametag — either programmatically or in the API Playground.
  </Step>

  <Step title="Evaluation">
    Defend scores the output against your workflow's guardrails, applying the thresholds you've set or selected.
  </Step>

  <Step title="Remediation">
    Passing outputs are returned immediately. Failing outputs trigger the improvement tool: FixIt iteratively improves the original output, ReGen regenerates a fresh one, or Do Nothing records the failure without intervention.
  </Step>

  <Step title="Response & Visibility">
    Defend returns the outcome (pass/fail), guardrail scores and rationales, the final improved/regenerated output (if applicable), retry history, and detailed cost and status metadata. Every decision is logged under the workflow, and full statistics and visualizations are available in the DeepRails Console for monitoring, auditing, and optimization.
  </Step>
</Steps>

## Console Walkthrough

The Defend Console brings each stage of the lifecycle to life, making it easy to configure, monitor, and optimize your workflows.

### Metrics

The **Metrics** tab provides a visual, real-time view of how each workflow is performing across all guardrail metrics. It highlights how many outputs are being filtered, improved, or passed, and shows before-and-after score distributions so you can clearly see how Defend is raising quality over time.

<Frame caption="Defend Metrics visualizes how outputs move from failure to success — showing hallucinations filtered, improvements applied, and guardrail scores before vs. after Defend">
  <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/defend_console.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=ed5513e9460ab1937b1a87605b7c7ee7" alt="Defend Metrics showing recent data from all workflows" width="2636" height="1409" data-path="images/defend_console.png" />
</Frame>

### Data

The **Data** tab provides a detailed, event-level view of every evaluation run that passes through a workflow. It captures inputs, outputs, status, scores, and more for each attempt. This gives teams full transparency into how Defend is filtering, correcting, or regenerating outputs in practice.

<Frame caption="Defend Data lists every evaluation run, including workflow type, tolerance, improvement action, status, model, input/output, and guardrail scores across metrics.">
  <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/defend_data.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=daa76d2d24a7da865b97bc8fafa82dff" alt="Defend Data tab showing evaluation runs and guardrail scores" width="2620" height="1379" data-path="images/defend_data.png" />
</Frame>

<Frame caption="Clicking into an evaluation reveals the full improvement chain — each attempt, its outcome, and the final pass — along with workflow configuration and status metadata.">
  <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/defend_data_details.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=10e542ba20044d8314bb9ff2e26f139b" alt="Defend Data evaluation details showing retries and improvement chain" width="2643" height="1444" data-path="images/defend_data_details.png" />
</Frame>

### Manage Workflows

The **Manage Workflows** tab is where you configure, track, and maintain all workflows across your organization. It provides both a high-level summary of each workflow's performance and the ability to drill into configuration details, thresholds, tolerances, and improvement strategies. From here, you can review existing workflows or launch the guided wizard to create new ones.

<Frame caption="Workflow details show throughput, hallucinations filtered, improvements applied, thresholds, tolerances, and chosen improvement actions.">
  <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/manage_workflows.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=ad65fb17305e679d0f896ba071b8005d" alt="Workflow detail screen in Manage Workflows tab" width="2579" height="1445" data-path="images/manage_workflows.png" />
</Frame>

#### Creating a Defend Workflow

The creation wizard walks you through five simple steps to define how Defend will evaluate and remediate outputs:

<Steps>
  <Step title="Step 1 — Basic Information">
    Start by naming your workflow and (optionally) describing what it protects against. This helps keep workflows organized and clear for your team.

    <Frame caption="Provide a workflow name and optional description to define the purpose of your new workflow.">
      <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/create_a_workflow_1.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=18102a7367fcc2461edd594b54cab485" alt="Defend workflow creation step 1 basic information" width="1175" height="772" data-path="images/create_a_workflow_1.png" />
    </Frame>
  </Step>

  <Step title="Step 2 — Select Metrics">
    Choose which guardrail metrics the workflow should evaluate. Multiple guardrails can be combined, including correctness, completeness, adherence, and safety.

    <Frame caption="Select one or more guardrail metrics such as correctness, completeness, adherence, and comprehensive safety.">
      <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/create_a_workflow_2.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=01e894838e44bbc49175de8f11a3d80c" alt="Defend workflow creation step 2 select metrics" width="1213" height="1039" data-path="images/create_a_workflow_2.png" />
    </Frame>
  </Step>

  <Step title="Step 3 — Extended AI Capabilities">
    Choose which additional tools will be needed to complete evaluations for your workflow. Each will add cost, so only select a tool if your initial model uses it.

    <Frame caption="Select one or more extended capabilities such as file search or web search.">
      <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/create_a_workflow_3.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=996a8daebe561a835e97a7a2e53e9114" alt="Defend workflow creation step 3 select metrics" width="1168" height="1083" data-path="images/create_a_workflow_3.png" />
    </Frame>
  </Step>

  <Step title="Step 4 — Configure Thresholds">
    Define how strict the workflow should be. Use adaptive automatic thresholds with configurable hallucination tolerance (low, medium, high), or set explicit custom thresholds for full control.

    <Frame caption="Configure thresholds using adaptive automatic tolerance levels or custom cutoff values per guardrail.">
      <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/create_a_workflow_4.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=c31f70a6d06615b5120470ea72b13c59" alt="Defend workflow creation step 4 configure thresholds" width="1146" height="1308" data-path="images/create_a_workflow_4.png" />
    </Frame>
  </Step>

  <Step title="Step 5 — Choose Improvement Action">
    Decide how Defend should remediate outputs that fail. Options include FixIt (improve the flagged output), ReGen (regenerate a fresh output), or Do Nothing (record the failure only). Configure the maximum number of retries for automated attempts.

    <Frame caption="Pick between FixIt, ReGen, or Do Nothing, and set retry limits for remediation attempts.">
      <img src="https://mintcdn.com/deeprails-479f3a7b/KdzBGLVi0OKvQaB4/images/create_a_workflow_5.png?fit=max&auto=format&n=KdzBGLVi0OKvQaB4&q=85&s=6bcb848aa8f2cc320205a62f8317fbe4" alt="Defend workflow creation step 5 choose improvement action" width="1150" height="1211" data-path="images/create_a_workflow_5.png" />
    </Frame>
  </Step>
</Steps>
