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

# Update Policy

> Change a policy. What is left out stays as it is.

With a CLI sign-in or a key marked for an agent, refused with
`approval_required` until your user approves it, unless it changes nothing.

Guide: [Configure a project](https://docs.promptguard.co/api-reference/configuration#policies)



## OpenAPI

````yaml /api-reference/openapi-developer.json patch /api/v1/projects/{project_id}/policies/{policy_id}
openapi: 3.1.0
info:
  title: PromptGuard Developer API
  description: >-
    Public API for developers to integrate PromptGuard security into their
    applications
  version: 1.0.0
servers:
  - url: https://api.promptguard.co
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/projects/{project_id}/policies/{policy_id}:
    patch:
      tags:
        - configuration
      summary: Update Policy
      description: >-
        Change a policy. What is left out stays as it is.


        With a CLI sign-in or a key marked for an agent, refused with

        `approval_required` until your user approves it, unless it changes
        nothing.


        Guide: [Configure a
        project](https://docs.promptguard.co/api-reference/configuration#policies)
      operationId: update_policy_api_v1_projects__project_id__policies__policy_id__patch
      parameters:
        - name: project_id
          in: path
          required: true
          schema:
            type: string
            title: Project Id
        - name: policy_id
          in: path
          required: true
          schema:
            type: string
            title: Policy Id
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
        - name: PromptGuard-Approval
          in: header
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 64
              - type: 'null'
            description: >-
              The `approval_id` of an `approval_required` refusal, once your
              user has approved it. Send the same method, path, query and body.
            title: Promptguard-Approval
          description: >-
            The `approval_id` of an `approval_required` refusal, once your user
            has approved it. Send the same method, path, query and body.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProjectPolicyUpdate'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyResponse'
              example:
                id: b2a7c1de-90f4-4a6e-8f5b-3c1d7e2a9f10
                user_id: 6a1f0c3e-7d2b-4c58-9e0a-1b2c3d4e5f60
                name: No codenames
                description: null
                policy_type: input_filter
                status: active
                priority: 100
                rules:
                  - condition: contains_text
                    action: block
                    value: Project Nightingale
                threat_types: []
                is_default: false
                triggered_count: 0
                project_id: 910b6423-8a12-4461-a6bf-9148d9b6b8e3
                system_prompt_details: null
                created_at: '2026-12-01T09:00:00Z'
                updated_at: '2026-12-01T09:00:00Z'
                enforced: true
                warnings: []
        '401':
          description: Missing, malformed, unknown, disabled or expired API key
          content:
            application/json:
              examples:
                missing_api_key:
                  summary: No X-API-Key header
                  value:
                    error:
                      message: >-
                        PromptGuard API key required. Please provide via
                        X-API-Key header.
                      type: authentication_error
                      code: missing_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#missing_api_key
                malformed_api_key:
                  summary: Not a pg_live_ key
                  value:
                    error:
                      message: Invalid API key format
                      type: authentication_error
                      code: invalid_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#invalid_api_key
                unknown_api_key:
                  summary: No such key
                  value:
                    error:
                      message: Invalid API key
                      type: authentication_error
                      code: invalid_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#invalid_api_key
                disabled_api_key:
                  summary: Key disabled
                  value:
                    error:
                      message: API key is disabled
                      type: authentication_error
                      code: disabled_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#disabled_api_key
                expired_api_key:
                  summary: Key expired
                  value:
                    error:
                      message: API key has expired
                      type: authentication_error
                      code: expired_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#expired_api_key
                grant_ended_api_key:
                  summary: Key minted through an MSP Grant that has ended
                  value:
                    error:
                      message: >-
                        API key was created through a managed service provider's
                        access, which has ended. An administrator of this
                        organization can create a new key.
                      type: authentication_error
                      code: grant_ended_api_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#grant_ended_api_key
                cli_sign_in_ended:
                  summary: CLI sign-in whose user's sessions were ended
                  value:
                    error:
                      message: >-
                        This CLI sign-in ended when your sessions did. Run
                        'promptguard login' to sign in again.
                      type: authentication_error
                      code: cli_sign_in_ended
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#cli_sign_in_ended
              schema:
                $ref: '#/components/schemas/AuthErrorEnvelope'
        '403':
          description: >-
            Refused by the key's scopes or the IP allowlist, or waiting for, or
            not covered by, its user's approval
          content:
            application/json:
              examples:
                scope_denied:
                  summary: The key's scopes exclude this endpoint
                  value:
                    error:
                      message: >-
                        This endpoint needs the `configuration:write` scope,
                        which this API key does not hold. Create a key that
                        includes it.
                      type: insufficient_scope
                      code: scope_denied
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#scope_denied
                      required_scope: configuration:write
                scan_only_credential:
                  summary: A scan-only device credential
                  value:
                    error:
                      message: This credential is scan-only; endpoint not permitted.
                      type: insufficient_scope
                      code: scope_denied
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#scope_denied
                read_only_key:
                  summary: A SIEM export key
                  value:
                    error:
                      message: >-
                        This is a read-only export key. It may only GET
                        /api/v1/alerts, /api/v1/audit-events,
                        /api/v1/audit-events/stream, /api/v1/interactions and
                        /api/v1/interactions/stream.
                      type: insufficient_scope
                      code: read_only_key
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#read_only_key
                ip_not_allowed:
                  summary: Caller IP outside the allowlist
                  value:
                    error:
                      message: Request IP is not in the organization's allowlist
                      type: permission_error
                      code: ip_not_allowed
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#ip_not_allowed
                ip_allowlist_error:
                  summary: Allowlist could not be checked
                  value:
                    error:
                      message: IP allowlist validation failed
                      type: permission_error
                      code: ip_allowlist_error
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#ip_allowlist_error
                approval_required:
                  summary: approval_required
                  value:
                    error:
                      code: approval_required
                      type: approval_required
                      message: >-
                        This change waits for your user's approval. Ask them to
                        open approval_url, then send the same request again with
                        the header PromptGuard-Approval:
                        0f8c2c1e-6f0b-4a6e-9b1d-3a1f7c9d2e54
                      approval_id: 0f8c2c1e-6f0b-4a6e-9b1d-3a1f7c9d2e54
                      approval_url: >-
                        https://app.promptguard.co/approvals/0f8c2c1e-6f0b-4a6e-9b1d-3a1f7c9d2e54
                      expires_at: '2026-11-30T12:30:00+00:00'
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_required
                approval_invalid:
                  summary: approval_invalid
                  value:
                    error:
                      code: approval_invalid
                      type: approval_invalid
                      message: This request is not the one that was approved.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_invalid
                approval_limit_reached:
                  summary: approval_limit_reached
                  value:
                    error:
                      code: approval_limit_reached
                      type: approval_limit_reached
                      message: >-
                        Your user already has 10 approvals waiting in this
                        organization, the most they may. Cancel one, or wait for
                        one to be decided or to expire.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_limit_reached
                approval_change_too_large:
                  summary: approval_change_too_large
                  value:
                    error:
                      code: approval_change_too_large
                      type: approval_change_too_large
                      message: >-
                        This request changes more than its user could be shown
                        to approve. Send it as several smaller ones.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_change_too_large
                approval_change_unshowable:
                  summary: approval_change_unshowable
                  value:
                    error:
                      code: approval_change_unshowable
                      type: approval_change_unshowable
                      message: >-
                        This request changes a value to one its user would read
                        as the same. Make the change in the PromptGuard
                        dashboard.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_change_unshowable
                approval_unavailable:
                  summary: approval_unavailable
                  value:
                    error:
                      code: approval_unavailable
                      type: approval_unavailable
                      message: >-
                        This change needs its user's approval, and this server
                        has no dashboard to approve it in. Make the change in
                        the PromptGuard dashboard that manages it.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#approval_unavailable
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorEnvelope'
        '429':
          description: Per-minute rate limit reached; retry after `retry_after` seconds
          content:
            application/json:
              examples:
                rate_limit_exceeded:
                  summary: Per-minute limit reached
                  value:
                    error:
                      message: >-
                        Rate limit exceeded: your plan allows 60 requests per
                        minute. Please retry later.
                      type: rate_limit_exceeded
                      code: rate_limit_exceeded
                      retry_after: 42
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#rate_limit_exceeded
              schema:
                $ref: '#/components/schemas/RateLimitErrorEnvelope'
        '503':
          description: An approved change could not be audited, so it was not made
          content:
            application/json:
              examples:
                agent_action_not_audited:
                  summary: Approved change not recorded
                  value:
                    error:
                      code: agent_action_not_audited
                      type: api_error
                      message: >-
                        The change could not be recorded in the audit log, so it
                        was not made. Send the request without the header to ask
                        again.
                      doc_url: >-
                        https://docs.promptguard.co/production/error-handling#agent_action_not_audited
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      externalDocs:
        description: 'Guide: Configure a project'
        url: https://docs.promptguard.co/api-reference/configuration#policies
components:
  schemas:
    ProjectPolicyUpdate:
      properties:
        name:
          anyOf:
            - type: string
              maxLength: 255
              minLength: 1
            - type: 'null'
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        policy_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Policy Type
        status:
          anyOf:
            - type: string
            - type: 'null'
          title: Status
        priority:
          anyOf:
            - type: integer
              maximum: 1000
              minimum: 1
            - type: 'null'
          title: Priority
        rules:
          anyOf:
            - items:
                $ref: '#/components/schemas/PolicyRule'
              type: array
            - type: 'null'
          title: Rules
        threat_types:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Threat Types
        system_prompt_details:
          anyOf:
            - type: string
            - type: 'null'
          title: System Prompt Details
      type: object
      title: ProjectPolicyUpdate
      description: A change to a policy, which stays on its project.
    PolicyResponse:
      properties:
        id:
          type: string
          title: Id
        user_id:
          type: string
          title: User Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        policy_type:
          type: string
          title: Policy Type
        status:
          type: string
          title: Status
        priority:
          type: integer
          title: Priority
        rules:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Rules
        threat_types:
          items:
            type: string
          type: array
          title: Threat Types
        is_default:
          type: boolean
          title: Is Default
        triggered_count:
          type: integer
          title: Triggered Count
        project_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Project Id
        system_prompt_details:
          anyOf:
            - type: string
            - type: 'null'
          title: System Prompt Details
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        enforced:
          type: boolean
          title: Enforced
          description: >-
            False for a policy of a type the engine does not enforce: a
            `rate_limit` policy saved before such policies were refused. Rate
            limits are set per API key (`rate_limit_per_minute`) and by the
            Plan.
        warnings:
          items:
            $ref: '#/components/schemas/PolicyWarning'
          type: array
          title: Warnings
      type: object
      required:
        - id
        - user_id
        - name
        - description
        - policy_type
        - status
        - priority
        - rules
        - threat_types
        - is_default
        - triggered_count
        - created_at
        - updated_at
        - enforced
      title: PolicyResponse
      description: Policy response schema
    AuthErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
          examples:
            - code: missing_api_key
              message: >-
                PromptGuard API key required. Please provide via X-API-Key
                header.
              type: authentication_error
      type: object
      required:
        - error
      title: AuthErrorEnvelope
    ErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorEnvelope
    ValidationErrorEnvelope:
      description: The developer API's 422 (`shared/infrastructure/framework_errors.py`).
      properties:
        error:
          $ref: '#/components/schemas/ValidationErrorDetail'
        detail:
          deprecated: true
          description: >-
            The same list as `error.details`, in FastAPI's old shape. Removed on
            2027-02-11; read `error.details`
          items:
            $ref: '#/components/schemas/ValidationErrorField'
          title: Detail
          type: array
      required:
        - error
        - detail
      title: ValidationErrorEnvelope
      type: object
      example:
        error:
          message: 'The request is invalid: body.messages: Field required'
          type: invalid_request_error
          code: invalid_request
          details:
            - type: missing
              loc:
                - body
                - messages
              msg: Field required
              input:
                direction: input
          error_id: 3f0b8c1e-6a0e-4d52-9a57-0c2a9a7f5b11
          doc_url: >-
            https://docs.promptguard.co/production/error-handling#invalid_request
        detail:
          - type: missing
            loc:
              - body
              - messages
            msg: Field required
            input:
              direction: input
    RateLimitErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/RateLimitErrorDetail'
      type: object
      required:
        - error
      title: RateLimitErrorEnvelope
    PolicyRule:
      properties:
        condition:
          type: string
          title: Condition
        action:
          $ref: '#/components/schemas/RuleAction'
        value:
          anyOf:
            - type: string
            - type: 'null'
          title: Value
      type: object
      required:
        - condition
        - action
      title: PolicyRule
      description: Single policy rule
    PolicyWarning:
      properties:
        code:
          type: string
          title: Code
        message:
          type: string
          title: Message
        rule_index:
          anyOf:
            - type: integer
            - type: 'null'
          title: Rule Index
        policy_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Policy Id
        policy_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Policy Name
      type: object
      required:
        - code
        - message
      title: PolicyWarning
      description: >-
        Something worth telling the author about, that does not stop the save.


        Warnings are advisory by design (see ``conflicts.py``): a create that
        fails

        because the server disliked the shape of a policy is a worse product
        than

        one that says what it noticed. ``code`` is the stable identifier the UI

        keys on; ``message`` is what a non-coder reads.
    ErrorDetail:
      properties:
        message:
          type: string
          title: Message
          description: Human-readable error description
        type:
          type: string
          title: Type
          description: Error category, e.g. 'authentication_error'
        code:
          type: string
          title: Code
          description: Machine-readable error code
        doc_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Doc Url
          description: >-
            The error catalogue's entry for `code` (cause and fix); present when
            the catalogue documents the code
        required_scope:
          anyOf:
            - type: string
            - type: 'null'
          title: Required Scope
          description: >-
            On `scope_denied`, the scope the endpoint needs, as
            `<group>:<level>`. Absent when no scope would do, as for a device
            credential.
        approval_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Approval Id
          description: >-
            On `approval_required`, what to send as `PromptGuard-Approval` once
            it is approved
        approval_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Approval Url
          description: On `approval_required`, the dashboard page your user approves it on
        expires_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Expires At
          description: On `approval_required`, when the approval lapses (ISO 8601)
      type: object
      required:
        - message
        - type
        - code
      title: ErrorDetail
    ValidationErrorDetail:
      properties:
        message:
          description: The failed fields, one line
          title: Message
          type: string
        type:
          description: '''invalid_request_error'''
          title: Type
          type: string
        code:
          description: '''invalid_request'''
          title: Code
          type: string
        details:
          description: Each field that failed
          items:
            $ref: '#/components/schemas/ValidationErrorField'
          title: Details
          type: array
        error_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Equals the X-Request-ID header
          title: Error Id
        doc_url:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            The error catalogue's entry for `code` (cause and fix); present when
            the catalogue documents the code
          title: Doc Url
      required:
        - message
        - type
        - code
        - details
      title: ValidationErrorDetail
      type: object
    ValidationErrorField:
      description: One field that failed validation, as FastAPI reports it.
      properties:
        loc:
          description: The field's path, e.g. ['body', 'messages']
          items:
            anyOf:
              - type: string
              - type: integer
          title: Loc
          type: array
        msg:
          description: What is wrong with it
          title: Msg
          type: string
        type:
          description: The kind of failure, e.g. 'missing'
          title: Type
          type: string
        input:
          default: null
          description: The value that was sent
          title: Input
        ctx:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          default: null
          description: The limit it broke, where there is one
          title: Ctx
      required:
        - loc
        - msg
        - type
      title: ValidationErrorField
      type: object
    RateLimitErrorDetail:
      properties:
        message:
          type: string
          title: Message
        type:
          type: string
          title: Type
          description: '''rate_limit_exceeded'''
        code:
          type: string
          title: Code
          description: '''rate_limit_exceeded'''
        retry_after:
          type: integer
          title: Retry After
          description: Seconds until the window resets; also `Retry-After`
        doc_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Doc Url
          description: >-
            The error catalogue's entry for `code` (cause and fix); present when
            the catalogue documents the code
      type: object
      required:
        - message
        - type
        - code
        - retry_after
      title: RateLimitErrorDetail
    RuleAction:
      type: string
      enum:
        - allow
        - block
        - redact
        - flag
      title: RuleAction
      description: |-
        What a custom policy rule does when its condition matches. The policy
        API accepts exactly these (``consumer/policies/schemas.py``).
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        PromptGuard API key for developer endpoints. Keys start with pg_live_
        and are created in the dashboard.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.