> ## 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.

# Update a Workflow

> Use this endpoint to update an existing defend workflow if its details change.


This endpoint can update the workflow's `name`, `description`, `threshold_type`, `automatic_hallucination_tolerance_levels`, `custom_hallucination_threshold_values`, and `improvement_action` when needed. You can also add or remove extended AI capabilities like `web_search` and `file_search`. Only fields provided in the request body will be updated.


## OpenAPI

````yaml /api-reference/openapi.yaml put /defend/{workflow_id}
openapi: 3.0.0
info:
  title: DeepRails API
  description: >
    DeepRails is a powerful developer tool with a comprehensive set of adaptive
    & accurate guardrails to protect against LLM hallucinations - deploy our
    Monitor and Defend APIs in less than 15 minutes for the best out-of-the-box
    guardrails available.
  version: v3.0
  contact:
    name: DeepRails Support
    email: support@deeprails.ai
servers:
  - url: https://api.deeprails.com
    description: Production server
security:
  - BearerAuth: []
paths:
  /defend/{workflow_id}:
    put:
      tags:
        - Defend
      summary: Update a Workflow
      description: >
        Use this endpoint to update an existing defend workflow if its details
        change.
      parameters:
        - name: workflow_id
          in: path
          description: The ID of the workflow to edit.
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: New name for the workflow.
                description:
                  type: string
                  description: New description for the workflow.
                threshold_type:
                  type: string
                  description: >
                    New type of thresholds to use for the workflow, either
                    `automatic` or `custom`.  Automatic thresholds are assigned
                    internally after the user specifies a qualitative tolerance
                    for the metrics, whereas custom metrics allow the user to
                    set the threshold for each metric as a floating point number
                    between 0.0 and 1.0.
                  enum:
                    - automatic
                    - custom
                automatic_hallucination_tolerance_levels:
                  type: object
                  description: >
                    New mapping of guardrail metrics to hallucination tolerance
                    levels
                     (either `low`, `medium`, or `high`) to be used when `threshold_type`
                     is set to `automatic`. Possible metrics are 
                     `completeness`, `instruction_adherence`, `context_adherence`, 
                     `ground_truth_adherence`, or `comprehensive_safety`.
                  additionalProperties:
                    type: string
                    enum:
                      - low
                      - medium
                      - high
                custom_hallucination_threshold_values:
                  type: object
                  description: >
                    New mapping of guardrail metrics to floating point threshold
                    values to be used when `threshold_type` is set to `custom`.
                    Possible metrics are `correctness`, `completeness`,
                    `instruction_adherence`, `context_adherence`,
                    `ground_truth_adherence`, or `comprehensive_safety`.
                  additionalProperties:
                    type: number
                    format: float
                    minimum: 0
                    maximum: 1
                improvement_action:
                  type: string
                  description: >
                    The new action used to improve outputs that fail one or more
                    guardrail metrics for the workflow events.  May be `regen`,
                    `fixit`, or `do_nothing`.  ReGen runs the user's input
                    prompt with minor induced variance.  FixIt attempts to
                    directly address the shortcomings of the output using the
                    guardrail failure rationale. Do Nothing does not attempt any
                    improvement.
                  enum:
                    - regen
                    - fixit
                    - do_nothing
                  nullable: false
                max_improvement_attempts:
                  type: integer
                  description: >-
                    Max. number of improvement action attempts until a given
                    event passes the guardrails. Defaults to 10.
                  default: 10
                web_search:
                  type: boolean
                  description: >-
                    Whether to enable web search for this workflow's
                    evaluations.
                  default: false
                file_search:
                  type: array
                  description: >-
                    An array of file IDs to search in the workflow's
                    evaluations. Files must be uploaded via the DeepRails API
                    first.
                  items:
                    type: string
                    description: >-
                      A file ID corresponding to a file to search in the
                      workflow's evaluations.
                context_awareness:
                  type: boolean
                  description: >-
                    Whether to enable context awareness for this workflow's
                    evaluations.
                  default: false
      responses:
        '200':
          description: Workflow updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DefendUpdateResponse'
        '400':
          description: Invalid request
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: python
          label: Update a Workflow
          source: |
            from deeprails import DeepRails

            DEEPRAILS_API_KEY = "YOUR_API_KEY"

            client = DeepRails(
                api_key=DEEPRAILS_API_KEY,
            )

            workflow_response = client.defend.update_workflow(
                workflow_id="wkfl_xxxxxxxxxxxx",
                description="A workflow used to test the DeepRails SDK",
                threshold_type="automatic",
                automatic_hallucination_tolerance_levels={
                    "completeness": "low",
                    "instruction_adherence": "medium",
                    "comprehensive_safety": "medium"
                },
                improvement_action="regen",
                max_improvement_attempts=3,
                web_search=False,
                context_awareness=False,
                file_search=["file_1", "file_2", "file_3"]
            )
            print(workflow_response)
components:
  schemas:
    DefendUpdateResponse:
      type: object
      properties:
        workflow_id:
          type: string
          description: A unique workflow ID.
          example: wkfl_xxxxxxxxxxxx
        status:
          type: string
          description: >-
            Status of the selected workflow.  May be `inactive` or `active`. 
            Inactive workflows will not accept events.
          example: active
          enum:
            - inactive
            - active
        name:
          type: string
          description: The name of the workflow.
          example: Test Workflow
        modified_at:
          type: string
          format: date-time
          description: The time the workflow was last modified in UTC.
          example: '2025-01-15T10:30:00Z'
      required:
        - workflow_id
        - status
        - modified_at
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````