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

# Create a rule

> Create a rule in a workspace.



## OpenAPI

````yaml post /workspaces/{workspaceId}/rules
openapi: 3.0.3
info:
  contact:
    email: support@openlayer.com
    name: Openlayer
    url: https://openlayer.com/
  description: API for interacting with the Openlayer server.
  title: Openlayer API
  version: '1.0'
  x-logo:
    url: https://logo.clearbit.com/openlayer.com
servers:
  - url: https://api.openlayer.com/v1
    description: Our prod backend
security:
  - bearerAuth: []
paths:
  /workspaces/{workspaceId}/rules:
    post:
      tags:
        - Governance
      summary: Create a rule
      description: Create a rule in a workspace.
      operationId: createRule
      parameters:
        - $ref: '#/components/parameters/workspaceId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - scope
                - type
              properties:
                name: 5803a17d-c594-44a2-9425-a42bac55bce3
                description: 4dcc72e1-391c-4f06-bf9b-969844088b1b
                scope: e32c8331-2e88-4f9b-8724-dc38ec33b452
                type: ed64fc36-f5dc-403e-aa2d-436aad600b75
                evidenceType: 9e269fac-9f5d-4bdb-967b-06d4fcb81e75
                renewalCadenceDays: 2adcbc09-f0cc-4a02-8f18-bb4d43674657
                automationType: 87cc02a0-e571-48da-9716-cfb49b856cf7
                automationParams: 7b11c098-f062-4dd6-be53-383ceebacf67
                deactivated: bca6432b-e3ce-4bd6-84d2-958d7856363e
                assigneeId: 82ed60e2-8ae4-4558-992e-7a6b422862db
                tagIds: e6dc5bc9-a030-4cc0-bb92-135363da77de
      responses:
        '201':
          description: >-
            Rule created. It belongs to no framework until you map it to one in
            the Openlayer app.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Rule'
        default:
          $ref: '#/components/responses/UnexpectedError'
      x-codeSamples:
        - lang: python
          source: |
            from openlayer import Openlayer

            client = Openlayer()

            rule = client.governance.rules.create(
                "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                name="Model card is published",
                scope="project",
                type="evidence",
                evidence_type="document",
                renewal_cadence_days=365,
            )
            print(rule.id)
        - lang: typescript
          source: >
            import Openlayer from 'openlayer';


            const client = new Openlayer();


            const rule = await
            client.governance.rules.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
            {
              name: 'Monitoring enabled',
              scope: 'project',
              type: 'platform',
              automationType: 'monitoring_mode_enabled',
              description: 'Each project must have Openlayer monitoring mode enabled.',
            });


            console.log(rule.id);
        - lang: go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/openlayer-ai/openlayer-go\"\n)\n\nclient := openlayer.NewClient()\nrule, err := client.Governance.Rules.New(\n\tcontext.TODO(),\n\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\topenlayer.GovernanceRuleNewParams{\n\t\tName:               openlayer.F(\"Model card is up to date\"),\n\t\tScope:              openlayer.F(openlayer.GovernanceRuleNewParamsScopeProject),\n\t\tType:               openlayer.F(openlayer.GovernanceRuleNewParamsTypeEvidence),\n\t\tEvidenceType:       openlayer.F(openlayer.GovernanceRuleNewParamsEvidenceTypeDocument),\n\t\tRenewalCadenceDays: openlayer.Int(90),\n\t},\n)\nif err != nil {\n\tpanic(err.Error())\n}\nfmt.Printf(\"%+v\\n\", rule.ID)\n"
        - lang: java
          source: >
            import com.openlayer.api.client.OpenlayerClient;

            import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;

            import com.openlayer.api.models.governance.rules.RuleCreateParams;

            import com.openlayer.api.models.governance.rules.RuleCreateResponse;


            OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();


            RuleCreateParams params = RuleCreateParams.builder()
                .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
                .name("Model risk assessment")
                .scope(RuleCreateParams.Scope.PROJECT)
                .type(RuleCreateParams.Type.EVIDENCE)
                .evidenceType(RuleCreateParams.EvidenceType.DOCUMENT)
                .renewalCadenceDays(90L)
                .build();
            RuleCreateResponse rule =
            client.governance().rules().create(params);
        - lang: ruby
          source: |
            require "openlayer"

            openlayer = Openlayer::Client.new(api_key: ENV["OPENLAYER_API_KEY"])

            rule = openlayer.governance.rules.create(
              "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              name: "Monitoring enabled",
              scope: :project,
              type: :platform,
              description: "Each project must have Openlayer monitoring mode enabled.",
              automation_type: "monitoring_mode_enabled"
            )

            puts(rule)
        - lang: curl
          source: |
            curl --request POST \
              --url https://api.openlayer.com/v1/workspaces/3fa85f64-5717-4562-b3fc-2c963f66afa6/rules \
              --header 'Authorization: Bearer <token>' \
              --header 'Content-Type: application/json' \
              --data '{
                "name": "Annual model risk review",
                "description": "Each high-risk project is reviewed and signed off once a year.",
                "scope": "project",
                "type": "evidence",
                "evidenceType": "document",
                "renewalCadenceDays": 365
              }'
components:
  parameters:
    workspaceId:
      name: workspaceId
      in: path
      description: The workspace id.
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    Rule:
      type: object
      description: >
        A single requirement Openlayer tracks. `platform` rules are evaluated
        automatically from the state of your workspace, and `evidence` rules are
        satisfied by attaching evidence. A rule can belong to several
        frameworks, or to none.
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          description: The rule id.
          example: 7c9a1e2b-3d4f-4a5b-8c6d-7e8f9a0b1c2d
        workspaceId:
          type: string
          format: uuid
          readOnly: true
          description: The id of the workspace the rule belongs to.
        name:
          type: string
          maxLength: 255
          description: The rule name.
          example: Monitoring enabled
        description:
          type: string
          nullable: true
          description: What the rule requires.
          example: Each project must have Openlayer monitoring mode enabled.
        scope:
          type: string
          enum:
            - project
            - workspace
          description: >
            Whether the rule is evaluated once for the whole workspace, or once
            per project the rule's frameworks apply to. Must be `project` for
            platform rules. Fixed once the rule is created.
          example: project
        type:
          type: string
          enum:
            - platform
            - evidence
          description: >
            `platform` rules are evaluated automatically from the state of your
            Openlayer workspace. `evidence` rules are satisfied by attaching
            evidence. Fixed once the rule is created.
          example: platform
        evidenceType:
          type: string
          nullable: true
          enum:
            - document
            - text
            - url
            - categoryValue
            - null
          description: >
            The kind of evidence that satisfies the rule. Set it for evidence
            rules; omit or `null` for platform rules. Fixed once the rule is
            created.
        renewalCadenceDays:
          type: integer
          nullable: true
          minimum: 1
          description: >
            How often evidence must be renewed, in days. Once evidence is older
            than this, the rule result becomes `due_soon` and then `failing`.
            The window restarts whenever evidence is attached. Omit or `null`
            for platform rules.
          example: 90
        automationType:
          type: string
          nullable: true
          description: >
            Which workspace signal a platform rule checks, for example
            `monitoring_mode_enabled`, `test_setup`, or `project_owner_set`. Set
            it for platform rules; omit or `null` for evidence rules. Fixed once
            the rule is created.
          example: monitoring_mode_enabled
        automationParams:
          type: object
          nullable: true
          additionalProperties: true
          description: >
            Configuration for the platform check, when the automation takes
            parameters. Omit or `null` for evidence rules. Fixed once the rule
            is created.
        deactivated:
          type: boolean
          default: false
          description: Whether the rule is excluded from compliance calculations.
        assigneeId:
          type: string
          format: uuid
          nullable: true
          description: The user responsible for satisfying the rule.
        tagIds:
          type: array
          nullable: true
          writeOnly: true
          description: >
            The ids of the rule tags to associate with the rule. Replaces the
            rule's tags. Read them back from `tags`, and list the tags available
            in the workspace with `GET /workspaces/{workspaceId}/rule-tags`.
          items:
            type: string
            format: uuid
        tags:
          type: array
          nullable: true
          readOnly: true
          description: The rule tags associated with the rule.
          items:
            $ref: '#/components/schemas/RuleTag'
        frameworks:
          type: array
          readOnly: true
          description: The frameworks that include this rule.
          items:
            type: object
            required:
              - id
              - name
              - avatar
              - builtInSlug
              - enabled
            properties:
              id: 375f31da-dcc9-420e-b9c5-d63b6bda8c76
              name: 7e080bcf-26a2-4b1e-84ba-fe303e714c01
              avatar: df63df6f-dcf6-46fe-af6f-00a9c24c4d6f
              builtInSlug: b2bda309-05e0-4d3e-b2c8-bc433192e78c
              enabled: 6e2f4260-23ed-4f91-80fd-7d8b97b49be0
        results:
          type: array
          readOnly: true
          description: >
            The rule's results, one per entity the rule is evaluated against.
            Only returned when `includeResults` is `true`.
          items:
            $ref: '#/components/schemas/RuleResult'
        resultsSummary:
          type: object
          nullable: true
          readOnly: true
          description: >
            Pass-rate counts across all of the rule's entities, independent of
            any status filter applied to the request.
          properties:
            passing:
              type: integer
              minimum: 0
            total:
              type: integer
              minimum: 0
        immutable:
          type: boolean
          readOnly: true
          description: >
            Whether the rule is managed by Openlayer. These rules can't be
            renamed or deleted; set `deactivated` to exclude one from compliance
            instead.
        dateCreated:
          type: string
          format: date-time
          readOnly: true
          description: The creation date.
          example: '2026-03-22T11:31:01.185Z'
        dateUpdated:
          type: string
          format: date-time
          readOnly: true
          description: The last update date.
          example: '2026-03-22T11:31:01.185Z'
      required:
        - id
        - workspaceId
        - name
        - scope
        - type
        - dateCreated
        - dateUpdated
    RuleTag:
      type: object
      description: >-
        A label that groups rules across frameworks, for example by team or
        control family.
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          description: The rule tag id.
          example: 6e8a0c2d-4f5b-4a3c-9d7e-8f0a1b2c3d4e
        workspaceId:
          type: string
          format: uuid
          readOnly: true
          description: The id of the workspace the tag belongs to.
        creatorId:
          type: string
          format: uuid
          nullable: true
          readOnly: true
          description: >-
            The user who created the tag. `null` for tags that ship with
            Openlayer.
        name:
          type: string
          maxLength: 255
          description: The tag name.
          example: Evaluation
        color:
          type: string
          maxLength: 50
          nullable: true
          description: The color the tag is displayed with.
        immutable:
          type: boolean
          default: false
          readOnly: true
          description: >-
            Whether the tag is managed by Openlayer. These tags can't be
            deleted.
        dateCreated:
          type: string
          format: date-time
          readOnly: true
          description: The creation date.
          example: '2026-03-22T11:31:01.185Z'
        dateUpdated:
          type: string
          format: date-time
          readOnly: true
          description: The last update date.
          example: '2026-03-22T11:31:01.185Z'
      required:
        - id
        - workspaceId
        - creatorId
        - name
        - immutable
        - dateCreated
        - dateUpdated
    RuleResult:
      type: object
      description: >
        The compliance status of one rule for one entity: a project for
        project-scoped rules, or the workspace for workspace-scoped rules.
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          description: The rule result id.
          example: 5b7d9f1a-2c3e-4d5f-8a6b-9c0d1e2f3a4b
        workspaceId:
          type: string
          format: uuid
          readOnly: true
          description: The id of the workspace the rule result belongs to.
        ruleId:
          type: string
          format: uuid
          readOnly: true
          description: The rule this result belongs to.
        projectId:
          type: string
          format: uuid
          nullable: true
          readOnly: true
          description: >-
            The project this result was evaluated for. `null` for
            workspace-scoped rules.
        status:
          type: string
          enum:
            - running
            - passing
            - failing
            - skipped
            - error
            - pending
            - due_soon
          description: >
            The compliance status of the rule for this entity. Computed by
            Openlayer and can't be set directly.
          example: passing
        statusMessage:
          type: string
          nullable: true
          description: A human-readable explanation of the status.
        dateLastEvaluated:
          type: string
          format: date-time
          nullable: true
          readOnly: true
          description: When the rule was last evaluated. Platform rules only.
        dateOfNextEvaluation:
          type: string
          format: date-time
          nullable: true
          readOnly: true
          description: When the rule will next be evaluated. Platform rules only.
        dateOfLatestEvidence:
          type: string
          format: date-time
          nullable: true
          readOnly: true
          description: >-
            When the most recent piece of evidence was attached. Evidence rules
            only.
        dateOfRenewal:
          type: string
          format: date-time
          nullable: true
          readOnly: true
          description: >-
            When the evidence must be renewed. Evidence rules with a renewal
            cadence only.
        deactivated:
          type: boolean
          default: false
          description: >
            Whether this result is excluded from compliance calculations.
            Excludes just this result, without deactivating the rule everywhere.
        deactivatedReason:
          type: string
          nullable: true
          description: >-
            Why the result was excluded. Required when setting `deactivated` to
            `true`.
        assigneeId:
          type: string
          format: uuid
          nullable: true
          description: The user responsible for this result.
        blockedBy:
          type: array
          default: []
          description: Rule results that must pass before this one can be satisfied.
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              status: c8d6dae9-615f-4f41-9ec2-c7ddf3c322a0
        blocking:
          type: array
          default: []
          description: Rule results that this one blocks.
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              status: c8d6dae9-615f-4f41-9ec2-c7ddf3c322a0
        dateCreated:
          type: string
          format: date-time
          readOnly: true
          description: The creation date.
          example: '2026-03-22T11:31:01.185Z'
        dateUpdated:
          type: string
          format: date-time
          readOnly: true
          description: The last update date.
          example: '2026-03-22T11:31:01.185Z'
      required:
        - id
        - workspaceId
        - ruleId
        - status
        - deactivated
        - dateCreated
        - dateUpdated
  responses:
    UnexpectedError:
      description: Unexpected error.
      content:
        application/json:
          schema:
            type: object
            required:
              - code
              - error
            properties:
              code:
                type: integer
                format: int32
              error:
                type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your workspace API key. See [Find your API
        key](https://www.openlayer.com/docs/workspace-and-projects/find-your-api-key)
        for more information.

````

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