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

# Create Guardrail

> Creates a new guardrail rule for use within the TruGen AI system. Guardrails are workspace-scoped and reusable across agents - creating one does not attach it anywhere.



## OpenAPI

````yaml POST /ext/guardrail
openapi: 3.0.3
info:
  title: TruGen Developer Platform API
  version: 1.0.0
  description: OpenAPI specification for MCP endpoint
servers:
  - url: https://api.trugen.ai/v1
security: []
paths:
  /ext/guardrail:
    post:
      summary: Create a new Guardrail
      description: >-
        Creates a new guardrail rule for use within the TruGen AI system.
        Guardrails are workspace-scoped and reusable across agents - creating
        one does not attach it anywhere.
      operationId: createGuardrail
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: >-
                    Human-readable label. Also used to derive the permanent
                    `key` used at runtime (lowercased, punctuation replaced with
                    underscores, deduplicated with a numeric suffix on
                    collision).
                  example: Hate Speech Filter
                category:
                  type: string
                  description: >-
                    Free-text tag for grouping guardrails. No fixed list - any
                    string is accepted, including an empty one.
                  example: Content Safety
                prompt:
                  type: string
                  description: >-
                    The rule text the agent's LLM evaluates a user's message
                    against to decide whether this guardrail applies.
                  example: >-
                    Trigger when the user uses hateful, discriminatory, or
                    abusive language toward a person or group.
                response_message:
                  type: string
                  description: >-
                    Spoken to the user verbatim when this guardrail fires. If
                    omitted, the guardrail falls back to a moderation-endpoint
                    check instead of a canned response.
                  example: >-
                    I'm sorry, but I can't help with that. Let's keep things
                    respectful.
                callback_url:
                  type: string
                  format: uri
                  description: >-
                    Where a `guardrail_triggered` event is POSTed when this
                    guardrail fires. Must be a well-formed http(s):// URL if
                    present. Delivery is fire-and-forget - no retries.
                  example: https://yourapp.com/webhooks/guardrail
                is_active:
                  type: boolean
                  default: true
                  description: >-
                    Set to false to exclude this guardrail from live
                    conversations without deleting it.
              required:
                - name
                - prompt
            example:
              name: Hate Speech Filter
              category: Content Safety
              prompt: >-
                Trigger when the user uses hateful, discriminatory, or abusive
                language toward a person or group.
              response_message: >-
                I'm sorry, but I can't help with that. Let's keep things
                respectful.
              callback_url: https://yourapp.com/webhooks/guardrail
              is_active: true
      responses:
        '201':
          description: Guardrail created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    example: dfbaa3c6-1e90-43df-869a-b023896a198c
                  message:
                    type: string
                    example: Guardrail created
                required:
                  - id
                  - message
        '400':
          description: >-
            Invalid request body - missing name/prompt, or a malformed
            callback_url
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              examples:
                missingName:
                  value:
                    error: name is required
                missingPrompt:
                  value:
                    error: prompt is required
                badCallbackUrl:
                  value:
                    error: callback_url must be a valid http(s) URL
        '401':
          description: Unauthorized - missing or invalid API key
        '500':
          description: Internal server error
      security:
        - apiKeyAuth: []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````