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

# Rule Studio

> Turn your parsed policy documents into structured, reviewable rules (paid)

<Info>
  Rule Studio is a **paid workspace add-on**. It builds on [Your policy documents](/docs/policy-documents):
  first parse and structure a PDF, then extract structured rules from its sections. Free
  workspaces get `402 upgrade_required` on every Rule Studio endpoint.
</Info>

## What it does

The document lane turns a payer PDF into a folder tree of cited prose. Rule Studio takes the
next step: it sends each section's prose to an extraction pass and produces **structured rule
candidates** — landing as `draft` for staff review. Nothing is trusted until a reviewer
approves it, and only approved payment **algorithms** can be run.

Every candidate carries two orthogonal dimensions:

* **`kind`** — the structural shape: `rule`, `decision_table`, or `algorithm`.
* **`rule_type`** — the semantic category: `coding_edit`, `billing_edit`, `post_adjudication`
  (denials & appeals, recoupment, adjustments), `reimbursement` (payment math), `medical_necessity`,
  `authorization`, `timely_filing` (initial filing deadlines only), `clinical_documentation`,
  `charge`, `benefits`, `edi_formatting`, `general`.

An algorithm is a *kind*, not a rule\_type — payment math is `kind=algorithm`,
`rule_type=reimbursement`.

## Prerequisites

1. `POST /v1/policy/parse` — parse the PDF into chunks.
2. `POST /v1/policy/structure` — build the folder tree (Rule Studio will build it on demand if missing).
3. A workspace on a **paid plan** (Pro or Enterprise).

## Endpoints

| Method | Path                                                  | Auth                           | Purpose                                               |
| ------ | ----------------------------------------------------- | ------------------------------ | ----------------------------------------------------- |
| `POST` | `/v1/policy/rules/extract`                            | API key (paid) or admin secret | Extract draft candidates for a document               |
| `GET`  | `/v1/policy/rules/{document_id}`                      | API key (paid) or admin secret | List candidates (`?status=draft\|approved\|rejected`) |
| `POST` | `/v1/policy/rules/candidates/{candidate_id}/review`   | Admin secret (staff)           | Approve / reject (optional `edited_body`)             |
| `POST` | `/v1/policy/rules/algorithms/{candidate_id}/evaluate` | API key (paid) or admin secret | Run an **approved** algorithm on your inputs          |
| `POST` | `/v1/policy/rules/algorithms/{candidate_id}/selftest` | API key (paid) or admin secret | Re-run the manual's worked examples; pass/fail        |

API-key callers are scoped to their own tenant's documents. Review is staff-only.

## The lock

A FREE-tier workspace receives:

```json theme={null}
{
  "detail": {
    "error": "feature_locked",
    "code": "upgrade_required",
    "locked": true,
    "feature": "rule_studio",
    "message": "Rule Studio is a paid feature. Upgrade your workspace to turn documents into structured rules: https://rcintell.com/upgrade",
    "upgrade_path": "/upgrade"
  }
}
```

with HTTP `402`. Front-ends render the "Turn documents into rules" button locked when the
workspace plan is FREE, and fall back to this response if the plan changes mid-session.

## Review workflow

Candidates land `status="draft"` with `extracted_by="llm:<model>"`, a `confidence`, and
`citations` back to source page ranges. A reviewer approves, edits, or rejects each one; the
review status survives re-extraction (re-running `extract` refreshes draft rows but never
overwrites an approved or rejected decision). Only `approved` algorithms can be evaluated or
self-tested via the API.
