Skip to content

NID Field Definitions ​

Every field extracted from a a Vietnamese NID — National Identity Card, known locally as Căn cước công dân (CCCD) or Thẻ căn cước (TCC) through OCR, QR parsing and MRZ parsing, with its canonical format, source, validation rules and normalization requirements.

Data Model ​

The extraction pipeline aggregates three independent sources into one unified dataset:

WhatDescription
OCROptical character recognition of the printed card surface.
QRThe official pipe-delimited QR payload encoded on the card.
MRZThe ICAO 9303-compliant machine-readable zone.
Image metadataCard bounding box and preprocessing references produced during extraction.
json
{
  "code": 0,
  "success": true,
  "data": {
    "image1": {},
    "image2": {},
    "status": "success",
    "request_id": "uuid",
    "card_information": []
  }
}

Identity Fields ​

FieldTypeDescription
idstringThe 12-digit Citizen Identification Number (Mã số định danh cá nhân). Format ^[0-9]{12}$. Source: OCR, QR, MRZ. Unique per citizen; encodes province, gender-century marker and a random sequence. MRZ checksum is optional.
id_1stringLegacy 9-digit CMND number. Format ^[0-9]{9}$. Source: QR only. Optional — present only if the citizen previously held an old ID card.
id_last_9stringLast 9 digits of the full NID number. Format ^[0-9]{9}$. Source: MRZ, which requires the truncated form.
genderstringNam (male) or Nữ (female). Source: OCR, QR, MRZ. Map MRZ M → Nam and F → Nữ.
dobstringDate of birth. DD/MM/YYYY from OCR/MRZ, DDMMYYYY from QR. Must produce a valid ISO date; transform to canonical YYYY-MM-DD.
nationalitystringFixed value Việt Nam. Source: OCR (front).

Name fields ​

FieldTypeDescription
namestringFull legal name. Unicode. Source: OCR, QR, MRZ. Uppercase from OCR, Title Case from QR/MRZ — normalize to Title Case.
last_namestringFamily name, e.g. NGUYỄN. Unicode. Source: OCR/MRZ. The first component.
middle_namestringMiddle name, e.g. VĂN. Unicode. Source: OCR/MRZ. Zero or more components.
first_namestringGiven name, e.g. A. Unicode. Source: OCR/MRZ. The last component.

Name normalization is required: remove extra spaces, convert to NFC Unicode, and standardize casing to your product rules.

Address Fields ​

Vietnamese addresses are hierarchical, from the province down to the residential group:

text
Level 1 → Level 2 → Level 3 → Level 4
Province → District → Ward → Hamlet/Group
FieldTypeDescription
addressstringFull printed residence address. Free text. Source: OCR. Used as a fallback when the hierarchical components cannot be reconstructed.
address_level_1_(city)stringProvince or centrally-managed city, e.g. TP. Hồ Chí Minh.
address_level_1_(city)_codestringProvincial administrative code, e.g. 79.
address_level_2_(district)stringDistrict-level administrative area, e.g. Quận 1.
address_level_2_(district)_codestringDistrict administrative code, e.g. 760.
address_level_3_(ward)stringWard, commune or township, e.g. Phường Bến Nghé.
address_level_3_(ward)_codestringWard administrative code, e.g. 26740.
address_level_4stringSmallest administrative unit — hamlet or residential group, e.g. Tổ 1.
native_placestringQuê quán — the citizen's registered birthplace, which is not necessarily their current residence. Usually <Ward/Commune>, <District>, <Province>. Source: OCR or QR.

Card Issuance Fields ​

FieldTypeDescription
issue_datestringDate the card was issued. DD/MM/YYYY from OCR, DDMMYYYY from QR. Normalize to ISO YYYY-MM-DD.
expiry_datestringDate the card expires — 20 years from issuance for ages 14–59, no expiration above 60. Format DD/MM/YYYY. Must be later than the issue date.
issue_placestringAuthority that issued the card, e.g. CỤC TRƯỞNG CỤC CẢNH SÁT QUẢN LÝ HÀNH CHÍNH VỀ TRẬT TỰ XÃ HỘI.
issue_place_codestringEncoded issuer ID. Format ^[0-9]{4}$, e.g. 7740 for the national police administration.
signaturestringSignature of the issuing officer, on the back of the card.

Card Metadata Fields ​

FieldTypeDescription
card_typestringCard version/type used for OCR processing, e.g. vn.cccd_new.
card_labelstringFront or back card type used by the OCR engine, e.g. vn.cccd_new.front, vn.cccd_new.back.

QR Code Fields ​

The official QR payload is a pipe-delimited string:

text
<NID>|<Legacy_ID>|<Name>|<DOB>|<Gender>|<Native_Place>|<Issue_Date>

Example:

text
001xxxxxxxxx|xxxxxxxxx|Nguyễn Văn A|12121990|Nam|Tổ 1, Phường Bến Nghé, Quận 1, TP. Hồ Chí Minh|01012021
FieldTypeDescription
idstringPosition 1 — NID number, 12 digits.
id_1stringPosition 2 — legacy ID number, 9 digits. Optional.
namestringPosition 3 — full name. Unicode.
dobstringPosition 4 — date of birth, DDMMYYYY.
genderstringPosition 5 — Nam or Nữ.
native_placestringPosition 6 — place of origin. Free text.
issue_datestringPosition 7 — issue date, DDMMYYYY.

MRZ Fields ​

The MRZ follows the ICAO 9303 standard for ID cards:

text
IDVNMxxxxxxxxxx001xxxxxxxxx<<x9012123M3012121VNM<<<<<<<<<<<xNGUYEN<<VAN<A<<<<<<<<<<<<<<<<<
FieldTypeDescription
document_typestringDocument type — ID.
country_codestringIssuing country — VNM.
idstringNID number.
id_last_9stringLast nine digits of the NID number.
dobstringDate of birth, YYMMDD.
genderstringM or F.
expiry_datestringExpiry date, YYMMDD.
namestringName in LAST<<MIDDLE<FIRST form.

Image Metadata ​

FieldTypeDescription
card_boxobjectBounding box of the card within the input image, used for perspective correction, cropping and alignment.
transformed_image_idstringInternal reference ID for the processed and normalized image.
json
{
  "top_left": { "x": 44, "y": 309 },
  "top_right": { "x": 734, "y": 309 },
  "bottom_left": { "x": 44, "y": 758 },
  "bottom_right": { "x": 734, "y": 758 }
}

Confidence Metrics ​

FieldTypeDescription
confidence_scorefloatProbability from 0 to 1 that OCR read this field correctly.
confidence_verdictstringOptional label — SURE for high certainty, empty for a normal reading.
digit_confidence_scoresfloat[]Per-digit probabilities, used for numeric fields such as ID codes.

Minimum recommended acceptance thresholds:

FieldTypeDescription
Critical fieldsid, name, dob>= 0.90
Secondary fieldsaddress, signature>= 0.80

Field Priority and Merge Rules ​

When the same field arrives from more than one source, prefer them in this order — most to least reliable:

  1. QR — encoded at issuance, not subject to recognition error.
  2. MRZ — machine-readable and checksum-protected.
  3. OCR — recognition of the printed surface, the most error-prone.
text
if QR.dob is valid: use QR
else if MRZ.dob is valid: use MRZ
else use OCR

Address reconstruction follows the same fallback logic:

text
address = join(level_4, level_3, level_2, level_1)
if OCR.address exists and structured parts fail: fallback to OCR.address

Error Handling Requirements ​

FieldTypeDescription
CARD_NOT_DETECTEDstringCard not found in the image. Behavior: request a rescan.
QR_PARSE_ERRORstringThe QR code could not be parsed. Behavior: continue with OCR/MRZ.
INCOMPLETE_DATAstringA critical field (id, name, dob) is missing. Behavior: fail the extraction.
LOW_CONFIDENCEstringA field scored below its threshold. Behavior: return a warning label.

Output Normalization Rules ​

  • All dates → YYYY-MM-DD
  • Names → Title Case
  • Address components → Title Case
  • Unicode normalization → NFC
  • Remove duplicate spaces and punctuation inconsistencies
FieldTypeDescription
idVARCHAR(12)Primary key — the NID number.
id_legacyVARCHAR(9)Legacy CMND number. Nullable.
full_nameTEXTFull legal name.
last_nameTEXTFamily name.
middle_nameTEXTMiddle name.
first_nameTEXTGiven name.
genderENUM('Male','Female')Normalized gender.
dobDATEDate of birth.
nationalityTEXTNationality.
native_placeTEXTRegistered birthplace.
addressTEXTFallback address string.
wardTEXTLevel 3 ward name.
ward_codeVARCHAR(10)Level 3 administrative code.
districtTEXTLevel 2 district name.
district_codeVARCHAR(10)Level 2 administrative code.
provinceTEXTLevel 1 province name.
province_codeVARCHAR(10)Level 1 administrative code.
issue_dateDATECard issue date.
expiry_dateDATECard expiry date.
issue_placeTEXTIssuing authority.
issue_place_codeVARCHAR(10)Issuing authority code.
signatureTEXTIssuing officer's signature.
confidence_overallFLOATAggregate extraction confidence.

WARNING

Every column above is personal data under Vietnamese data protection rules, and face_image from the chip is biometric. Encrypt at rest, restrict read access to callers with a business reason, and apply a retention policy — do not keep identity records longer than the relationship requires.

Suggested Additional Validations ​

  • Look up province, district and ward codes against the Vietnam administrative database.
  • Check date consistency — date of birth must be on or before the issue date.
  • Cross-check gender between the MRZ and the QR.

Next Steps ​

  • Read NFC — the API that returns these fields from the chip
  • Overview — the full transaction lifecycle

Developers