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

# Create Rating Revision Form Logic

> Creates a new form-logic rule in the rating engine revision's config JSON
(`rating_engine_revisions.config.policyFormLogicConfigs`). Rules determine
which forms are attached to policies or quotes based on a `shouldAdd`
expression evaluated during rating.

The `ratingEngineRevisionId` must reference an existing, non-deleted
revision owned by this company.

**Required permission:** `company:update`




## OpenAPI

````yaml /openapi/generated-external-api.yaml post /api/external/companies/{companyId}/configuration/rating/form-logic
openapi: 3.0.3
info:
  title: AI Insurance External API
  description: External API for AI Insurance platform
  version: 1.0.0
  contact:
    email: support@aiinsurance.io
servers:
  - url: https://app.aiinsurance.io
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/external/companies/{companyId}/configuration/rating/form-logic:
    post:
      tags:
        - Configuration Rating Form Logic
      summary: Create Rating Revision Form Logic
      description: >
        Creates a new form-logic rule in the rating engine revision's config
        JSON

        (`rating_engine_revisions.config.policyFormLogicConfigs`). Rules
        determine

        which forms are attached to policies or quotes based on a `shouldAdd`

        expression evaluated during rating.


        The `ratingEngineRevisionId` must reference an existing, non-deleted

        revision owned by this company.


        **Required permission:** `company:update`
      operationId: createRatingRevisionFormLogic
      parameters:
        - $ref: '#/components/parameters/companyId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRatingRevisionFormLogicRequest'
            examples:
              simpleLeaf:
                summary: Minimal request — attach a specific form for policies
                value:
                  ratingEngineRevisionId: e06153b8-53c8-4305-bc23-0b67450ec450
                  revisionStrategy: UpdateExistingRevision
                  ruleName: Attach Certificate of Insurance
                  rank: 1
                  step: policies
                  shouldAdd:
                    leftKey: form.number
                    operator: '='
                    rightValue: FM-0001
              nested:
                summary: Nested AND/OR expression applying to both policies and quotes
                value:
                  ratingEngineRevisionId: e06153b8-53c8-4305-bc23-0b67450ec450
                  revisionStrategy: UpdateExistingRevision
                  ruleName: Attach state-specific endorsement
                  rank: 2
                  step:
                    - policies
                    - quotes
                  shouldAdd:
                    operator: AND
                    conditions:
                      - leftKey: form.number
                        operator: '='
                        rightValue: FM-0002
                      - operator: OR
                        conditions:
                          - leftKey: policy.data.state
                            operator: '='
                            rightValue: CA
                          - leftKey: policy.data.state
                            operator: '='
                            rightValue: NY
              some:
                summary: >-
                  SOME — attach a form when any coverage matches a nested
                  expression
                value:
                  ratingEngineRevisionId: e06153b8-53c8-4305-bc23-0b67450ec450
                  revisionStrategy: UpdateExistingRevision
                  ruleName: Attach GL supplement when a GL coverage is present
                  rank: 3
                  shouldAdd:
                    operator: AND
                    conditions:
                      - leftKey: form.number
                        operator: '='
                        rightValue: FM-0050
                      - leftKey: coverages
                        operator: SOME
                        rightValue:
                          leftKey: coverageTypeId
                          operator: '='
                          rightValue: general_liability
      responses:
        '201':
          description: Form-logic rule created successfully
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                properties:
                  id:
                    type: string
                    format: uuid
                    description: The server-generated ID of the created rule
              examples:
                success:
                  summary: Rule created
                  value:
                    id: bc6a626e-7a96-49fd-b477-2b18cf189a0d
        '400':
          description: Bad Request - Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                emptyRuleName:
                  summary: Empty rule name
                  value:
                    error:
                      code: InvalidProperties
                      message: 'ruleName: The value is an empty string'
                      details:
                        - field: ruleName
                          message: The value is an empty string
                invalidShouldAdd:
                  summary: Malformed shouldAdd expression
                  value:
                    error:
                      code: InvalidProperties
                      message: >-
                        shouldAdd: The value did not match any of the expected
                        validations
                      details:
                        - field: shouldAdd
                          message: >-
                            The value did not match any of the expected
                            validations
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                revisionNotFound:
                  summary: >-
                    Rating engine revision does not exist or does not belong to
                    this company
                  value:
                    error:
                      code: NotFoundError
                      message: >-
                        Rating engine revision not found:
                        e06153b8-53c8-4305-bc23-0b67450ec450
        '500':
          $ref: '#/components/responses/InternalServerError'
        '501':
          description: Not Implemented
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                notImplemented:
                  summary: CreateNewRevision is not yet implemented
                  value:
                    error:
                      code: NotImplemented
                      message: CreateNewRevision is not yet implemented
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
  schemas:
    CreateRatingRevisionFormLogicRequest:
      type: object
      description: >-
        Request body for creating a form-logic rule in a rating engine
        revision's config JSON
      required:
        - ratingEngineRevisionId
        - revisionStrategy
        - ruleName
        - rank
        - shouldAdd
      properties:
        ratingEngineRevisionId:
          type: string
          format: uuid
          description: >-
            The rating engine revision to add this rule to. Must reference an
            existing, non-deleted revision belonging to this company (otherwise
            the request returns 404).
        revisionStrategy:
          type: string
          enum:
            - UpdateExistingRevision
            - CreateNewRevision
          description: >-
            How to handle the rating engine revision. `UpdateExistingRevision`
            modifies the specified revision in place. `CreateNewRevision` is not
            yet implemented and will return a 501 error.
        ruleName:
          type: string
          minLength: 1
          description: >-
            Human-readable name for the rule (e.g. "Attach Certificate of
            Insurance").
        rank:
          type: number
          description: >-
            Sort order for this rule relative to others on the same revision.
            Controls the position of attached forms in the output list (lower
            numbers appear first). Duplicates are permitted.
        step:
          description: >
            Tag controlling which form-selection contexts this rule's output
            appears in — `"policies"` (output appears during policy form
            selection), `"quotes"` (output appears during quote form selection),
            or an array of these values. If omitted, the rule's output only
            appears during policy form selection; specify `"quotes"` (or an
            array that includes it) to also participate in quote form selection.
          oneOf:
            - type: string
              enum:
                - policies
                - quotes
            - type: array
              items:
                type: string
                enum:
                  - policies
                  - quotes
        shouldAdd:
          $ref: '#/components/schemas/ShouldAddExpression'
    ErrorResponse:
      type: object
      description: Standard error response for all external API endpoints
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code
              example: VALIDATION_ERROR
            message:
              type: string
              description: Human-readable error message
              example: 'submissionId: Required field is missing'
            details:
              type: array
              description: Additional details for validation errors (field-level errors)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: The field that caused the error
                    example: submissionId
                  message:
                    type: string
                    description: Description of the field error
                    example: Required field is missing
    ShouldAddExpression:
      description: >
        A conditional expression that evaluates to true or false during rating
        (of either a quote or a policy). Determines whether a form should be
        attached. Three variants are supported.
      oneOf:
        - title: Branch Expression
          description: Combines child expressions with a logical operator.
          type: object
          required:
            - operator
            - conditions
          properties:
            operator:
              type: string
              enum:
                - AND
                - OR
            conditions:
              type: array
              items:
                $ref: '#/components/schemas/ShouldAddExpression'
        - title: Leaf Expression
          description: >
            Compares the value at `leftKey` against `rightValue` using the given
            operator. `EXISTS` and `NOTEXISTS` check only whether `leftKey`
            resolves to a defined, non-null value (`rightValue` is required
            structurally but ignored). For `SOME`, `rightValue` is a nested
            expression evaluated against each element of the array at `leftKey`;
            the expression returns `false` if `leftKey` does not resolve to an
            array. `IN` and `NOTIN` accept either an array (membership check:
            the `leftKey` value must be an element) or a string (substring
            check: the `leftKey` value must appear within `rightValue`) for
            `rightValue`.
          type: object
          required:
            - leftKey
            - operator
            - rightValue
          properties:
            leftKey:
              type: string
              minLength: 1
              description: >
                Dotted path to a value in the rating context. The context
                includes `policy`, `insured`/`insureds`, `coverage`/`coverages`,
                and `form` (e.g. `policy.data.state`, `form.number`,
                `coverage.coverageTypeId`).
            operator:
              type: string
              enum:
                - '='
                - '!='
                - <
                - <=
                - '>'
                - '>='
                - IN
                - NOTIN
                - EXISTS
                - NOTEXISTS
                - SOME
            rightValue:
              description: >
                Primitive, array, `null`, or nested expression — a nested
                expression only makes sense with `SOME`. `null` is accepted by
                the runtime but cannot be expressed inside an OpenAPI 3.0
                `oneOf`.
              oneOf:
                - type: string
                - type: number
                - type: boolean
                - type: array
                  items: {}
                - $ref: '#/components/schemas/ShouldAddExpression'
        - title: Inverted Leaf Expression
          description: >
            Checks whether a static `leftValue` appears in the array or string
            at `rightKey`. Only the `IN` operator is supported.
          type: object
          required:
            - leftValue
            - operator
            - rightKey
          properties:
            leftValue:
              oneOf:
                - type: string
                - type: number
                - type: boolean
            operator:
              type: string
              enum:
                - IN
            rightKey:
              type: string
              minLength: 1
              description: >
                Dotted path to the array (or string) that `leftValue` is checked
                against. Resolved against the same rating context as `leftKey`.
  responses:
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingApiKey:
              summary: Missing API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: Authorization header is required
            bearerTokenNotAllowed:
              summary: Bearer token used instead of API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: External API endpoints require API key authentication
    Forbidden:
      description: Forbidden - Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            insufficientPermissions:
              summary: Insufficient permissions
              value:
                error:
                  code: FORBIDDEN
                  message: Insufficient permissions to perform this action
    InternalServerError:
      description: Internal Server Error - Unexpected error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internalError:
              summary: Unexpected server error
              value:
                error:
                  code: INTERNAL_ERROR
                  message: An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Include your API key in the Authorization
        header.

````