How can we make AI understand the difference between a cell phone number and a SSN, ID or DNI?
asked 15 hours ago by @qa-tfxp61t9jgvhehqroxj6 0 rep · 66 views
json parsing artificial intelligence
I need to parse a person's data from plain text. This data includes first name, last name, etc. It can also include phone number and SSN or DNI (used in Argentina, which can have 7 or 8 numeric characters).
It successfully extracts the data when both are present in the text, but it fails if only one is present. The AI does the following:
- Assigns cell phone number to DNI.
- Assigns DNI to cell phone number.
I have this inside the prompt indicating that it returns a json:
...
"identification": {
"type": "object",
"properties": {
"id_number": {"type": "string", "synonyms": ["DNI", "Identity document", "Document", "Passport", "passport", "Precaria", "documento", "identificacion"]},
"id_type": {
"type": "string",
"enum": ["DU", "PA", "CRP"],
"description": "Strictly map the document type. If the text mentions 'DNI', 'Documento Nacional de Identidad', 'Cédula', or 'DU', map it to 'DU'. If it mentions 'Pasaporte' or 'Passport', map to 'PA'. If it mentions 'Precaria' or 'Documento Precario', map to 'CRP'. Return null only if no document type is mentioned or inferable."
},
"cuil": {"type": "string", "format": {"regex": "[1-9]{2}\\-[0-9]{8}\\-[0-9]{1}"} }
}
},
"phone_number": {"type": "string", "description": "Extract the phone number exactly as written in the document."}
...
This is a fragment of the prompt I use as a rule:
- Identification vs. Phone Disambiguation (CRITICAL): In Argentina, national IDs (DU) strictly have 7 or 8 digits. Unlabeled 10-digit continuous numbers (like '1162323987' or any similar sequence) found at the top of the document, in the margins, or near an email address are MOBILE PHONES. You MUST extract them into 'phone_number' and NEVER put them in 'id_number' or 'cuil' unless they are explicitly labeled with words like 'DNI' or 'CUIL'.
Output example:
{
"identification": {
"id_number": null,
"id_type": null,
"cuil": null,
},
"phone": "111-22-3333"
}