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

# Templates

> Define custom extraction schemas for the Document Extraction service, or use prebuilt templates provided by AnyCheck.

## Overview

Templates define **which fields to extract** and **how to extract them** from documents processed by the Document Extraction service. When you attach a template to a verification, AnyCheck uses it to structure the output into the exact fields your application needs.

<CardGroup cols={2}>
  <Card title="Custom templates" icon="pen-ruler">
    Define your own schema to extract any fields from any document type.
  </Card>

  <Card title="Prebuilt templates" icon="box">
    Ready-to-use templates for common Indonesian documents maintained by AnyCheck.
  </Card>

  <Card title="Auto-schema generation" icon="wand-magic-sparkles">
    Describe what you want to extract in plain text and the schema is generated automatically.
  </Card>

  <Card title="Reusable across verifications" icon="rotate">
    Create a template once and attach it to any number of Document Extraction verifications.
  </Card>
</CardGroup>

***

## Template Types

### Custom Templates

Custom templates are created and maintained by your organization. You define the schema: the fields to extract, their types, and any special extraction instructions.

```bash theme={null}
GET /templates/custom
```

### Prebuilt Templates

Prebuilt templates are provided and maintained by AnyCheck for common document types (e.g., KTP, NPWP, SIUP). They are read-only and cannot be modified.

```bash theme={null}
GET /templates/prebuilt
```

***

## Creating a Custom Template

### Option 1: Define the schema manually

Specify the fields you want to extract and their types:

```bash theme={null}
curl -X POST https://api.anycheck.ai/templates \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Invoice Extraction Template",
    "description": "Extracts key fields from Indonesian tax invoices",
    "instruction": "Focus on the invoice number and tax amounts. Ignore header/footer text.",
    "schema": {
      "invoice_number": { "type": "string", "description": "Invoice number (e.g., 010.001-24.12345678)" },
      "invoice_date": { "type": "string", "description": "Invoice date in YYYY-MM-DD format" },
      "seller_name": { "type": "string", "description": "Seller company name" },
      "buyer_name": { "type": "string", "description": "Buyer company name" },
      "dpp": { "type": "number", "description": "Dasar Pengenaan Pajak (tax base amount)" },
      "ppn": { "type": "number", "description": "PPN amount (11% of DPP)" },
      "total_amount": { "type": "number", "description": "Total invoice amount including tax" }
    },
    "config": {
      "preset_mode": "BALANCED"
    }
  }'
```

The `instruction` field lets you give the AI model context about where to focus on the document. The `config` field controls which AI model and parser to use. See [Template Configuration](#template-configuration) below.

### Option 2: Use auto-schema generation

Describe in plain text what you want to extract, and AnyCheck generates the schema automatically:

```bash theme={null}
curl -X POST https://api.anycheck.ai/templates/autoschema \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Extract the invoice number, issue date, seller and buyer names, and the total amount including tax from Indonesian tax invoices (Faktur Pajak)",
    "extraction_mode": "ODIN"
  }'
```

**Response:**

```json theme={null}
{
  "schema": {
    "properties": {
      "invoice_number": {
        "type": "string",
        "description": "The unique invoice identifier"
      },
      "issue_date": {
        "type": "string",
        "description": "Invoice issue date in YYYY-MM-DD format"
      },
      "seller_name": {
        "type": "string",
        "description": "Name of the issuing company"
      },
      "buyer_name": {
        "type": "string",
        "description": "Name of the purchasing company"
      },
      "total_amount": {
        "type": "number",
        "description": "Total amount including all taxes"
      }
    },
    "required": ["invoice_number", "issue_date", "seller_name", "total_amount"],
    "type": "object"
  }
}
```

Review and refine the generated schema, then use it in a `POST /templates` call.

***

## Using a Template in a Verification

When creating a Document Extraction verification, pass the template ID in the configuration:

```bash theme={null}
curl -X POST https://api.anycheck.ai/verifications \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service_id": "<document-extraction-service-uuid>",
    "folder_id": "<folder-uuid>",
    "configuration": {
      "files": {
        "document_extraction_file": ["/uploads/invoice.pdf"]
      },
      "template_id": "<your-template-uuid>"
    }
  }'
```

The verification output will contain extracted field values keyed by the schema property names you defined.

***

## Finding the Right Template

Use the form endpoint to browse available templates in a dropdown-friendly format (includes both custom and prebuilt):

```bash theme={null}
GET /forms/templates?search=invoice&page_size=20
```

For full template details (schema, instructions, config):

```bash theme={null}
GET /templates/{id}
```

***

## Managing Custom Templates

### Update a template

You can update the name, description, instruction, schema, or config of a custom template. Prebuilt templates cannot be modified.

```bash theme={null}
curl -X PUT https://api.anycheck.ai/templates/{id} \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Invoice Extraction Template v2",
    "schema": {
      "invoice_number": { "type": "string" },
      "issue_date": { "type": "string" },
      "total_amount": { "type": "number" },
      "npwp_seller": { "type": "string", "description": "Seller NPWP number" }
    }
  }'
```

### Delete a template

```bash theme={null}
DELETE /templates/{id}
```

Only custom templates can be deleted. Deleting a template does not affect existing verifications that used it.

***

## Template Schema Reference

The `schema` object follows a JSON Schema-like format. Each property supports:

| Field         | Required    | Description                                                    |
| ------------- | ----------- | -------------------------------------------------------------- |
| `type`        | Yes         | Data type: `string`, `number`, `boolean`, `array`, `object`    |
| `description` | Recommended | What this field represents; helps guide extraction             |
| `required`    | No          | Mark in the root `required` array if the field must be present |

<Note>
  The `instruction` field at the template level provides context to the AI about the document as a whole (e.g., "this is a two-page document; all amounts are in IDR"). Per-field descriptions guide extraction of individual values.
</Note>

***

## Template Configuration

The `config` object in `POST /templates` controls how extraction is performed. You can use a preset or configure individual settings.

### Preset modes (recommended)

The simplest way to control quality vs. speed:

| `preset_mode` | Speed   | Accuracy | Cost   | Best for                      |
| ------------- | ------- | -------- | ------ | ----------------------------- |
| `FAST`        | Fastest | Good     | Low    | High-volume, simple documents |
| `BALANCED`    | Fast    | Better   | Medium | Most use cases                |
| `PRECISE`     | Slower  | Best     | High   | Complex or dense documents    |
| `BUDGET`      | Fast    | Good     | Lowest | Cost-sensitive workloads      |

```json theme={null}
{
  "config": {
    "preset_mode": "BALANCED"
  }
}
```

### Individual settings

For finer control, configure each setting separately:

| Field              | Values                                                         | Default | Description                                                     |
| ------------------ | -------------------------------------------------------------- | ------- | --------------------------------------------------------------- |
| `extraction_mode`  | `FREYA`, `FREYA_PRO`, `ODIN`, `ODIN_PRO`, `NEXUS`, `NEXUS_PRO` | `FREYA` | AI model used for extraction                                    |
| `parser_mode`      | `LITE`, `PLUS`, `PRO`                                          | `LITE`  | Document parsing quality before AI extraction                   |
| `use_parser`       | `true`, `false`                                                | `false` | Parse document structure before sending to AI                   |
| `use_chunk`        | `true`, `false`                                                | `false` | Split large documents into chunks (requires `use_parser: true`) |
| `enable_citations` | `true`, `false`                                                | `true`  | Include source location in extracted values                     |

<Note>
  When both `preset_mode` and individual settings are provided, the preset applies first and individual settings override it.
</Note>

***

## Lifecycle

```mermaid actions={false} theme={null}
flowchart LR
    A[Create template] --> B[Test with a sample document]
    B --> C[Review output accuracy]
    C --> D{Accurate enough?}
    D -- No --> E[Update schema]
    E --> B
    D -- Yes --> F[Use in production]
```

Start with a small schema (3–5 fields), test accuracy, then expand. Complex schemas with many fields may require more specific per-field descriptions to maintain accuracy.
