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

# Array Ordering

> How Data Legion sorts arrays deterministically: phones and emails by current status and confidence, locations by recency, experience and education by date, skills alphabetically, certifications by issue date, and company headcount history in chronological order.

All arrays in the output are sorted deterministically for consistency.

## Person Data

### Sorting Rules

* **`phones[]`, `emails[]`**: current items first, then by confidence (highest first)
* **`locations[]`**: most recently seen first (by `last_seen`)
* **`socials[]`**: current items first
* **`experience[]`**: current entries first, then by start date (most recent first)
* **`education[]`**: by start date, most recent first
* **Skills & Languages**: alphabetical
* **Certifications**: by issue date, most recent first

### Contact Data Arrays

#### Phones, Emails, Locations, Socials

Phones and emails place current items first, then higher confidence, so you can rely on the first phone or email being the best available contact method. Locations are ordered by most recently seen (`last_seen`). Socials place current items first.

Example phone array:

```json theme={null}
"phones": [
  {"type": "mobile", "number": "+15551234567", "current": true, "confidence": "high", "num_sources": 2, "last_seen": "2026-01-15"},
  {"type": "mobile", "number": "+15559876543", "current": true, "confidence": "moderate", "num_sources": 3, "last_seen": "2025-11-20"},
  {"type": "landline", "number": "+15551111111", "current": false, "confidence": "high", "num_sources": 4, "last_seen": "2024-06-01"}
]
```

### Experience & Education

Experience places current entries first (`current: true`), followed by past entries by start date (most recent first). You can rely on `experience[0]` being the current or most recent job. Education is sorted by start date, most recent first.

### Skills & Languages

These arrays are sorted alphabetically by the `cleaned` value:

```json theme={null}
"skills": [
  {"cleaned": "data analysis", "raw": ["Data Analysis"]},
  {"cleaned": "project management", "raw": ["Project Management", "PM"]},
  {"cleaned": "python", "raw": ["Python", "python3"]}
]
```

### Certifications

Sorted by issue date, most recent first:

```json theme={null}
"certifications": [
  {
    "name": {"cleaned": "aws certified solutions architect", "raw": ["AWS Certified Solutions Architect"]},
    "institution": {"cleaned": "amazon web services", "raw": ["Amazon Web Services"]},
    "credential_id": null,
    "issue_date": "2021-03",
    "expiration_date": "2024-03"
  },
  {
    "name": {"cleaned": "project management professional", "raw": ["Project Management Professional", "PMP"]},
    "institution": {"cleaned": "project management institute", "raw": ["Project Management Institute"]},
    "credential_id": "1234567",
    "issue_date": "2018-06",
    "expiration_date": "2024-06"
  }
]
```

## Company Data

### Sorting Rules

* **`legion_employee_count_by_month[]`**: chronological (oldest month first)
* **`domains[]`**, **`socials[]`**, **`tickers[]`**: no guaranteed ordering

<Note>
  Company `socials[]` do not include `confidence`, `num_sources`, `last_seen`, or `current` fields, so quality-based sorting does not apply. Person `socials[]` do include these fields and place current items first.
</Note>

### Headcount History

The `legion_employee_count_by_month[]` array places the oldest month first:

```json theme={null}
"legion_employee_count_by_month": [
  {"month": "2025-12", "count": 8450, "net_change": 65, "growth_rate": 0.008, "hires": 135, "departures": 70},
  {"month": "2026-01", "count": 8500, "net_change": 50, "growth_rate": 0.006, "hires": 120, "departures": 70}
]
```

## Why Deterministic Ordering Matters

1. **Consistency**: Same data always appears in the same order
2. **Predictability**: You can rely on `experience[0]` being the current job
3. **Filtering**: Easier to find primary contact methods
4. **Testing**: Deterministic output makes testing and validation easier

## Related Documentation

* **[Field Formats](/docs/data-standardization/field-formats)** - Format specifications
* **[Person Schema Example](/docs/person-data/schema)** - See person arrays in context
* **[Company Schema Example](/docs/company-data/schema)** - See company arrays in context
