# Passport OCR: MRZ, Extracted Fields, and JSON Outputs

> Passport OCR explained: which fields come from the MRZ and visual zone, a JSON schema, cited output, check digits, and the checks extraction cannot replace.

Canonical: https://reducto.ai/guides/passport-ocr

## The short answer

Passport OCR reads a passport's identity page and returns its printed data as structured fields: name, passport number, nationality, dates of birth and expiry, and the two-line machine-readable zone (MRZ). A useful passport OCR API returns JSON your application can validate and trace back to the page.

[Reducto Extract](https://reducto.ai/extract) takes a JSON schema you define and returns the requested passport fields, with optional [citations](https://docs.reducto.ai/configs/extract/citations) that point each value to its page location. MRZ check-digit validation, document authentication, and identity verification are separate steps. Extraction reads what is printed; it does not prove that a passport is genuine or belongs to the person presenting it.

## What passport OCR extracts

A passport data page has two zones. The visual inspection zone holds the human-readable fields and photo. The MRZ repeats core fields in a fixed format defined by [ICAO Doc 9303](https://www.icao.int/publications/doc-series/doc-9303). Passport data extraction usually needs both, because each zone contains something the other lacks.

<Table html={"<table>\n  <thead>\n    <tr>\n      <th>Field</th>\n      <th>In the MRZ</th>\n      <th>In the visual zone</th>\n      <th>Notes</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Document type and issuing state</td>\n      <td>Yes, positions 1–5 of line 1</td>\n      <td>Yes</td>\n      <td>Three-letter codes, such as the fictional UTO used in ICAO specimens</td>\n    </tr>\n    <tr>\n      <td>Surname and given names</td>\n      <td>Yes, uppercase A–Z with &lt; separators</td>\n      <td>Yes, as printed</td>\n      <td>MRZ names are transliterated and may be truncated to fit 39 characters</td>\n    </tr>\n    <tr>\n      <td>Passport number</td>\n      <td>Yes, with a check digit</td>\n      <td>Yes</td>\n      <td>Up to 9 characters in the MRZ</td>\n    </tr>\n    <tr>\n      <td>Nationality</td>\n      <td>Yes, three-letter code</td>\n      <td>Yes, often as a word</td>\n      <td>No check digit covers this field</td>\n    </tr>\n    <tr>\n      <td>Date of birth</td>\n      <td>Yes, YYMMDD with a check digit</td>\n      <td>Yes, full date</td>\n      <td>The MRZ uses a two-digit year</td>\n    </tr>\n    <tr>\n      <td>Sex</td>\n      <td>Yes, F, M, or &lt;</td>\n      <td>Yes</td>\n      <td>Store the printed value; do not infer it</td>\n    </tr>\n    <tr>\n      <td>Date of expiry</td>\n      <td>Yes, YYMMDD with a check digit</td>\n      <td>Yes, full date</td>\n      <td>Compare against your own review date</td>\n    </tr>\n    <tr>\n      <td>Personal number</td>\n      <td>Optional, 14 characters</td>\n      <td>Sometimes</td>\n      <td>Use depends on the issuing state</td>\n    </tr>\n    <tr>\n      <td>Place of birth, date of issue, authority</td>\n      <td>No</td>\n      <td>Yes</td>\n      <td>Only available from the visual zone</td>\n    </tr>\n  </tbody>\n</table>"} />

## MRZ versus visual fields

A passport (the TD3 format in Doc 9303) has two MRZ lines of 44 characters each, using only A–Z, 0–9, and the filler character `<`. Line 1 holds the document type, issuing state, and name. Line 2 holds the passport number, nationality, date of birth, sex, expiry date, optional personal number, and check digits.

Each check digit is computed with repeating weights of 7, 3, and 1, with letters counted as 10–35 and fillers as 0. Line 2 has check digits for the passport number, birth date, expiry date, and personal number, plus a final composite digit over most of the line. That makes passport MRZ OCR easier to validate than free-form text, but it has limits:

- Nationality and the name line are not covered by any check digit.
- Two-digit years need a rule to decide the century.
- Names lose accents and punctuation, and long names are truncated.
- Place of birth, date of issue, and issuing authority are not in the MRZ.

The visual zone has the printed name, four-digit years, and the extra fields, but layouts vary by issuing state. Extract both and compare them.

## Field schema and example JSON

This example uses a synthetic passport image we generated with a fictional issuing state, not a real identity document. The schema asks for normalized visual-zone fields plus both raw MRZ lines:

```python
import json
from pathlib import Path
from reducto import Reducto

schema = {
    "type": "object",
    "properties": {
        "issuing_state": {"type": "string", "description": "Three-letter issuing state code"},
        "passport_number": {"type": "string", "description": "Passport number in the visual zone"},
        "surname": {"type": "string", "description": "Surname as printed, with accents"},
        "given_names": {"type": "string", "description": "Given names as printed"},
        "date_of_birth": {"type": "string", "description": "Date of birth in YYYY-MM-DD format"},
        "sex": {"type": "string", "enum": ["F", "M", "X"]},
        "place_of_birth": {"type": "string", "description": "Place of birth in the visual zone"},
        "date_of_issue": {"type": "string", "description": "Date of issue in YYYY-MM-DD format"},
        "date_of_expiry": {"type": "string", "description": "Date of expiry in YYYY-MM-DD format"},
        "mrz_line_1": {"type": "string", "description": "First MRZ line exactly as printed"},
        "mrz_line_2": {"type": "string", "description": "Second MRZ line exactly as printed"},
    },
}

client = Reducto()  # reads REDUCTO_API_KEY
upload = client.upload(file=Path("synthetic-passport.png"))
result = client.extract.run(
    input=upload.file_id,
    instructions={
        "schema": schema,
        "system_prompt": "Extract passport data page fields. Return null for any field not printed.",
    },
    settings={"citations": {"enabled": True}},
)
print(json.dumps(result.model_dump(mode="json")["result"], indent=2))
```

We ran this with `reductoai==0.24.0` on Python 3.12. Trimmed output:

```json
{
  "surname": {
    "value": "RIVERA NÚÑEZ",
    "citations": [{"content": "RIVERA NÚÑEZ", "confidence": "high", "bbox": {"page": 1, "left": 0.296, "top": 0.242}}]
  },
  "date_of_birth": {
    "value": "1990-03-14",
    "citations": [{"content": "1990-03-14", "confidence": "high", "bbox": {"page": 1, "left": 0.3824, "top": 0.4307}}]
  },
  "place_of_birth": {"value": "PORT ALDER", "citations": ["..."]},
  "mrz_line_1": {"value": "P<UTORIVERA<NUNEZ<<MARISOL<ANDREA<<<<<<<<<<<", "citations": ["..."]},
  "mrz_line_2": {
    "value": "X7R4K29P18UT09003141F3412318<<<<<<<<<<<<<<00",
    "citations": [{"confidence": "high", "granular_confidence": {"extract_confidence": 0.943}}]
  }
}
```

Every visual-zone field matched the synthetic page. The second MRZ line did not: the page prints `UTO`, but the output reads `UT0`, with a zero. Nationality has no check digit, so all five check digits on this line still pass, and the citation was marked high confidence. This is one synthetic test, not a benchmark, but it shows why the checks below matter.

## Source citations and missing values

With citations enabled, each value comes back with `value` and `citations`. Each citation has the source text, a normalized bounding box with page number, a `high` or `low` confidence label, and numeric `extract_confidence` and `parse_confidence` scores, per the [Extract response format](https://docs.reducto.ai/extract/response-format). Reviewers can open the cited region instead of rereading the scan.

Extract returns every schema field. A scalar value that is not on the page comes back as `null`. The [schema keyword reference](https://docs.reducto.ai/extract/schema-keywords) lists enforced keywords, such as `enum` and `pattern`, and guidance-only ones, such as `format`. Treat `null` in a required field as a review case.

## Checks outside extraction

Run these checks in your application after extraction:

1. Confirm each MRZ line is 44 characters and recompute its check digits.
2. Compare MRZ fields with visual fields: passport number, nationality and issuing state, names after transliteration, and dates after resolving the century.
3. Check expiry against an explicit review date.
4. Route mismatches, nulls, and low-confidence citations to a reviewer.

A minimal check-digit function, tested with Python 3.12 on the synthetic line and on the published ICAO specimen:

```python
def check_digit(field: str) -> int:
    weights = (7, 3, 1)
    total = 0
    for i, ch in enumerate(field):
        value = int(ch) if ch.isdigit() else ord(ch) - 55 if ch.isalpha() else 0
        total += value * weights[i % 3]
    return total % 10

line = "X7R4K29P18UT09003141F3412318<<<<<<<<<<<<<<00"
print(check_digit(line[0:9]) == int(line[9]))   # True
print(line[10:13].isalpha())                    # False: nationality must be letters
```

Passing these checks shows the extracted text is internally consistent, not that the passport is authentic. Security-feature inspection, chip reading, face matching, liveness, and sanctions screening belong to identity verification and compliance systems.

## Try the schema with Reducto

Upload a synthetic or properly authorized test passport to [Reducto Studio](https://studio.reducto.ai), paste the schema above into an Extract pipeline, and inspect the cited fields. For workflows built on the same pattern, see the [KYC document refresh cookbook](https://reducto.ai/cookbooks/kyc-document-refresh), which compares identity-document numbers and expiry dates with a customer profile, and the [international registration packet cookbook](https://reducto.ai/cookbooks/international-registration-packet), which reconciles names and birth dates across records. The [schema-based extraction guide](https://reducto.ai/guides/schema-based-document-extraction) covers schema design in more depth.

## Frequently asked questions

### What is passport MRZ OCR?

OCR of the two 44-character lines at the bottom of the data page. Their fixed format and check digits let you test the passport number, birth date, and expiry date after reading.

### Is a passport OCR API enough for KYC?

No. It captures data for a KYC process. Authentication, matching the document to the person, and screening are separate steps.

### Which file types can I send?

Reducto accepts PDFs and common image formats, including PNG, JPEG, TIFF, and HEIC, according to its [supported file types](https://docs.reducto.ai/upload/overview).

### Should I extract the MRZ or the visual fields?

Both. The MRZ has a fixed format and check digits; the visual zone has full names and fields the MRZ omits. Disagreement between them is a review signal.
