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

# Guard Content

> Scan messages for security threats without proxying to an LLM.

This is the primary endpoint for auto-instrumentation and framework
callback integrations. It runs the same policy engine, ML ensemble,
preset configuration, custom rules, and entitlements checks as the
proxy pipeline.

Use ``direction="input"`` before sending messages to the LLM and
``direction="output"`` after receiving a response.

Returns a decision of ``allow``, ``block``, or ``redact`` along with
detailed threat information and optional redacted messages.



## OpenAPI

````yaml /api-reference/openapi-developer.json post /api/v1/guard
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.dev
    description: Production API
  - url: https://staging-api.promptguard.dev
    description: Staging API
  - url: http://localhost:8080
    description: Local Development
security:
  - ApiKeyAuth: []
paths:
  /api/v1/guard:
    post:
      tags:
        - guard
      summary: Guard Content
      description: |-
        Scan messages for security threats without proxying to an LLM.

        This is the primary endpoint for auto-instrumentation and framework
        callback integrations. It runs the same policy engine, ML ensemble,
        preset configuration, custom rules, and entitlements checks as the
        proxy pipeline.

        Use ``direction="input"`` before sending messages to the LLM and
        ``direction="output"`` after receiving a response.

        Returns a decision of ``allow``, ``block``, or ``redact`` along with
        detailed threat information and optional redacted messages.
      operationId: guard_content_api_v1_guard_post
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GuardRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GuardResponse'
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthErrorEnvelope'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Monthly quota exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QuotaErrorEnvelope'
components:
  schemas:
    GuardRequest:
      properties:
        messages:
          items:
            $ref: '#/components/schemas/GuardMessage'
          type: array
          minItems: 1
          title: Messages
          description: Messages to scan (OpenAI-style message array)
        direction:
          type: string
          pattern: ^(input|output)$
          title: Direction
          description: 'Scan direction: ''input'' (pre-LLM) or ''output'' (post-LLM)'
          default: input
        model:
          anyOf:
            - type: string
            - type: 'null'
          title: Model
          description: Model being used (for logging)
        context:
          anyOf:
            - $ref: '#/components/schemas/GuardContext'
            - type: 'null'
          description: Optional framework context
        retrieved_context:
          anyOf:
            - items:
                $ref: '#/components/schemas/ContextDoc'
              type: array
            - type: 'null'
          title: Retrieved Context
          description: >-
            RAG-retrieved documents to scan for knowledge poisoning. Each
            document is individually scanned before being merged into the LLM
            prompt. Optional; backwards-compatible.
        media:
          anyOf:
            - items:
                $ref: '#/components/schemas/MediaPartSchema'
              type: array
            - type: 'null'
          title: Media
          description: >-
            Media attachments to scan for steganographic payloads, adversarial
            patches, and font injection. Optional.
      type: object
      required:
        - messages
      title: GuardRequest
      description: Request body for the guard endpoint.
    GuardResponse:
      properties:
        decision:
          type: string
          title: Decision
          description: 'Policy decision: ''allow'', ''block'', or ''redact'''
        event_id:
          type: string
          title: Event Id
          description: Unique event identifier for tracking
        confidence:
          type: number
          title: Confidence
          description: Confidence score of the decision
        threat_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Threat Type
          description: Primary threat type detected
        redacted_messages:
          anyOf:
            - items:
                $ref: '#/components/schemas/GuardMessage'
              type: array
            - type: 'null'
          title: Redacted Messages
          description: Redacted messages (only present when decision='redact')
        threats:
          items:
            $ref: '#/components/schemas/ThreatDetail'
          type: array
          title: Threats
          description: Detailed threat breakdown
        latency_ms:
          type: number
          title: Latency Ms
          description: Processing time in milliseconds
      type: object
      required:
        - decision
        - event_id
        - confidence
        - latency_ms
      title: GuardResponse
      description: Response from the guard endpoint.
    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
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    QuotaErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/QuotaErrorDetail'
      type: object
      required:
        - error
      title: QuotaErrorEnvelope
    GuardMessage:
      properties:
        role:
          type: string
          title: Role
          description: 'Message role: system, user, assistant, tool'
        content:
          type: string
          title: Content
          description: Message text content
          default: ''
      type: object
      required:
        - role
      title: GuardMessage
      description: A single message in the conversation.
    GuardContext:
      properties:
        framework:
          anyOf:
            - type: string
            - type: 'null'
          title: Framework
          description: Framework name, e.g. 'langchain', 'crewai'
        chain_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Chain Name
          description: LangChain chain name or pipeline identifier
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
          description: Agent identifier for multi-agent systems
        session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Id
          description: Session identifier for multi-turn tracking
        tool_calls:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Tool Calls
          description: Tool calls in this turn
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
          description: Arbitrary framework-specific metadata
      type: object
      title: GuardContext
      description: Optional rich context from framework integrations.
    ContextDoc:
      properties:
        content:
          type: string
          title: Content
          description: Document text content
        source:
          anyOf:
            - type: string
            - type: 'null'
          title: Source
          description: Source identifier (URL, doc ID, etc.)
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
          description: Extra metadata
      type: object
      required:
        - content
      title: ContextDoc
      description: A document retrieved by a RAG pipeline to be scanned for poisoning.
    MediaPartSchema:
      properties:
        type:
          type: string
          pattern: ^(image|audio)$
          title: Type
          description: 'Media type: ''image'' or ''audio'''
        mime_type:
          type: string
          title: Mime Type
          description: MIME type, e.g. 'image/png', 'audio/wav'
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          description: URL to fetch the media from
        base64:
          anyOf:
            - type: string
            - type: 'null'
          title: Base64
          description: Base64-encoded media data
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
          description: Extra metadata
      type: object
      required:
        - type
        - mime_type
      title: MediaPartSchema
      description: >-
        A media attachment to be scanned for steganographic/adversarial
        payloads.
    ThreatDetail:
      properties:
        type:
          type: string
          title: Type
        confidence:
          type: number
          title: Confidence
        details:
          type: string
          title: Details
      type: object
      required:
        - type
        - confidence
        - details
      title: ThreatDetail
      description: Individual threat found during scanning.
    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
      type: object
      required:
        - message
        - type
        - code
      title: ErrorDetail
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    QuotaErrorDetail:
      properties:
        message:
          type: string
          title: Message
        type:
          type: string
          title: Type
          description: '''quota_exceeded'' or ''spending_limit_exceeded'''
        code:
          type: string
          title: Code
          description: '''monthly_quota_exceeded'' or ''spending_limit_exceeded'''
        current_plan:
          type: string
          title: Current Plan
        requests_used:
          type: integer
          title: Requests Used
        requests_limit:
          type: integer
          title: Requests Limit
        upgrade_url:
          type: string
          title: Upgrade Url
        retry_after:
          anyOf:
            - type: integer
            - type: 'null'
          title: Retry After
      type: object
      required:
        - message
        - type
        - code
        - current_plan
        - requests_used
        - requests_limit
        - upgrade_url
      title: QuotaErrorDetail
  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.

````