Configuration Guide

Template Structure

Define exactly how you want your documents processed. Templates combine natural language instructions with strict schema validation.

Anatomy of a Template

The Template Object

A complete breakdown of all configurable fields in a template.

name
Required • String

A unique, human-readable name for your template. Used to identify the template in the dashboard.

format
Required • String

Determines the output structure. Common values are structured (JSON) or markdown.

instructions
Optional • String

Natural language prompts guiding the AI on what to extract and how to handle edge cases. Up to 2000 characters.

schema
Optional • Object

A valid JSON Schema object defining the expected structure of the output. Ensures data consistency and type safety.

tags
Optional • Array

List of string tags for organizing and filtering templates within your project.

template_object.json
{
  "name": "Invoice Processor v2",
  "description": "Extracts vendor, date, and line items from invoices.",
  "format": "structured",
  "instructions": "Extract the vendor name, invoice date, and a list of all line items. Ensure the date is in YYYY-MM-DD format. If the vendor address is missing, leave it null.",
  "schema": {
    "type": "object",
    "properties": {
      "vendor": { "type": "string" },
      "date": { "type": "string", "format": "date" },
      "total": { "type": "number" },
      "line_items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "item": { "type": "string" },
            "price": { "type": "number" }
          }
        }
      }
    },
    "required": ["vendor", "total"]
  },
  "tags": ["finance", "invoices"],
  "favorite": true,
  "enabled": true
}

Core Components

Powering Your Extraction

Understanding the three pillars of a robust OCR template.

Smart Instructions

Use natural language to guide the AI. Explain context, define formatting rules, and handle edge cases just like you would when training a human operator.

Schema Validation

Define a rigid JSON schema to ensure 100% consistent output. The AI will strictly adhere to your types, required fields, and nested structures.

Format Control

Switch between structured JSON for data pipelines or clean Markdown for LLM context injection. One template, multiple possibilities.

Using Templates

Integration

Apply your template to any OCR job by referencing its ID.

Seamless Integration

Once created, a template can be reused across millions of documents. Simply pass the template_slug in your OCR request.

  • No need to send instructions with every request
  • Centralized configuration management
  • Version control your extraction logic
ocr_request.sh
curl https://api.leapocr.com/api/v1/ocr/url \
  -X POST \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "url": "https://example.com/invoice.pdf",
    "template_slug": "invoice-template"
  }'

Ready to transform your documents with AI?