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

# Jinba Modules

> Advanced data extraction, parsing, and validation using Jinba Modules

## Overview

Jinba Modules provide LLM-powered data processing capabilities including extraction, parsing, and rule-based checking. These tools analyze files with large language models to handle complex data transformation and validation tasks with high accuracy and flexibility.

## Key Features

### JINBA\_MODULES\_EXTRACT

Uses an LLM to analyze a file and extract structured data according to a JSON Schema you define.

| Parameter        | Type   | Required | Description                                                                                                                   |
| ---------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `name`           | string | Yes      | Task name                                                                                                                     |
| `fileUrl`        | string | Yes      | The URL of the file to extract data from                                                                                      |
| `dataSchema`     | object | No       | The schema of the data to extract. Must be a valid [JSON Schema](https://json-schema.org/understanding-json-schema/reference) |
| `extractionMode` | string | No       | `FAST`, `BALANCED` (default), or `QUALITY`                                                                                    |

Output: `result` — the extracted data, shaped by your `dataSchema`.

### JINBA\_MODULES\_PARSE

A dynamic parser in which the LLM automatically adjusts the parsing approach based on the file type and outputs the extracted content.

| Parameter        | Type   | Required | Description                                   |
| ---------------- | ------ | -------- | --------------------------------------------- |
| `fileUrl`        | string | Yes      | The URL of the file to parse                  |
| `outputFormat`   | string | No       | `MARKDOWN` (default), `TEXT`, or `STRUCTURED` |
| `extractionMode` | string | No       | `FAST`, `BALANCED` (default), or `QUALITY`    |

Output: `result` — the parsed content as a string.

### JINBA\_MODULES\_CHECKER\_V2

An enhanced LLM-based checker that validates a target file against JSON-defined rules. v2 supports flexible rule structures, higher-precision evaluation, and detailed reasoning for each judgment.

| Parameter              | Type   | Required | Description                                                                                                                            |
| ---------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `target_file`          | string | Yes      | The file to check (PDF, text, JSON, XML, CSV, or DOCX)                                                                                 |
| `task`                 | string | Yes      | The task name                                                                                                                          |
| `description`          | string | No       | Task description. Use when you want to add instructions specialized for a specific task                                                |
| `rules`                | array  | No       | JSON array of rule objects (see [Rule Format](#rule-format))                                                                           |
| `references`           | array  | No       | Up to 10 reference file URLs. To suppress hallucinations, you can embed company regulations, legal documents, RAG search results, etc. |
| `additionalDataSchema` | object | No       | JSON Schema describing additional data to return with each check result                                                                |

Output: `result` — an array of check results, one per rule, each with `uniqueId`, `rule`, `status` (`accepted` / `rejected` / `pending`), `range`, `reason`, and optional `additionalData`.

## Authentication

No authentication or tool configuration is required. The Jinba Modules API credentials are managed server-side.

## Example: Intelligent Document Extraction

```yaml theme={null}
- id: upload_document
  name: upload_document
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload document for intelligent extraction"

- id: extract_structured_data
  name: extract_structured_data
  tool: JINBA_MODULES_EXTRACT
  input:
    - name: name
      value: "Invoice Data Extraction"
    - name: fileUrl
      value: "{{steps.upload_document.result}}"
    - name: dataSchema
      value: |
        {
          "$schema": "http://json-schema.org/draft-07/schema#",
          "type": "object",
          "properties": {
            "invoice_number": {
              "type": "string",
              "description": "Invoice number or ID"
            },
            "date": {
              "type": "string",
              "format": "date",
              "description": "Invoice date"
            },
            "vendor": {
              "type": "object",
              "properties": {
                "name": {"type": "string"},
                "address": {"type": "string"},
                "phone": {"type": "string"},
                "email": {"type": "string"}
              }
            },
            "items": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "description": {"type": "string"},
                  "quantity": {"type": "number"},
                  "unit_price": {"type": "number"},
                  "total": {"type": "number"}
                }
              }
            },
            "total_amount": {
              "type": "number",
              "description": "Total invoice amount"
            },
            "tax_amount": {
              "type": "number",
              "description": "Tax amount if present"
            }
          },
          "required": ["invoice_number", "date", "total_amount"]
        }
    - name: extractionMode
      value: "QUALITY"  # Options: FAST, BALANCED, QUALITY

- id: validate_document
  name: validate_document
  tool: JINBA_MODULES_CHECKER_V2
  input:
    - name: target_file
      value: "{{steps.upload_document.result}}"
    - name: task
      value: "Invoice Validation"
    - name: description
      value: "Check that the uploaded invoice satisfies the rules below."
    - name: rules
      value: |
        [
          {
            "uniqueId": "invoice-001",
            "name": "Invoice number present",
            "description": "The document must contain an invoice number or ID."
          },
          {
            "uniqueId": "invoice-002",
            "name": "Positive total amount",
            "description": "The total amount must be a positive number."
          },
          {
            "uniqueId": "invoice-003",
            "name": "Valid invoice date",
            "description": "The invoice date must be present and in a valid date format."
          },
          {
            "uniqueId": "invoice-004",
            "name": "Valid vendor email",
            "description": "If a vendor email address is present, it must be in a valid email format."
          }
        ]

- id: process_extraction_results
  name: process_extraction_results
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        import json
        
        # Process extraction and check results
        extracted_data = json.loads('''{{steps.extract_structured_data.result}}''')
        check_results = json.loads('''{{steps.validate_document.result}}''')
        
        print("Document Extraction Results")
        print("=" * 35)
        
        # Display extracted data
        print("Extracted Information:")
        print(f"Invoice Number: {extracted_data.get('invoice_number', 'N/A')}")
        print(f"Date: {extracted_data.get('date', 'N/A')}")
        print(f"Vendor: {extracted_data.get('vendor', {}).get('name', 'N/A')}")
        print(f"Total Amount: ${extracted_data.get('total_amount', 0):,.2f}")
        
        if 'items' in extracted_data:
            print(f"Items Count: {len(extracted_data['items'])}")
        
        print("\nCheck Results:")
        accepted_count = sum(1 for r in check_results if r.get('status') == 'accepted')
        total_rules = len(check_results)
        print(f"Accepted: {accepted_count}/{total_rules}")
        
        # Show any rejected rules
        rejected = [r for r in check_results if r.get('status') == 'rejected']
        if rejected:
            print("\nRejected Rules:")
            for r in rejected:
                print(f"  - {r.get('rule', 'Unknown')}: {r.get('reason', 'No reason provided')}")
        else:
            print("All rules accepted")

- id: export_processed_data
  name: export_processed_data
  tool: OUTPUT_FILE
  input:
    - name: content
      value: "{{steps.extract_structured_data.result}}"
    - name: filename
      value: "extracted_invoice_data_{{date | format('YYYY-MM-DD')}}.json"
    - name: fileType
      value: "json"
```

## Example: Batch Document Processing

```yaml theme={null}
- id: process_document_batch
  name: process_document_batch
  tool: JINBA_MODULES_EXTRACT
  input:
    - name: name
      value: "Batch Document Processing"
    - name: fileUrl
      value: "{{input.batch_file_url}}"
    - name: dataSchema
      value: |
        {
          "$schema": "http://json-schema.org/draft-07/schema#",
          "type": "object",
          "properties": {
            "documents": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "document_type": {"type": "string"},
                  "date": {"type": "string"},
                  "amount": {"type": "number"},
                  "vendor": {"type": "string"},
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                },
                "required": ["document_type", "date", "amount"]
              }
            }
          }
        }
    - name: extractionMode
      value: "BALANCED"

- id: parse_document_content
  name: parse_document_content
  tool: JINBA_MODULES_PARSE
  input:
    - name: fileUrl
      value: "{{input.batch_file_url}}"
    - name: outputFormat
      value: "MARKDOWN"  # Options: MARKDOWN, TEXT, STRUCTURED
    - name: extractionMode
      value: "BALANCED"

- id: comprehensive_validation
  name: comprehensive_validation
  tool: JINBA_MODULES_CHECKER_V2
  input:
    - name: target_file
      value: "{{input.batch_file_url}}"
    - name: task
      value: "Batch Document Check"
    - name: rules
      value: |
        [
          {
            "uniqueId": "doc-001",
            "name": "Known document types only",
            "description": "Every document must be an invoice, a receipt, or a contract."
          },
          {
            "uniqueId": "doc-002",
            "name": "Amount within range",
            "description": "Every document amount must be between 0 and 1,000,000."
          },
          {
            "uniqueId": "doc-003",
            "name": "Date within range",
            "description": "Every document date must be between 2020-01-01 and 2025-12-31."
          },
          {
            "uniqueId": "doc-004",
            "name": "Vendor name length",
            "description": "Every vendor name must be between 2 and 200 characters."
          }
        ]
    - name: additionalDataSchema
      value: |
        {
          "type": "object",
          "properties": {
            "documentType": {
              "type": "string",
              "description": "The type of the document the rule was evaluated against"
            }
          }
        }

- id: generate_processing_report
  name: generate_processing_report
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        import json
        from datetime import datetime
        
        # Compile processing report
        extracted = json.loads('''{{steps.process_document_batch.result}}''')
        parsed = '''{{steps.parse_document_content.result}}'''
        check_results = json.loads('''{{steps.comprehensive_validation.result}}''')
        
        report = {
            "processing_summary": {
                "timestamp": datetime.now().isoformat(),
                "total_documents": len(extracted.get('documents', [])),
                "extraction_mode": "BALANCED",
                "parsed_characters": len(parsed),
                "all_rules_accepted": all(r.get('status') == 'accepted' for r in check_results)
            },
            "document_breakdown": {},
            "check_summary": {
                "total_rules": len(check_results),
                "accepted": sum(1 for r in check_results if r.get('status') == 'accepted'),
                "rejected": sum(1 for r in check_results if r.get('status') == 'rejected'),
                "pending": sum(1 for r in check_results if r.get('status') == 'pending')
            },
            "recommendations": []
        }
        
        # Document type breakdown
        if 'documents' in extracted:
            doc_types = {}
            total_amount = 0
            for doc in extracted['documents']:
                doc_type = doc.get('document_type', 'unknown')
                doc_types[doc_type] = doc_types.get(doc_type, 0) + 1
                total_amount += doc.get('amount', 0)
            
            report['document_breakdown'] = doc_types
            report['processing_summary']['total_amount'] = total_amount
        
        # Add recommendations
        if report['check_summary']['rejected'] > 0:
            report['recommendations'].append("Review rejected rules and correct data issues")
        
        if report['check_summary']['pending'] > 0:
            report['recommendations'].append("Review pending rules manually")
        
        print(json.dumps(report, indent=2))

- id: save_processing_report
  name: save_processing_report
  tool: OUTPUT_FILE
  input:
    - name: content
      value: "{{steps.generate_processing_report.result.stdout}}"
    - name: filename
      value: "batch_processing_report_{{date | format('YYYY-MM-DD-HHmm')}}.json"
    - name: fileType
      value: "json"
```

## Extraction Modes

The `extractionMode` parameter is shared by `JINBA_MODULES_EXTRACT` and `JINBA_MODULES_PARSE`:

* **FAST**: Extracts data quickly. Best for high-volume processing of simple documents
* **BALANCED** (default): Extracts data with a balance of speed and accuracy. A good general-purpose choice
* **QUALITY**: Extracts data with the highest accuracy. Best for critical documents and complex layouts

## Output Formats

The `outputFormat` parameter of `JINBA_MODULES_PARSE` controls the shape of the parsed result:

* **MARKDOWN** (default): Output in Markdown format, preserving headings, tables, and lists
* **TEXT**: Output as plain text
* **STRUCTURED**: Output in a structured format

## Data Schema Design

The `dataSchema` parameter of `JINBA_MODULES_EXTRACT` accepts any valid JSON Schema.

### Basic Schema Structure

```json theme={null}
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "field_name": {
      "type": "string|number|object|array",
      "description": "Clear description of the field",
      "format": "date|email|uri|etc",
      "pattern": "regex_pattern_if_needed"
    }
  },
  "required": ["list_of_required_fields"]
}
```

### Advanced Schema Features

* **Nested objects**: Complex data structures
* **Arrays**: Multiple items of the same type
* **Conditional fields**: Fields dependent on other values
* **Pattern matching**: Regex validation
* **Format validation**: Date, email, URL formats

## Rule Format

The `rules` parameter of `JINBA_MODULES_CHECKER_V2` is a JSON array of rule objects. Each rule is evaluated against the target file by the LLM.

| Field         | Type   | Required | Description                                                                                          |
| ------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------- |
| `uniqueId`    | string | Yes      | Identifier echoed back in the corresponding check result                                             |
| `name`        | string | Yes      | Short rule name                                                                                      |
| `description` | string | Yes      | What the rule checks, written in natural language                                                    |
| `references`  | array  | No       | Rule-specific references: objects with `type` (`text` or `url`) and a matching `text` or `url` field |
| `examples`    | array  | No       | Example judgments to guide the evaluation                                                            |

### Check Results

Each entry in the `result` output corresponds to one rule:

* **`uniqueId`**: The rule's identifier
* **`rule`**: The rule that was evaluated
* **`status`**: `accepted`, `rejected`, or `pending`
* **`range`**: The location in the target the judgment refers to
* **`reason`**: Detailed reasoning behind the judgment
* **`additionalData`**: Extra fields matching `additionalDataSchema`, when provided

## Use Cases

* **Invoice Processing**: Automated invoice data extraction and validation
* **Document Digitization**: Convert paper documents to structured data
* **Data Migration**: Extract data from legacy systems
* **Compliance Checking**: Validate documents against regulations
* **Research Data**: Extract structured data from research documents
* **Form Processing**: Automate form data extraction
* **Contract Analysis**: Extract key terms from contracts
* **Financial Processing**: Process financial statements and reports

## Best Practices

### Schema Design

* Keep schemas simple and focused
* Use clear, descriptive field names
* Include comprehensive descriptions
* Test schemas with sample data
* Version your schemas for consistency

### Extraction Optimization

* Choose the appropriate extraction mode for your use case
* Provide high-quality input documents
* Use consistent document formats when possible
* Monitor extraction accuracy and adjust as needed

### Checking Strategy

* Write rule descriptions in clear, unambiguous natural language
* Give each rule a stable `uniqueId` so results can be traced over time
* Attach `references` (regulations, legal documents, RAG search results) to suppress hallucinations
* Review `pending` results manually and refine rules based on the `reason` output

### Performance Considerations

* Batch similar documents together
* Use FAST mode for simple, high-volume processing
* Use QUALITY mode only where accuracy is critical
* Implement error handling for failed extractions
