Learn how to automatically detect and redact phone numbers from text, documents, and datasets. Handle international formats, extensions, and mobile numbers with precision while maintaining data utility for analytics.
Phone numbers are critical personally identifiable information (PII) that can directly contact individuals and often link to other personal data through reverse lookups.
Anonymization API uses sophisticated pattern recognition combined with contextual analysis to detect phone numbers with 99.2% accuracy across 200+ country formats. Our system handles the complexities of international dialing codes, local formatting conventions, extensions, and even phone numbers written in words or mixed formats.
Before Anonymization
After Anonymization
Whether you're processing customer support transcripts, scraping web data, or anonymizing medical records, our API ensures that phone numbers are consistently identified and redacted according to your privacy requirements.
Detect phone formats from every country and region worldwide
Properly detect ext., x, and other extension formats
Sub-100ms response for instant phone redaction
Phone numbers present unique privacy risks because they serve as both direct contact methods and identity verification tools. Understanding these risks helps you implement appropriate redaction strategies.
A phone number can be used to call or text someone directly, look up their name and address through reverse directories, or even access their accounts through SMS-based two-factor authentication exploits.
Phone numbers are personal data under Article 4. Processing requires lawful basis, and individuals have the right to erasure. Anonymization removes GDPR obligations from the data.
The Telephone Consumer Protection Act regulates how phone numbers can be used for marketing. Proper redaction helps demonstrate compliance with do-not-call requirements.
Phone numbers are personal information that consumers can request to be deleted. Anonymization satisfies deletion requirements while preserving data utility.
Phone numbers are one of the 18 HIPAA identifiers that must be removed for de-identification under the Safe Harbor method.
Personal data including phone numbers requires consent for collection and use. Anonymization provides an exemption.
Phone numbers are personal data requiring legal basis for processing under Brazil's data protection law.
Get started with phone number redaction in just a few lines of code. This example demonstrates the simplest way to detect and redact phone numbers from text using our API, handling international formats automatically.
from anonymization import Client client = Client(api_key="your_api_key") result = client.anonymize( text="Call me at (555) 123-4567 or +44 20 7946 0958", entity_types=["PHONE"] ) print(result.anonymized_text) # Output: Call me at [PHONE] or [PHONE]
const { AnonymizationClient } = require('@anonymization/api'); const client = new AnonymizationClient('your_api_key'); const result = await client.anonymize({ text: "Call me at (555) 123-4567 or +44 20 7946 0958", entityTypes: ["PHONE"] }); console.log(result.anonymizedText); // Output: Call me at [PHONE] or [PHONE]
curl -X POST https://api.anonymizationapi.com/v2/anonymize \ -H "Authorization: Bearer your_api_key" \ -H "Content-Type: application/json" \ -d '{ "text": "Call me at (555) 123-4567 or +44 20 7946 0958", "entity_types": ["PHONE"] }'
The API response includes detailed information about each detected phone number:
{
"anonymized_text": "Call me at [PHONE] or [PHONE]",
"entities": [
{
"type": "PHONE",
"text": "(555) 123-4567",
"start": 11,
"end": 25,
"confidence": 0.97,
"metadata": {
"country_code": "US",
"format": "NATIONAL"
}
},
{
"type": "PHONE",
"text": "+44 20 7946 0958",
"start": 29,
"end": 45,
"confidence": 0.99,
"metadata": {
"country_code": "GB",
"format": "INTERNATIONAL"
}
}
]
}
Phone numbers vary dramatically across countries and regions. Our API recognizes and properly handles all major international formats, including country-specific conventions for separators, groupings, and special numbers.
Phone numbers with extensions are fully supported in multiple notations:
Extension Formats
After Anonymization
You can specify the expected country to improve detection accuracy for local formats:
# Specify country for better local format detection result = client.anonymize( text="Call 020 7946 0958 for UK support", entity_types=["PHONE"], options={"phone_default_country": "GB"} ) # Without country hint, local formats may be ambiguous result = client.anonymize( text="Call 020 7946 0958 for UK support", entity_types=["PHONE"] ) # Still detected, but with lower confidence
Different scenarios require different approaches to phone number anonymization. Choose the technique that best balances privacy protection with your data utility requirements.
Completely replaces the phone number with a placeholder tag. Provides maximum privacy protection and is suitable for most compliance scenarios where the actual number has no analytical value.
Preserves some digits while masking others. Useful when you need to show that a phone number exists or verify partial matches without exposing the full number.
Replaces with a fake but valid-looking phone number. The same input number always generates the same pseudonym within a session, maintaining referential integrity. Perfect for creating realistic test data.
Keeps the country code visible while redacting the local number. Useful for geographic analysis where you need to know the country but not the individual.
Replaces with a description based on the phone type or purpose. Useful when preserving the semantic meaning of the data is important.
# Full redaction (default) result = client.anonymize(text, entity_types=["PHONE"], mode="redact") # Partial masking - show last 4 digits result = client.anonymize(text, entity_types=["PHONE"], mode="mask", options={"phone_mask_pattern": "show_last_4"}) # Format-preserving pseudonymization result = client.anonymize(text, entity_types=["PHONE"], mode="pseudonymize") # Country-preserving redaction result = client.anonymize(text, entity_types=["PHONE"], mode="redact", options={"phone_preserve_country": True}) # Generalization by phone type result = client.anonymize(text, entity_types=["PHONE"], mode="generalize")
Phone numbers can be combined with other data points for re-identification. Even partial phone numbers (like area codes) can narrow down geographic location. Consider your full data context when deciding redaction strategies.
Efficiently process multiple records containing phone numbers:
call_logs = [
"Incoming call from +1-555-123-4567 at 14:32",
"Outbound to (800) 555-0199 ext 234, duration 5:23",
"Missed call: +44 7911 123456 at 09:15",
"Voicemail from 555.867.5309"
]
results = client.batch_anonymize(
items=[{"text": log} for log in call_logs],
entity_types=["PHONE"]
)
for r in results:
print(r.anonymized_text)
# Incoming call from [PHONE] at 14:32
# Outbound to [PHONE], duration 5:23
# Missed call: [PHONE] at 09:15
# Voicemail from [PHONE]
Redact phone numbers along with names and emails for complete privacy:
contact_info = """ Customer: John Smith Email: [email protected] Phone: (555) 123-4567 Mobile: +1 555 987 6543 """ result = client.anonymize( text=contact_info, entity_types=["PERSON", "EMAIL", "PHONE"] ) print(result.anonymized_text) # Customer: [PERSON] # Email: [EMAIL] # Phone: [PHONE] # Mobile: [PHONE]
Process large files or streams with real-time phone number detection:
import asyncio async def process_stream(file_path): async with client.stream_anonymize( entity_types=["PHONE"] ) as stream: with open(file_path, 'r') as f: for line in f: result = await stream.process(line) print(result.anonymized_text) asyncio.run(process_stream("call_records.txt"))
Keep certain phone numbers (like your support line) visible while redacting customer numbers:
result = client.anonymize( text="Customer 555-123-4567 called our support line 1-800-555-0123", entity_types=["PHONE"], options={ "allow_list": ["1-800-555-0123", "18005550123"] } ) print(result.anonymized_text) # Customer [PHONE] called our support line 1-800-555-0123
Some number sequences could be phone numbers or other identifiers (order numbers, IDs). Enable context analysis to reduce false positives:
# Enable context-aware detection result = client.anonymize( text=text, entity_types=["PHONE"], options={"use_context": True} ) # "Order #5551234567" won't be detected as phone # "Call 5551234567" will be detected as phone
If you know the geographic context of your data, specify it to improve detection of local formats:
# For US-focused data result = client.anonymize( text=text, entity_types=["PHONE"], options={"phone_default_country": "US"} ) # For multi-country data, specify likely countries result = client.anonymize( text=text, entity_types=["PHONE"], options={"phone_countries": ["US", "CA", "GB"]} )
Decide whether extensions should be included in redaction or kept separate:
# Include extension in redaction (default) result = client.anonymize( text="Call 555-123-4567 ext 890", entity_types=["PHONE"] ) # Output: Call [PHONE] # Keep extension visible result = client.anonymize( text="Call 555-123-4567 ext 890", entity_types=["PHONE"], options={"phone_preserve_extension": True} ) # Output: Call [PHONE] ext 890
Before production deployment, test with representative samples of your actual data to ensure proper detection rates. Pay special attention to:
If you need to track the same phone number across records (e.g., for customer journey analysis), use session-based pseudonymization:
# Same session_id ensures same phone maps to same pseudonym result = client.anonymize( text=text, entity_types=["PHONE"], mode="pseudonymize", session_id="customer-analysis-2025-01" )
Caution: When using partial masking, ensure you mask enough digits. Showing the last 4 digits of a phone number along with area code may still allow identification in small geographic areas.
Our phone number detection achieves 99.2% accuracy on benchmark datasets covering 200+ country formats.
Yes, the API can detect phone numbers written as words like "five five five, one two three, four five six seven" or "1-800-FLOWERS". Enable the option with: options={"phone_detect_words": True}. Note this may increase false positives in some contexts.
Emergency numbers (911, 999, 112, etc.) are detected as phone numbers by default. You can choose to exclude them using: options={"phone_exclude_emergency": True}. This is recommended when you want to preserve emergency contact information.
Vanity numbers like 1-800-FLOWERS or 555-GET-HELP are detected and redacted. The API recognizes letter-to-number mappings used on phone keypads. The redacted output will be [PHONE] regardless of whether the original contained letters.
Yes, the API can optionally validate detected numbers against country-specific rules to determine if they could be real phone numbers. Enable with: options={"phone_validate": True}. Invalid formats will still be detected but marked with lower confidence.
Phone numbers in tel: links and click-to-call HTML are automatically detected. For example, <a href="tel:+15551234567"> will have the number redacted while preserving the HTML structure: <a href="tel:[PHONE]">.
Fax numbers are detected as phone numbers (they use the same format). If you need to distinguish them, the API uses context clues (like "fax:" prefix) to tag them as PHONE_FAX. You can redact or preserve fax numbers separately using: entity_types=["PHONE", "-PHONE_FAX"] to exclude fax numbers.
Get your free API key and protect phone numbers in your data within minutes. Handle any international format with confidence.
Get Started Free