Skip to main content

Document MRT API

The Document MRT API manages document-specific MRT (Machine-Readable Template) details including sections with nested extraction rules.

Update Document MRT

Full replacement (PUT) of a Document MRT including sections and extraction rules. All existing sections are deleted and replaced.
PUT /api/v1/document-mrt/{mrt_id}

Path Parameters

ParameterTypeRequiredDescription
mrt_idstringYesUUID of Document MRT

Request Body

{
  "docx_url": "s3://bucket/output.docx",
  "endpoint_analysis": "Analysis results",
  "output_name": "CSR_Final.docx",
  "connector_data_id": "connector-uuid",
  "rule_type_to_table_like_status": {
    "extraction": "table",
    "summary": "text"
  },
  "sections": [
    {
      "order_index": 0,
      "level": 1,
      "section_id": "section-1",
      "title": "Executive Summary",
      "synopsis": "Overview",
      "template_instructions": "Summarize findings",
      "template_text": "Template content",
      "additional_details": {
        "custom_field": "custom_value"
      },
      "relevant_chunk_ids": ["chunk-1", "chunk-2"],
      "relevant_chunk_names": ["Finding 1", "Finding 2"],
      "rules": [
        {
          "confidence_score": 0.95,
          "rule_type": "extraction",
          "rule_mode": "auto",
          "description": "Extract safety data",
          "explanation": "Extracted from protocol",
          "generated_content": "Generated summary text",
          "rule_parameters": {
            "include_tables": true
          }
        }
      ]
    }
  ],
  "auto_increment_regeneration": false
}

Request Parameters

ParameterTypeRequiredDescription
sectionsarrayYesSections with nested rules (at least one required)
docx_urlstringNoS3 URL of DOCX file
endpoint_analysisstringNoAnalysis text
output_namestringNoOutput file name
connector_data_idstringNoData connector ID
rule_type_to_table_like_statusobjectNoRule type mappings
auto_increment_regenerationbooleanNoAuto-increment regeneration count

Section Parameters

Each section must include:
ParameterTypeRequiredDescription
order_indexintegerYesPosition in document
levelintegerYesNesting level
section_idstringNoSection identifier
titlestringNoSection title
synopsisstringNoBrief summary
template_instructionsstringNoInstructions
template_textstringNoTemplate text
additional_detailsobjectNoJSONB metadata
relevant_chunk_idsarrayNoReferenced chunk IDs
relevant_chunk_namesarrayNoReferenced chunk names
rulesarrayNoNested extraction rules

Rule Parameters

ParameterTypeRequiredDescription
confidence_scorenumberNoConfidence level (0-1)
rule_typestringNoType of rule
rule_modestringNoRule operation mode
descriptionstringNoRule description
explanationstringNoExplanation of results
generated_contentstringNoGenerated content
rule_parametersobjectNoRule-specific parameters

Request Example

curl -X PUT "https://api.artosai.com/api/v1/document-mrt/mrt-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "sections": [
      {
        "order_index": 0,
        "level": 1,
        "section_id": "section-1",
        "title": "Executive Summary",
        "template_instructions": "Summarize",
        "rules": [
          {
            "rule_type": "extraction",
            "description": "Extract key findings",
            "confidence_score": 0.92
          }
        ]
      }
    ]
  }'

Python Example

import requests

url = "https://api.artosai.com/api/v1/document-mrt/mrt-uuid"
headers = {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
}

payload = {
    "sections": [
        {
            "order_index": 0,
            "level": 1,
            "section_id": "section-1",
            "title": "Executive Summary",
            "rules": [
                {
                    "rule_type": "extraction",
                    "confidence_score": 0.92
                }
            ]
        }
    ],
    "auto_increment_regeneration": True
}

response = requests.put(url, headers=headers, json=payload)
result = response.json()
print(f"Updated MRT")

Response

{
  "outline": {
    "mrt_id": "mrt-uuid",
    "sections": [
      {
        "order_index": 0,
        "level": 1,
        "section_id": "section-1",
        "title": "Executive Summary",
        "rules": [...]
      }
    ]
  }
}

Status Codes

  • 200 OK: Document MRT updated successfully
  • 400 Bad Request: Invalid MRT structure
  • 401 Unauthorized: Missing or invalid Bearer token
  • 403 Forbidden: User not authorized
  • 404 Not Found: Document MRT or parent document not found
  • 422 Unprocessable Entity: Request validation error
  • 500 Internal Server Error: Database error

Get Document MRT by Document ID

Retrieve the Document MRT for a specific parent document.
GET /api/v1/document-mrt/by-document/{document_id}

Path Parameters

ParameterTypeRequiredDescription
document_idstringYesUUID of parent document

Request Example

curl -X GET "https://api.artosai.com/api/v1/document-mrt/by-document/document-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "outline": {
    "mrt_id": "mrt-uuid",
    "document_id": "document-uuid",
    "sections": [
      {
        "order_index": 0,
        "level": 1,
        "section_id": "section-1",
        "title": "Executive Summary",
        "synopsis": "Summary",
        "rules": [
          {
            "rule_type": "extraction",
            "confidence_score": 0.95,
            "generated_content": "Generated content"
          }
        ]
      }
    ],
    "created_at": "2024-01-25T12:00:00Z",
    "updated_at": "2024-01-25T12:30:00Z"
  }
}

Status Codes

  • 200 OK: Document MRT retrieved successfully
  • 401 Unauthorized: Missing or invalid Bearer token
  • 403 Forbidden: User not authorized (document belongs to different organization)
  • 404 Not Found: Document not found or no MRT found for document
  • 500 Internal Server Error: Database error

Features

  • Auto-Sorted: Sections are automatically sorted by order_index
  • Hierarchical: Supports multiple nesting levels via level parameter
  • Rule Nesting: Each section can contain multiple nested rules
  • Organization-Scoped: Returns only MRTs belonging to authenticated user’s organization

Typical Workflow

# 1. Get document
DOC=$(curl -X GET "https://api.artosai.com/api/v1/documents/document-uuid" \
  -H "Authorization: Bearer $TOKEN")

# 2. Retrieve associated MRT
MRT=$(curl -X GET "https://api.artosai.com/api/v1/document-mrt/by-document/document-uuid" \
  -H "Authorization: Bearer $TOKEN")

# 3. Update MRT with new sections
curl -X PUT "https://api.artosai.com/api/v1/document-mrt/mrt-uuid" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "sections": [...]
  }'