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

# Compile and Save

> Compiles a Watchscript and saves it as an instruction. The script is validated and parsed into an AST, then stored in the database. Once saved, the rule is immediately active and will be evaluated against all incoming transactions.



## OpenAPI

````yaml POST /compile-and-save-instruction
openapi: 3.1.0
info:
  title: FinWatch API
  description: >-
    FinWatch REST API for real-time transaction monitoring, rule evaluation, and
    instruction management.
  version: 1.0.0
  contact:
    name: FinWatch Support
    url: https://docs.finwatch.finance
servers:
  - url: http://localhost:8081
    description: Local development server
security: []
tags:
  - name: Transactions
    description: >-
      Inject transactions for evaluation, retrieve transaction details, and
      handle webhook events.
  - name: Instructions
    description: >-
      Create, list, retrieve, and delete monitoring rules written in
      Watchscript.
  - name: Git
    description: Manage rules with Git for version control — status, pull, push, and clone.
paths:
  /compile-and-save-instruction:
    post:
      tags:
        - Instructions
      summary: Compile and Save Instruction
      description: >-
        Compiles a Watchscript and saves it as an instruction. The script is
        validated and parsed into an AST, then stored in the database. Once
        saved, the rule is immediately active and will be evaluated against all
        incoming transactions.
      operationId: compileAndSaveInstruction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompileRequest'
            example:
              script: |-
                rule HighValueTransaction {
                    description "Review any transaction above $10,000"
                    when amount > 10000
                    then review
                         score   0.5
                         reason  "Amount exceeds threshold"
                }
      responses:
        '201':
          description: Instruction compiled and saved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Instruction'
              example:
                id: 1
                name: HighValueTransaction
                text: |-
                  rule HighValueTransaction {
                      description "Review any transaction above $10,000"
                      when amount > 10000
                      then review
                           score   0.5
                           reason  "Amount exceeds threshold"
                  }
                description: Review any transaction above $10,000
                dsl_json: '{"name":"HighValueTransaction","when":[...],"then":{...}}'
                created_at: '2024-01-15T10:00:00Z'
                updated_at: '2024-01-15T10:00:00Z'
        '400':
          description: Invalid request body or empty script
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Instruction with the same name already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Failed to compile script or save instruction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CompileRequest:
      type: object
      required:
        - script
      properties:
        script:
          type: string
          description: The Watchscript source code to compile and save
    Instruction:
      type: object
      properties:
        id:
          type: integer
          description: Unique instruction identifier
        name:
          type: string
          description: Rule name (extracted from Watchscript)
        text:
          type: string
          description: The original Watchscript source text
        description:
          type: string
          description: Human-readable description (extracted from Watchscript)
        dsl_json:
          type: string
          description: Compiled DSL as JSON string (AST representation)
        created_at:
          type: string
          format: date-time
          description: Creation timestamp
        updated_at:
          type: string
          format: date-time
          description: Last update timestamp
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
        code:
          type: string
          description: Error code

````