# Check Compliance

> Evaluate content against compliance policies, regulatory rules, or business guidelines.

Source: https://docs.sommatic.ai/en/nodes/ai.compliance.check/

- Slug: `ai.compliance.check`
- Family: AI
- Version: 1.0.0
- Status: Available
- Execution: async

Evaluate content against compliance policies, regulatory rules, or business guidelines.

Link a Knowledge Resource containing your compliance policy and this node will automatically check any text for violations — returning severity levels, specific rule citations, and remediation suggestions.

**Operations:**
- **Full Check:** Deep analysis against all policy rules with detailed violation reports.
- **Quick Check:** Fast scan for critical violations only.

Ideal for regulatory compliance (GDPR, HIPAA, SOX), internal policy enforcement, content review workflows, and audit automation.

## Configuration

- `llm_provider_id` (string, optional): The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.
- `invocation_mode` (string, optional): Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`. Default: `sync`. Allowed values: `sync`, `stream`.
- `timeout_ms` (integer, optional): Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.
- `knowledge_resource_id` (string, required): REQUIRED: Knowledge Resource containing the compliance rules/policy to check against.
- `check_mode` (string, optional): Full: deep analysis of all rules. Quick: critical violations only. Default: `full`. Allowed values: `full`, `quick`.
- `severity_levels` (array<string>, optional): Severity classification for violations. Default: `["critical","major","minor","info"]`.
- `language` (string, optional): Default: `en`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `compliant` (default): Content passes all compliance checks.
- `non_compliant`: One or more violations detected.
- `error`: Compliance check failed.

## Input contract

- `text` (string, required): Content to evaluate for compliance.
- `document_type` (string, optional): Optional: type of document (contract, email, report).
- `context` (object, optional): Optional: additional context for evaluation.

## Output contract

- `compliant` (boolean, optional): Whether the content passes all checks.
- `violations` (array, optional): List of violations found.
- `violation_count` (number, optional): Total number of violations.
- `risk_level` (string, optional): Overall risk assessment.
- `summary` (string, optional): Human-readable compliance summary.

## In expressions

What a later node can read from this node's output with `$("Check Compliance").item.json.<path>` (write your node's label instead of `Check Compliance`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `compliant`, from the output shown in Ports.

- `$("Check Compliance").item.json.compliant` (boolean) = `true`: Whether the content passes all checks.
- `$("Check Compliance").item.json.violations` (array) = `[…] (0)`: List of violations found.
- `$("Check Compliance").item.json.violation_count` (number) = `0`: Total number of violations.
- `$("Check Compliance").item.json.risk_level` (string) = `"none"`: Overall risk assessment.
- `$("Check Compliance").item.json.summary` (string) = `"The contract meets all payment and data rules."`: Human-readable compliance summary.


## How it works

Audits `text` against the rules of a policy knowledge resource with the model and routes to `compliant` or `non_compliant` with the list of violations.

1. Merges the upstream payload with the node config (config wins) and reads `text` (falling back to `input`) and `document_type`. Fails when `knowledge_resource_id` is empty.
2. Loads the policy: `content.structured_data.rules` (or `.policies`) as a rule list, each rendered as `- **<name>** [<severity>]: <description>` (severity default `major`); otherwise `content.text` as free text. Fails if both are empty.
3. Sends an auditor system prompt (all rules for `check_mode: "full"`, only critical and major for `"quick"`) with the severity levels and a strict JSON format; `text` is the user message; `temperature: 0`.
4. Parses the answer as JSON; it must contain a boolean `compliant`. Each violation's `severity` is lower-cased and replaced by `major` when it is not in `severity_levels`.
5. Recomputes `compliant` itself: true only when no violation has a severity other than `info`. Routes to `compliant` or `non_compliant`.

## In a workflow

### Node

```json
{
  "node_id": "node-check-contract",
  "label": "Check contract",
  "operator_slug": "ai.compliance.check",
  "operator_version": "1.0.0",
  "config": {
    "knowledge_resource_id": "<knowledge_resource_id>",
    "text": "{{ $json.text }}",
    "document_type": "contract",
    "check_mode": "full",
    "severity_levels": [
      "critical",
      "major",
      "minor",
      "info"
    ],
    "language": "en",
    "llm_provider_id": "wf-llm-provider-xxxx",
    "invocation_mode": "stream",
    "timeout_ms": 120000
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "compliant": false,
    "violations": [
      {
        "rule": "Payment terms",
        "severity": "major",
        "description": "The contract sets payment at 90 days; the policy allows at most 60.",
        "location": "Clause 7: \"payment within ninety (90) days\"",
        "remediation": "Change the payment term to 60 days or fewer."
      }
    ],
    "violation_count": 1,
    "risk_level": "medium",
    "summary": "One major violation on payment terms."
  },
  "port": "non_compliant"
}
```

## Output ports (behaviour in the code)

### `compliant`

No violations, or only `info` ones (they stay in `violations`).

```json
{
  "compliant": true,
  "violations": [],
  "violation_count": 0,
  "risk_level": "none",
  "summary": "The contract meets all payment and data rules."
}
```

### `non_compliant`

At least one violation above `info`.

```json
{
  "compliant": false,
  "violations": [
    {
      "rule": "Payment terms",
      "severity": "major",
      "description": "The contract sets payment at 90 days; the policy allows at most 60.",
      "location": "Clause 7: \"payment within ninety (90) days\"",
      "remediation": "Change the payment term to 60 days or fewer."
    }
  ],
  "violation_count": 1,
  "risk_level": "medium",
  "summary": "One major violation on payment terms."
}
```

### `error`

Policy or text is missing, the model call failed or the answer was not valid.

```json
{
  "error": "Model did not return valid compliance check output."
}
```

## Behaviour in the code

- `text, document_type`: Not in the config schema, but read from the config first and then from the upstream payload. `document_type` adds `The document is a <type>.` to the prompt. The `context` input is ignored.
- `severity_levels`: Listed in the prompt and used to validate answers; unknown severities become `major`. Only the literal `info` is excluded from the compliance decision.
- `timeout_ms`: Stream mode only: idle timeout between chunks, default 600000. In sync mode it is not applied to the request.
- `execution`: Declared but ignored: neither the worker nor the engine reads `retryOnFail`, `maxTries`, `waitBetweenTries`, `continueOnFail`, `alwaysOutputData` or `timeout_ms` from this block.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `A Knowledge Resource with compliance rules is required. Link a policy document in the node configuration.` | `error` | `knowledge_resource_id` is empty. |
| `Knowledge Resource has no policy content. Add rules as text or structured_data.rules array.` | `error` | The resource has neither `content.text` nor a `structured_data.rules` / `policies` array. |
| `Model did not return valid compliance check output.` | `error` | The answer was not JSON or had no boolean `compliant`. |
| `Knowledge resource not found: <knowledge_resource_id>` | `error` | The id does not match any knowledge resource. A deleted resource fails with `Knowledge resource "<name>" has been deleted. Update the node config to reference an active resource.` |
| `[AiComplianceCheck] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'.` | `error` | `llm_provider_id` is empty or not a string. Pick an LLM provider record with chat capability. |
| `LLM Invocation Error: <backend message>` | `error` | The backend rejected the call: unknown or inactive provider record, provider error, quota or content filter. Check the provider record and the backend logs. |
| `LLM Invocation Error: empty response from backend (<transport error>)` | `error` | Sync mode: the HTTP call to the backend failed (network error, non-2xx status or timeout). Long prompts often hit the request timeout; switch to `invocation_mode: "stream"`. |
| `RemoteApiService.stream: idle timeout after <timeout_ms>ms` | `error` | Stream mode: no chunk arrived within `timeout_ms`. A failed stream request shows `RemoteApiService.stream: HTTP <status> — <body>` instead. |

## Notes and limits

- When `text` is empty, the worker falls back to `input`, which at runtime is always the whole upstream payload object. The missing-text check therefore never fires and the object is sent to the model as the message. Always map `text` explicitly.
- `risk_level` and `summary` come from the model; when `risk_level` is missing it is `none` (compliant) or `medium` (non-compliant).
- The worker returns `raw` next to `data`; the engine keeps only `data` as the node output, so `raw` is not available downstream.
- The model call goes through the Sommatic AI backend, which resolves the provider record named by `llm_provider_id` (endpoint, credentials, deployment); the orchestrator never holds provider keys. `invocation_mode: "sync"` (default) waits for the full answer; `"stream"` reads it as server-sent events and joins the chunks.
- `timeout_ms` only takes effect in stream mode, as the idle time allowed between chunks (default 600000). In sync mode the value is logged but not applied to the HTTP request, so the platform's default request timeout governs.
- In stream mode the backend endpoint does not apply sampling settings, so the fixed `temperature: 0` only takes effect in sync mode.
- The knowledge resource is read from the backend on every run (10 s timeout). A resource whose status is not `active` is used anyway, with a warning in the log.
- No automatic retries: the engine does not honour `execution.retryOnFail`, `maxTries` or `waitBetweenTries` for this node; a failed call goes straight to `error`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.compliance.check",
  "name": "Check Compliance",
  "category": "ai",
  "version": "1.0.0",
  "description": "Evaluate content against compliance policies, regulatory rules, or business guidelines.\n\n  Link a Knowledge Resource containing your compliance policy and this node will automatically check any text for violations — returning severity levels, specific rule citations, and remediation suggestions.\n\n  **Operations:**\n  - **Full Check:** Deep analysis against all policy rules with detailed violation reports.\n  - **Quick Check:** Fast scan for critical violations only.\n\n  Ideal for regulatory compliance (GDPR, HIPAA, SOX), internal policy enforcement, content review workflows, and audit automation.",
  "capabilities": [
    "compliance",
    "audit",
    "governance",
    "policy",
    "risk"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider",
        "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "chat"
        ]
      },
      "invocation_mode": {
        "type": "string",
        "title": "Invocation Mode",
        "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "knowledge_resource_id": {
        "type": "string",
        "title": "Compliance Policy",
        "description": "REQUIRED: Knowledge Resource containing the compliance rules/policy to check against.",
        "ui_widget": "knowledge_resource_picker"
      },
      "check_mode": {
        "type": "string",
        "title": "Check Mode",
        "enum": [
          "full",
          "quick"
        ],
        "default": "full",
        "description": "Full: deep analysis of all rules. Quick: critical violations only."
      },
      "severity_levels": {
        "type": "array",
        "title": "Severity Levels",
        "default": [
          "critical",
          "major",
          "minor",
          "info"
        ],
        "items": {
          "type": "string"
        },
        "description": "Severity classification for violations."
      },
      "language": {
        "type": "string",
        "title": "Language",
        "default": "en"
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "knowledge_resource_id"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "Content to evaluate for compliance."
      },
      "document_type": {
        "type": "string",
        "description": "Optional: type of document (contract, email, report)."
      },
      "context": {
        "type": "object",
        "description": "Optional: additional context for evaluation."
      }
    },
    "required": [
      "text"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "compliant": {
        "type": "boolean",
        "description": "Whether the content passes all checks."
      },
      "violations": {
        "type": "array",
        "description": "List of violations found."
      },
      "violation_count": {
        "type": "number",
        "description": "Total number of violations."
      },
      "risk_level": {
        "type": "string",
        "description": "Overall risk assessment."
      },
      "summary": {
        "type": "string",
        "description": "Human-readable compliance summary."
      }
    }
  },
  "ports": [
    {
      "port_id": "compliant",
      "label": "Compliant",
      "description": "Content passes all compliance checks.",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "non_compliant",
      "label": "Non-Compliant",
      "description": "One or more violations detected.",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Compliance check failed.",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "compliance",
    "audit",
    "governance",
    "policy"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "llm_provider_id": {
      "type": "string",
      "title": "LLM Provider",
      "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
      "x-ui-widget": "llm-provider-picker",
      "x-llm-provider-capabilities": [
        "chat"
      ]
    },
    "invocation_mode": {
      "type": "string",
      "title": "Invocation Mode",
      "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
      "enum": [
        "sync",
        "stream"
      ],
      "default": "sync"
    },
    "timeout_ms": {
      "type": "integer",
      "title": "Timeout (ms)",
      "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
      "minimum": 1000
    },
    "knowledge_resource_id": {
      "type": "string",
      "title": "Compliance Policy",
      "description": "REQUIRED: Knowledge Resource containing the compliance rules/policy to check against.",
      "ui_widget": "knowledge_resource_picker"
    },
    "check_mode": {
      "type": "string",
      "title": "Check Mode",
      "enum": [
        "full",
        "quick"
      ],
      "default": "full",
      "description": "Full: deep analysis of all rules. Quick: critical violations only."
    },
    "severity_levels": {
      "type": "array",
      "title": "Severity Levels",
      "default": [
        "critical",
        "major",
        "minor",
        "info"
      ],
      "items": {
        "type": "string"
      },
      "description": "Severity classification for violations."
    },
    "language": {
      "type": "string",
      "title": "Language",
      "default": "en"
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "knowledge_resource_id"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "Content to evaluate for compliance."
    },
    "document_type": {
      "type": "string",
      "description": "Optional: type of document (contract, email, report)."
    },
    "context": {
      "type": "object",
      "description": "Optional: additional context for evaluation."
    }
  },
  "required": [
    "text"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "compliant": {
      "type": "boolean",
      "description": "Whether the content passes all checks."
    },
    "violations": {
      "type": "array",
      "description": "List of violations found."
    },
    "violation_count": {
      "type": "number",
      "description": "Total number of violations."
    },
    "risk_level": {
      "type": "string",
      "description": "Overall risk assessment."
    },
    "summary": {
      "type": "string",
      "description": "Human-readable compliance summary."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "compliant",
    "label": "Compliant",
    "description": "Content passes all compliance checks.",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "non_compliant",
    "label": "Non-Compliant",
    "description": "One or more violations detected.",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Compliance check failed.",
    "is_default": false,
    "supports_condition": false
  }
]
```
