{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/bol-ai/json-schema/bol-ai-extracted-document-schema.json",
  "title": "ExtractedDocument",
  "description": "One of the four freight-document field sets, distinguished by doc_type.",
  "x-generated": "2026-11-03",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/bol-ai-openapi.yml#/components/schemas/ExtractedDocument",
  "oneOf": [
    {
      "$ref": "#/$defs/BolFields"
    },
    {
      "$ref": "#/$defs/InvoiceFields"
    },
    {
      "$ref": "#/$defs/PackingListFields"
    },
    {
      "$ref": "#/$defs/CmrFields"
    }
  ],
  "$defs": {
    "BolFields": {
      "type": "object",
      "properties": {
        "doc_type": {
          "type": "string",
          "const": "bill_of_lading"
        },
        "bl_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "booking_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "scac": {
          "type": [
            "string",
            "null"
          ]
        },
        "carrier": {
          "type": [
            "string",
            "null"
          ]
        },
        "vessel": {
          "type": [
            "string",
            "null"
          ]
        },
        "voyage": {
          "type": [
            "string",
            "null"
          ]
        },
        "shipper": {
          "$ref": "#/$defs/Party"
        },
        "consignee": {
          "$ref": "#/$defs/Party"
        },
        "notify_party": {
          "$ref": "#/$defs/Party"
        },
        "port_of_loading": {
          "type": [
            "string",
            "null"
          ]
        },
        "port_of_discharge": {
          "type": [
            "string",
            "null"
          ]
        },
        "place_of_receipt": {
          "type": [
            "string",
            "null"
          ]
        },
        "place_of_delivery": {
          "type": [
            "string",
            "null"
          ]
        },
        "containers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Container"
          }
        },
        "hs_codes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "freight_terms": {
          "type": [
            "string",
            "null"
          ],
          "description": "PREPAID or COLLECT"
        },
        "incoterms": {
          "type": [
            "string",
            "null"
          ]
        },
        "date_of_issue": {
          "type": [
            "string",
            "null"
          ],
          "description": "YYYY-MM-DD"
        },
        "shipped_on_board_date": {
          "type": [
            "string",
            "null"
          ]
        },
        "number_of_originals": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "CmrFields": {
      "type": "object",
      "properties": {
        "doc_type": {
          "type": "string",
          "const": "cmr"
        },
        "cmr_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "place_of_issue": {
          "type": [
            "string",
            "null"
          ]
        },
        "date_of_issue": {
          "type": [
            "string",
            "null"
          ],
          "description": "YYYY-MM-DD"
        },
        "sender": {
          "$ref": "#/$defs/Party"
        },
        "consignee": {
          "$ref": "#/$defs/Party"
        },
        "carrier": {
          "$ref": "#/$defs/Party"
        },
        "place_of_taking_over": {
          "type": [
            "string",
            "null"
          ]
        },
        "place_of_delivery": {
          "type": [
            "string",
            "null"
          ]
        },
        "vehicle_registration": {
          "type": [
            "string",
            "null"
          ]
        },
        "goods": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CmrGoods"
          }
        },
        "total_gross_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "CmrGoods": {
      "type": "object",
      "properties": {
        "marks": {
          "type": [
            "string",
            "null"
          ]
        },
        "number_of_packages": {
          "type": [
            "number",
            "null"
          ]
        },
        "packing_method": {
          "type": [
            "string",
            "null"
          ]
        },
        "nature_of_goods": {
          "type": [
            "string",
            "null"
          ]
        },
        "gross_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "volume_cbm": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "Container": {
      "type": "object",
      "properties": {
        "container_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "seal_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "container_type": {
          "type": [
            "string",
            "null"
          ]
        },
        "packages": {
          "type": [
            "number",
            "null"
          ]
        },
        "package_type": {
          "type": [
            "string",
            "null"
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "gross_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "volume_cbm": {
          "type": [
            "number",
            "null"
          ]
        },
        "container_number_checksum_valid": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "ISO 6346 check-digit result; false signals a likely OCR misread"
        },
        "container_number_suggestion": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the number fails its checksum but a single OCR-confusion fix passes, the corrected number; null otherwise. The read value is never overwritten."
        }
      }
    },
    "InvoiceFields": {
      "type": "object",
      "properties": {
        "doc_type": {
          "type": "string",
          "const": "commercial_invoice"
        },
        "invoice_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "invoice_date": {
          "type": [
            "string",
            "null"
          ],
          "description": "YYYY-MM-DD"
        },
        "seller": {
          "$ref": "#/$defs/Party"
        },
        "buyer": {
          "$ref": "#/$defs/Party"
        },
        "incoterms": {
          "type": [
            "string",
            "null"
          ]
        },
        "currency": {
          "type": [
            "string",
            "null"
          ],
          "description": "3-letter ISO code"
        },
        "country_of_origin": {
          "type": [
            "string",
            "null"
          ]
        },
        "country_of_destination": {
          "type": [
            "string",
            "null"
          ]
        },
        "payment_terms": {
          "type": [
            "string",
            "null"
          ]
        },
        "related_bl_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "line_items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/InvoiceLineItem"
          }
        },
        "subtotal": {
          "type": [
            "number",
            "null"
          ]
        },
        "total_amount": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "InvoiceLineItem": {
      "type": "object",
      "properties": {
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "hs_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "quantity": {
          "type": [
            "number",
            "null"
          ]
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "unit_price": {
          "type": [
            "number",
            "null"
          ]
        },
        "amount": {
          "type": [
            "number",
            "null"
          ]
        }
      }
    },
    "PackingListFields": {
      "type": "object",
      "properties": {
        "doc_type": {
          "type": "string",
          "const": "packing_list"
        },
        "packing_list_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "date": {
          "type": [
            "string",
            "null"
          ],
          "description": "YYYY-MM-DD"
        },
        "shipper": {
          "$ref": "#/$defs/Party"
        },
        "consignee": {
          "$ref": "#/$defs/Party"
        },
        "related_invoice_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "related_bl_number": {
          "type": [
            "string",
            "null"
          ]
        },
        "total_packages": {
          "type": [
            "number",
            "null"
          ]
        },
        "total_gross_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "total_net_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "total_volume_cbm": {
          "type": [
            "number",
            "null"
          ]
        },
        "packages": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PackingListPackage"
          }
        }
      }
    },
    "PackingListPackage": {
      "type": "object",
      "properties": {
        "marks": {
          "type": [
            "string",
            "null"
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "quantity": {
          "type": [
            "number",
            "null"
          ]
        },
        "package_type": {
          "type": [
            "string",
            "null"
          ]
        },
        "net_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "gross_weight_kg": {
          "type": [
            "number",
            "null"
          ]
        },
        "dimensions": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "Party": {
      "type": "object",
      "properties": {
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "address": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}