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

# Enforce a policy

> Evaluates a set of messages against the specified policy and returns guardrail decisions.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/anthale/openapi.documented.yml post /organizations/policies/{policy_identifier}/enforce
openapi: 3.1.0
info:
  title: Anthale
  description: Deterministic guardrails for LLM applications. Ship AI with confidence.
  termsOfService: https://anthale.com/legal/terms-of-service
  contact:
    name: Anthale Support
    url: https://anthale.com/support
  license:
    name: Apache-2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 0.0.1
servers:
  - url: https://api.anthale.com
security: []
tags:
  - name: Policies
    description: Policy lifecycle management.
paths:
  /organizations/policies/{policy_identifier}/enforce:
    post:
      tags:
        - Policies
      summary: Enforce a policy
      description: >-
        Evaluates a set of messages against the specified policy and returns
        guardrail decisions.
      operationId: organizations.policies.enforce
      parameters:
        - name: policy_identifier
          in: path
          required: true
          schema:
            type: string
            format: uuid
            description: The policy identifier to enforce.
            title: Policy Identifier
            example: a90e34d6-41af-432f-a6ae-046598df4539
          description: The policy identifier to enforce.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PolicyEnforceRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyEnforcementResult'
          headers:
            Request-Id:
              $ref: '#/components/headers/Request-Id'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimit-Limit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimit-Remaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimit-Reset'
        '401':
          description: Missing, invalid, or disabled API key.
          headers:
            WWW-Authenticate:
              description: API key authentication challenge
              schema:
                type: string
              example: Bearer <api-key>
            Request-Id:
              $ref: '#/components/headers/Request-Id'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimit-Limit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimit-Remaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimit-Reset'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthaleErrorResponse'
              example:
                error:
                  title: Unauthorized
                  machineCode: Unauthorized
                  message: Authentication is required to access this resource.
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthaleErrorResponse'
          headers:
            Request-Id:
              $ref: '#/components/headers/Request-Id'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimit-Limit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimit-Remaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimit-Reset'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - ApiKeyBearer: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Anthale from 'anthale';

            const client = new Anthale({
              apiKey: process.env['ANTHALE_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.organizations.policies.enforce(
              'a90e34d6-41af-432f-a6ae-046598df4539',
              {
                direction: 'input',
                messages: [{ content: 'Can you summarize the plot of Interstellar?', role: 'user' }],
              },
            );

            console.log(response.action);
        - lang: Python
          source: |-
            import os
            from anthale import Anthale

            client = Anthale(
                api_key=os.environ.get("ANTHALE_API_KEY"),  # This is the default and can be omitted
            )
            response = client.organizations.policies.enforce(
                policy_identifier="a90e34d6-41af-432f-a6ae-046598df4539",
                direction="input",
                messages=[{
                    "content": "Can you summarize the plot of Interstellar?",
                    "role": "user",
                }],
            )
            print(response.action)
components:
  schemas:
    PolicyEnforceRequest:
      properties:
        direction:
          $ref: '#/components/schemas/PolicyGuardrailDirection'
          description: Whether to evaluate input or output messages against the policy.
          example: input
        includeEvaluations:
          type: boolean
          description: Whether to include evaluation details in the response.
          default: false
          example: false
        messages:
          items:
            $ref: '#/components/schemas/PolicyEnforceMessage'
          type: array
          minItems: 1
          description: Ordered list of messages that compose the conversation to evaluate.
        metadata:
          additionalProperties: true
          type: object
          description: Optional contextual metadata forwarded to guardrails.
          x-stainless-any: true
      additionalProperties: false
      type: object
      required:
        - direction
        - messages
      description: Policy enforcer request schema.
    PolicyEnforcementResult:
      properties:
        enforcerIdentifier:
          type: string
          format: uuid
          description: Identifier of the policy enforcer that processed the request.
          example: 8e9671f0-2365-4df9-bca0-2cc3cc61b0c9
        action:
          $ref: '#/components/schemas/PolicyEnforcementResultAction'
          description: Overall action decided by the policy (allow, detect, redact, block).
          example: block
        evaluations:
          items:
            oneOf:
              - $ref: '#/components/schemas/PromptInjectionEvaluation'
              - $ref: '#/components/schemas/ContentSafetyEvaluation'
              - $ref: '#/components/schemas/DataLeakageEvaluation'
              - $ref: '#/components/schemas/ContextSafetyEvaluation'
            discriminator:
              propertyName: guardrailKey
              mapping:
                content-moderation:
                  $ref: '#/components/schemas/ContentSafetyEvaluation'
                data-leakage-prevention:
                  $ref: '#/components/schemas/DataLeakageEvaluation'
                prompt-injection-protection:
                  $ref: '#/components/schemas/PromptInjectionEvaluation'
                topic-control:
                  $ref: '#/components/schemas/ContextSafetyEvaluation'
          type: array
          description: Per-guardrail evaluation results.
      additionalProperties: false
      type: object
      required:
        - enforcerIdentifier
        - action
      description: Policy enforcement response schema.
    AnthaleErrorResponse:
      type: object
      description: Standardized error envelope.
      required:
        - error
      additionalProperties: false
      properties:
        error:
          type: object
          required:
            - title
            - machineCode
            - message
          additionalProperties: false
          properties:
            title:
              type: string
              description: Human-readable error title.
            machineCode:
              type: string
              description: Machine-friendly error code.
            message:
              type: string
              description: Detailed human-readable error message.
            details:
              type:
                - object
                - 'null'
              description: Optional structured details about the error.
              additionalProperties: true
    PolicyGuardrailDirection:
      type: string
      enum:
        - input
        - output
      description: Enum representing possible policy guardrail direction values.
    PolicyEnforceMessage:
      properties:
        role:
          $ref: '#/components/schemas/PolicyEnforcementMessageRole'
          description: Message role within the conversation.
          example: user
        content:
          description: Raw text or a list of typed text blocks composing the message.
          oneOf:
            - type: string
              description: Message provided as a single text string.
              x-stainless-variantName: text
              example: Can you summarize the plot of Interstellar?
            - items:
                $ref: '#/components/schemas/PolicyEnforceTextMessage'
              type: array
              minItems: 1
              description: Message provided as ordered text blocks with metadata.
              x-stainless-variantName: blocks
              example:
                - text: Can you summarize the plot of Interstellar?
                  type: text
                - text: Include sentiment if possible.
                  type: text
      additionalProperties: false
      type: object
      required:
        - role
        - content
      description: Policy enforcer message request schema.
    PolicyEnforcementResultAction:
      type: string
      enum:
        - block
        - redact
        - detect
        - allow
      description: Enum representing possible policy enforcement result actions.
    PromptInjectionEvaluation:
      properties:
        guardrailKey:
          type: string
          const: prompt-injection-protection
          maxLength: 256
          minLength: 1
          description: Guardrail key that produced this evaluation.
          example: prompt-injection-protection
        action:
          $ref: '#/components/schemas/PolicyEnforcementResultAction'
          description: Action suggested by this guardrail (allow, detect, redact, block).
          example: block
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Overall confidence score.
          example: 0.91
        threads:
          items:
            $ref: '#/components/schemas/PromptInjectionThread'
          type: array
          minItems: 0
          description: Evidence or reasoning threads generated by the guardrail.
        metadata:
          additionalProperties: true
          type: object
          description: Additional guardrail-specific metadata.
          x-stainless-any: true
      additionalProperties: false
      type: object
      required:
        - guardrailKey
        - action
        - score
      description: Evaluation payload for prompt injection guardrail.
    ContentSafetyEvaluation:
      properties:
        guardrailKey:
          type: string
          const: content-moderation
          maxLength: 256
          minLength: 1
          description: Guardrail key that produced this evaluation.
          example: content-moderation
        action:
          $ref: '#/components/schemas/PolicyEnforcementResultAction'
          description: Action suggested by this guardrail (allow, detect, redact, block).
          example: allow
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Overall confidence score.
          example: 0.91
        threads:
          items:
            $ref: '#/components/schemas/ContentSafetyThread'
          type: array
          minItems: 0
          description: Evidence or reasoning threads generated by the guardrail.
        metadata:
          additionalProperties: true
          type: object
          description: Additional guardrail-specific metadata.
          x-stainless-any: true
      additionalProperties: false
      type: object
      required:
        - guardrailKey
        - action
        - score
      description: Evaluation payload for content safety guardrail.
    DataLeakageEvaluation:
      properties:
        guardrailKey:
          type: string
          const: data-leakage-prevention
          maxLength: 256
          minLength: 1
          description: Guardrail key that produced this evaluation.
          example: data-leakage-prevention
        action:
          $ref: '#/components/schemas/PolicyEnforcementResultAction'
          description: Action suggested by this guardrail (allow, detect, redact, block).
          example: redact
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Overall confidence score.
          example: 0.91
        threads:
          items:
            $ref: '#/components/schemas/DataLeakageThread'
          type: array
          minItems: 0
          description: Evidence or reasoning threads generated by the guardrail.
        metadata:
          additionalProperties: true
          type: object
          description: Additional guardrail-specific metadata.
          x-stainless-any: true
      additionalProperties: false
      type: object
      required:
        - guardrailKey
        - action
        - score
      description: Evaluation payload for data leakage guardrail.
    ContextSafetyEvaluation:
      properties:
        guardrailKey:
          type: string
          const: topic-control
          maxLength: 256
          minLength: 1
          description: Guardrail key that produced this evaluation.
          example: topic-control
        action:
          $ref: '#/components/schemas/PolicyEnforcementResultAction'
          description: Action suggested by this guardrail (allow, detect, redact, block).
          example: detect
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Overall confidence score.
          example: 0.91
        threads:
          items:
            $ref: '#/components/schemas/ContextSafetyThread'
          type: array
          minItems: 0
          description: Evidence or reasoning threads generated by the guardrail.
        metadata:
          additionalProperties: true
          type: object
          description: Additional guardrail-specific metadata.
          x-stainless-any: true
      additionalProperties: false
      type: object
      required:
        - guardrailKey
        - action
        - score
      description: Evaluation payload for context safety guardrail.
    PolicyEnforcementMessageRole:
      type: string
      enum:
        - system
        - user
        - assistant
        - tool
      description: Enum representing possible message role values.
    PolicyEnforceTextMessage:
      properties:
        type:
          $ref: '#/components/schemas/PolicyEnforcementMessageType'
          description: Content block type.
          example: text
        text:
          type: string
          description: Message text content.
          example: Can you summarize the plot of Interstellar?
      additionalProperties: false
      type: object
      required:
        - type
        - text
      description: Policy enforcer text message request schema.
    PromptInjectionThread:
      properties:
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Confidence score for this detection.
          example: 0.88
        messageIdentifier:
          type: integer
          minimum: 0
          description: Index of the message containing the issue.
          example: 0
        contentIdentifier:
          type: integer
          minimum: 0
          description: Index of the chunk/part within the message.
          example: 1
      additionalProperties: false
      type: object
      required:
        - score
        - messageIdentifier
        - contentIdentifier
      description: Thread details for prompt injection guardrail.
    ContentSafetyThread:
      properties:
        category:
          $ref: '#/components/schemas/ContentSafetyGuardrailCategory'
          description: Content safety category hit by the message.
          example: hate
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Confidence score for the category.
          example: 0.91
        messageIdentifier:
          type: integer
          minimum: 0
          description: Index of the message containing the issue.
          example: 2
        contentIdentifier:
          type: integer
          minimum: 0
          description: Index of the chunk/part within the message.
          example: 0
      additionalProperties: false
      type: object
      required:
        - category
        - score
        - messageIdentifier
        - contentIdentifier
      description: Thread details for content safety guardrail.
    DataLeakageThread:
      properties:
        category:
          $ref: '#/components/schemas/DataLeakageGuardrailCategory'
          description: Detected PII/secret category (email, phone, etc).
          example: email
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Confidence score for the detection.
          example: 0.95
        span:
          type: string
          description: Detected span of text that triggered the guardrail.
          example: example@anthale.com
        messageIdentifier:
          type: integer
          minimum: 0
          description: Index of the message containing the leak.
          example: 3
        contentIdentifier:
          type: integer
          minimum: 0
          description: Index of the chunk/part within the message.
          example: 1
      additionalProperties: false
      type: object
      required:
        - category
        - score
        - span
        - messageIdentifier
        - contentIdentifier
      description: Thread details for data leakage guardrail.
    ContextSafetyThread:
      properties:
        topic:
          type: string
          description: Topic label that was flagged.
          example: Politics
        score:
          type: number
          maximum: 1
          minimum: 0
          description: Confidence score for the topic.
          example: 0.85
        messageIdentifier:
          type: integer
          minimum: 0
          description: Index of the message containing the issue.
          example: 1
        contentIdentifier:
          type: integer
          minimum: 0
          description: Index of the chunk/part within the message.
          example: 2
      additionalProperties: false
      type: object
      required:
        - topic
        - score
        - messageIdentifier
        - contentIdentifier
      description: Thread details for context safety guardrail.
    PolicyEnforcementMessageType:
      type: string
      enum:
        - text
        - document
        - image
        - audio
        - video
      description: Enum representing possible message type values.
    ContentSafetyGuardrailCategory:
      type: string
      enum:
        - hate
        - crime
        - sexual
        - violence
      description: Content safety guardrail categories.
    DataLeakageGuardrailCategory:
      type: string
      enum:
        - name
        - email
        - phone
        - address
        - location
        - date
        - ssn
        - credit_card
        - bank_account
        - id_number
        - ip_address
        - url
        - username
        - password
        - api_key
        - organization
        - other
      description: Data leakage guardrail categories.
  headers:
    Request-Id:
      description: Correlation identifier generated for every request (UUID v4).
      schema:
        type: string
        format: uuid
      example: ec882cd8-be89-41ac-881b-7fef74545313
    RateLimit-Limit:
      description: Maximum requests allowed in the current rate-limit window.
      schema:
        type: integer
        minimum: 0
      example: 1000
    RateLimit-Remaining:
      description: Requests remaining in the current rate-limit window.
      schema:
        type: integer
        minimum: 0
      example: 997
    RateLimit-Reset:
      description: Seconds until the current rate-limit window resets.
      schema:
        type: integer
        minimum: 0
      example: 42
    Retry-After:
      description: Seconds to wait before retrying after a 429 response.
      schema:
        type: integer
        minimum: 0
      example: 60
  responses:
    TooManyRequests:
      description: Rate limit exceeded.
      headers:
        Request-Id:
          $ref: '#/components/headers/Request-Id'
        RateLimit-Limit:
          $ref: '#/components/headers/RateLimit-Limit'
        RateLimit-Remaining:
          $ref: '#/components/headers/RateLimit-Remaining'
        RateLimit-Reset:
          $ref: '#/components/headers/RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthaleErrorResponse'
          example:
            error:
              title: TooManyRequests
              machineCode: TooManyRequestsError
              message: Rate limit exceeded. Please try again later.
    InternalServerError:
      description: An unexpected server-side error occurred.
      headers:
        Request-Id:
          $ref: '#/components/headers/Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthaleErrorResponse'
          example:
            error:
              title: Internal Server Error
              machineCode: InternalServerError
              message: An unexpected error occurred.
  securitySchemes:
    ApiKeyBearer:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Send an organization API key in the `Authorization` header as `Bearer
        <api_key>`.

````