How to extract and validate emails in Copilot in Fabric: step by step
This tutorial shows how to use Copilot in Fabric to identify, extract, normalize and validate email addresses in a data table. It is useful to prepare contact lists, deduplicate records and reduce errors before campaigns or analyses.
Prerequisites
- Account with access to Microsoft Fabric and Copilot enabled.
- A table (for example, in a Lakehouse or Warehouse) with a column that contains raw or mixed emails.
- Basic knowledge of prompts and the ability to create a Notebook or Dataflow in Fabric.
Step 1: Prepare the source data
Open the table in Fabric where the column with emails is located (e.g.: column named contact_info or email). Check a few examples to understand variations: strings with extra text, separators, multiple emails in a cell.
Step 2: Create an initial prompt to extract emails
Create a simple prompt in Copilot to locate email patterns using a regular expression. The goal is to return a list of emails per row or a single normalized email.
Prompt: "Extract all valid email addresses from the following column. Use regex to locate patterns @. Return a comma-separated list or empty if none. Column: {contact_info}"
This prompt instructs Copilot to apply a basic regex. In many cases Copilot already knows common patterns, but we can be explicit.
Step 3: Normalize emails (lowercase and remove spaces)
After extracting, ask Copilot to normalize: convert to lowercase, remove leading/trailing spaces or repeated dots outside the domain, and split multiple emails into distinct columns if needed.
Prompt: "For each extracted email, convert to lowercase, remove leading/trailing spaces, replace multiple consecutive '.' with a single '.', and split multiple emails in a cell into emails[0], emails[1], ..."
If you are using a Notebook in Fabric, you can apply a transformation in Python/SQL generated by Copilot. Minimal Python (pandas) example that Copilot may suggest:
import re
import pandas as pd
def extract_emails(text):
if not isinstance(text, str):
return []
pattern = r'[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,}'
return re.findall(pattern, text)
df = pd.read_csv('dados.csv')
df['emails_list'] = df['contact_info'].apply(extract_emails)
df['emails_normalized'] = df['emails_list'].apply(lambda lst: [e.strip().lower().replace('..','.') for e in lst])
Step 4: Validate syntax and domain
Validation at two levels: syntax (already done by the regex) and domain verification (for example, check if the domain looks legitimate or belongs to a list of valid domains). Use Copilot to generate a function that checks MX records or compares with a domain allowlist.
Prompt: "Generate code to validate email domain by checking if the domain belongs to the allowlist ['example.com','empresa.pt'] or perform an MX lookup (optional). Return 'valid'/'invalid' or 'unknown'."
Example of allowlist validation (quick and offline):
allowlist = {'example.com','empresa.pt'}
def validate_domain(email):
try:
domain = email.split('@')[1].lower()
return 'valid' if domain in allowlist else 'invalid'
except Exception:
return 'invalid'
# Apply
flat_emails = [e for lst in df['emails_normalized'] for e in lst]
For more advanced validation, you can ask Copilot for code that uses dnspython to query MX records, but that requires permissions and network access.
Step 5: Flag and automatically fix common errors
Ask Copilot to identify recurring errors (e.g.: 'user at domain dot com', extra spaces, missing '@') and propose automatic corrections. Create a column email_suggestion with the suggestion.
Prompt: "Detect patterns like ' at ', ' dot ' or 'usuario[at]dominio.com' and suggest corrections to the format 'user@domain.com'. Return None if there is no safe suggestion."
Simple heuristic example that Copilot may generate:
def suggest_fix(text):
s = text.lower()
s = s.replace(' at ', '@').replace('[at]', '@').replace(' dot ', '.')
s = s.replace(' (at) ', '@')
candidates = extract_emails(s)
return candidates[0] if candidates else None
df['email_suggestion'] = df['contact_info'].apply(suggest_fix)
Verify the outcome
Confirm that you have columns with: emails_list, emails_normalized, validation_status and email_suggestion. Manually validate samples: review corrected entries and flag false positives.
Practical checks: filter rows with validation_status != 'valid' and review; count the percentage of emails extracted vs total rows to assess coverage.
Conclusion
By using Copilot in Fabric to extract, normalize and validate emails, you save time cleaning and preparing contact data. Next steps: integrate MX validation for robustness, deduplicate by similarity and export to a CRM. Tip: start with a simple allowlist and expand with MX validations only after testing locally — do you prefer domain-based validation or real-time checks?