Files
2026-07-04 15:29:51 +00:00

5373 lines
126 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="PII anonymization for text, images, and structured data.">
<meta name="author" content="Data Privacy Stack">
<link rel="canonical" href="https://data-privacy-stack.github.io/presidio/samples/python/synth_data_with_openai/">
<link rel="prev" href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/example_custom_lambda_anonymizer.py">
<link rel="next" href="../no_code_config/">
<link rel="icon" href="../../../assets/dps-icon.svg">
<meta name="generator" content="zensical-0.0.46">
<title>Use Presidio + OpenAI to turn real text into fake text - Presidio</title>
<link rel="stylesheet" href="../../../assets/stylesheets/modern/main.19d3147f.min.css">
<link rel="stylesheet" href="../../../assets/stylesheets/modern/palette.dfe2e883.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,300i,400,400i,500,500i,700,700i%7CJetBrains+Mono:400,400i,700,700i&amp;display=fallback">
<style>:root{--md-text-font:"Inter";--md-code-font:"JetBrains Mono"}</style>
<link rel="stylesheet" href="../../../stylesheets/extra.css">
<script>__md_scope=new URL("../../..",location),__md_scope.pathname.endsWith("/")||(__md_scope=new URL(__md_scope.pathname+"/",location)),__md_hash=e=>[...e].reduce(((e,t)=>(e<<5)-e+t.charCodeAt(0)),0),__md_get=(e,t=localStorage,_=__md_scope)=>JSON.parse(t.getItem(_.pathname+"."+e)),__md_set=(e,t,_=localStorage,a=__md_scope)=>{try{_.setItem(a.pathname+"."+e,JSON.stringify(t))}catch(e){}},document.documentElement.setAttribute("data-platform",navigator.platform)</script>
<!-- Microsoft Clarity with Consent Mode -->
<script type="text/javascript">
(function () {
// Determine the current consent state before loading Clarity
var storedConsent = null;
try {
storedConsent = window.localStorage && window.localStorage.getItem("clarity_consent");
} catch (e) {
// If localStorage is unavailable (e.g., privacy mode), fall back to denied
storedConsent = null;
}
// Default to "denied" when there is no prior explicit "granted" choice
var defaultConsent = storedConsent === "granted" ? "granted" : "denied";
(function (c, l, a, r, i, t, y) {
c[a] = c[a] || function () {
(c[a].q = c[a].q || []).push(arguments);
};
// Set consentv2 state before loading the Clarity script so it honors consent immediately
c[a]("consentv2", {
ad_Storage: defaultConsent,
analytics_Storage: defaultConsent
});
t = l.createElement(r);
t.async = 1;
t.src = "https://www.clarity.ms/tag/" + i;
y = l.getElementsByTagName(r)[0];
y.parentNode.insertBefore(t, y);
})(window, document, "clarity", "script", "5pd40fk720");
})();
</script>
<!-- Cookie consent banner -->
<style>
#cookie-consent-banner {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: var(--md-default-bg-color, #fff);
border-top: 1px solid var(--md-default-fg-color--lightest, #e0e0e0);
padding: 1rem 1.5rem;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 1rem;
z-index: 9999;
box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
font-size: 0.82rem;
}
#cookie-consent-banner p {
margin: 0;
flex: 1 1 300px;
color: var(--md-default-fg-color, #333);
}
#cookie-consent-banner a {
color: var(--md-accent-fg-color, #448aff);
}
#cookie-consent-banner .consent-buttons {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
}
#cookie-consent-banner button {
padding: 0.4rem 1.2rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.82rem;
font-weight: 500;
}
#cookie-consent-accept {
background: var(--md-primary-fg-color, #4051b5);
color: var(--md-primary-bg-color, #fff);
}
#cookie-consent-decline {
background: var(--md-default-fg-color--lightest, #e0e0e0);
color: var(--md-default-fg-color, #333);
}
</style>
<script type="text/javascript">
(function() {
if (localStorage.getItem("clarity_consent")) return;
var banner = document.createElement("div");
banner.id = "cookie-consent-banner";
banner.setAttribute("role", "dialog");
banner.setAttribute("aria-label", "Cookie consent");
banner.innerHTML =
'<p>This site uses cookies via Microsoft Clarity to understand how you use our documentation. ' +
'<a href="https://learn.microsoft.com/en-us/clarity/setup-and-installation/clarity-cookies" ' +
'target="_blank" rel="noopener">Learn more</a></p>' +
'<div class="consent-buttons">' +
'<button id="cookie-consent-decline">Decline</button>' +
'<button id="cookie-consent-accept">Accept</button>' +
'</div>';
document.addEventListener("DOMContentLoaded", function() {
document.body.appendChild(banner);
document.getElementById("cookie-consent-accept").addEventListener("click", function() {
localStorage.setItem("clarity_consent", "granted");
window.clarity("consentv2", {
ad_Storage: "granted",
analytics_Storage: "granted"
});
banner.remove();
});
document.getElementById("cookie-consent-decline").addEventListener("click", function() {
localStorage.setItem("clarity_consent", "denied");
window.clarity("consentv2", {
ad_Storage: "denied",
analytics_Storage: "denied"
});
banner.remove();
});
});
})();
</script>
<meta name="google-site-verification" content="XTJynzxw5KJpNFN8WemNurQh1lj33OTCbkDbQr8267k" />
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="custom" data-md-color-accent="custom">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer" aria-label="Navigation"></label>
<div data-md-component="skip">
<a href="#path-to-notebook-httpswwwgithubcomdata-privacy-stackpresidioblobmaindocssamplespythonsynth_data_with_openaiipynb" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header md-header--shadow md-header--lifted" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../../.." title="Presidio" class="md-header__button md-logo" aria-label="Presidio" data-md-component="logo">
<img src="../../../assets/dps-icon.svg" alt="Presidio">
</a>
<label class="md-header__button md-icon" for="__drawer" aria-label="Navigation">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-menu" viewBox="0 0 24 24"><path d="M4 5h16M4 12h16M4 19h16"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Presidio
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Use Presidio + OpenAI to turn real text into fake text
</span>
</div>
</div>
</div>
<form class="md-header__option" data-md-component="palette">
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="custom" data-md-color-accent="custom" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_0">
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m17.75 4.09-2.53 1.94.91 3.06-2.63-1.81-2.63 1.81.91-3.06-2.53-1.94L12.44 4l1.06-3 1.06 3zm3.5 6.91-1.64 1.25.59 1.98-1.7-1.17-1.7 1.17.59-1.98L15.75 11l2.06-.05L18.5 9l.69 1.95zm-2.28 4.95c.83-.08 1.72 1.1 1.19 1.85-.32.45-.66.87-1.08 1.27C15.17 23 8.84 23 4.94 19.07c-3.91-3.9-3.91-10.24 0-14.14.4-.4.82-.76 1.27-1.08.75-.53 1.93.36 1.85 1.19-.27 2.86.69 5.83 2.89 8.02a9.96 9.96 0 0 0 8.02 2.89m-1.64 2.02a12.08 12.08 0 0 1-7.8-3.47c-2.17-2.19-3.33-5-3.49-7.82-2.81 3.14-2.7 7.96.31 10.98 3.02 3.01 7.84 3.12 10.98.31"/></svg>
</label>
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="custom" data-md-color-accent="custom" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_1">
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 7a5 5 0 0 1 5 5 5 5 0 0 1-5 5 5 5 0 0 1-5-5 5 5 0 0 1 5-5m0 2a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0-7 2.39 3.42C13.65 5.15 12.84 5 12 5s-1.65.15-2.39.42zM3.34 7l4.16-.35A7.2 7.2 0 0 0 5.94 8.5c-.44.74-.69 1.5-.83 2.29zm.02 10 1.76-3.77a7.131 7.131 0 0 0 2.38 4.14zM20.65 7l-1.77 3.79a7.02 7.02 0 0 0-2.38-4.15zm-.01 10-4.14.36c.59-.51 1.12-1.14 1.54-1.86.42-.73.69-1.5.83-2.29zM12 22l-2.41-3.44c.74.27 1.55.44 2.41.44.82 0 1.63-.17 2.37-.44z"/></svg>
</label>
</form>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<label class="md-header__button md-icon" for="__search" aria-label="Search">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-search" viewBox="0 0 24 24"><path d="m21 21-4.34-4.34"/><circle cx="11" cy="11" r="8"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog" aria-label="Search">
<button type="button" class="md-search__button">
Search
</button>
</div>
<div class="md-header__source">
<a href="https://github.com/data-privacy-stack/presidio/" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
</nav>
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
<div class="md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item">
<a href="../../.." class="md-tabs__link">
Presidio
</a>
</li>
<li class="md-tabs__item">
<a href="../../../getting_started/" class="md-tabs__link">
Quick start
</a>
</li>
<li class="md-tabs__item">
<a href="../../../learn_presidio/" class="md-tabs__link">
Learn Presidio
</a>
</li>
<li class="md-tabs__item">
<a href="../../../supported_entities/" class="md-tabs__link">
Resources
</a>
</li>
<li class="md-tabs__item">
<a href="../../../recipes/" class="md-tabs__link">
Recipes
</a>
</li>
<li class="md-tabs__item md-tabs__item--active">
<a href="../../" class="md-tabs__link">
Samples
</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../../.." title="Presidio" class="md-nav__button md-logo" aria-label="Presidio" data-md-component="logo">
<img src="../../../assets/dps-icon.svg" alt="Presidio">
</a>
Presidio
</label>
<div class="md-nav__source">
<a href="https://github.com/data-privacy-stack/presidio/" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_1" >
<label class="md-nav__link" for="__nav_1" id="__nav_1_label" tabindex="0">
<span class="md-ellipsis">
Presidio
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_1_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_1">
<span class="md-nav__icon md-icon"></span>
Presidio
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../.." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../installation/" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../faq/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" >
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
Quick start
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
Quick start
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../getting_started/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../getting_started/getting_started_text/" class="md-nav__link">
<span class="md-ellipsis">
Text
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../getting_started/getting_started_images/" class="md-nav__link">
<span class="md-ellipsis">
Images
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../getting_started/getting_started_structured/" class="md-nav__link">
<span class="md-ellipsis">
Semi/Structured data
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Learn Presidio
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Learn Presidio
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../learn_presidio/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../learn_presidio/concepts/" class="md-nav__link">
<span class="md-ellipsis">
Concepts
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_3" >
<label class="md-nav__link" for="__nav_3_3" id="__nav_3_3_label" tabindex="0">
<span class="md-ellipsis">
Tutorial
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_3">
<span class="md-nav__icon md-icon"></span>
Tutorial
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../tutorial/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/00_getting_started/" class="md-nav__link">
<span class="md-ellipsis">
Getting started
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/01_deny_list/" class="md-nav__link">
<span class="md-ellipsis">
Deny-list recognizers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/02_regex/" class="md-nav__link">
<span class="md-ellipsis">
Regex recognizers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/03_rule_based/" class="md-nav__link">
<span class="md-ellipsis">
Rule-based recognizers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/05_languages/" class="md-nav__link">
<span class="md-ellipsis">
Additional models/languages
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/04_external_services/" class="md-nav__link">
<span class="md-ellipsis">
External services
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/06_context/" class="md-nav__link">
<span class="md-ellipsis">
Context enhancement
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/07_decision_process/" class="md-nav__link">
<span class="md-ellipsis">
Decision process
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/08_no_code/" class="md-nav__link">
<span class="md-ellipsis">
No-code recognizers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/09_ad_hoc/" class="md-nav__link">
<span class="md-ellipsis">
Ad-hoc recognizers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/10_simple_anonymization/" class="md-nav__link">
<span class="md-ellipsis">
Simple anonymization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/11_custom_anonymization/" class="md-nav__link">
<span class="md-ellipsis">
Custom anonymization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/12_encryption/" class="md-nav__link">
<span class="md-ellipsis">
Encryption/Decryption
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../tutorial/13_allow_list/" class="md-nav__link">
<span class="md-ellipsis">
Allow-lists
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4" >
<label class="md-nav__link" for="__nav_3_4" id="__nav_3_4_label" tabindex="0">
<span class="md-ellipsis">
Text de-identification
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_4">
<span class="md-nav__icon md-icon"></span>
Text de-identification
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../text_anonymization/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4_2" >
<label class="md-nav__link" for="__nav_3_4_2" id="__nav_3_4_2_label" tabindex="0">
<span class="md-ellipsis">
Presidio Analyzer
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="3" aria-labelledby="__nav_3_4_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_4_2">
<span class="md-nav__icon md-icon"></span>
Presidio Analyzer
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../analyzer/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4_2_2" >
<label class="md-nav__link" for="__nav_3_4_2_2" id="__nav_3_4_2_2_label" tabindex="0">
<span class="md-ellipsis">
Developing PII recognizers
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="4" aria-labelledby="__nav_3_4_2_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_4_2_2">
<span class="md-nav__icon md-icon"></span>
Developing PII recognizers
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../analyzer/adding_recognizers/" class="md-nav__link">
<span class="md-ellipsis">
Tutorial
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/developing_recognizers/" class="md-nav__link">
<span class="md-ellipsis">
Best practices
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/recognizer_registry_provider/" class="md-nav__link">
<span class="md-ellipsis">
Recognizer registry from file
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/filtering_by_country/" class="md-nav__link">
<span class="md-ellipsis">
Filtering recognizers by country
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/languages/" class="md-nav__link">
<span class="md-ellipsis">
Multi-language support
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4_2_5" >
<label class="md-nav__link" for="__nav_3_4_2_5" id="__nav_3_4_2_5_label" tabindex="0">
<span class="md-ellipsis">
Customizing the NLP model
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="4" aria-labelledby="__nav_3_4_2_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_4_2_5">
<span class="md-nav__icon md-icon"></span>
Customizing the NLP model
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../analyzer/customizing_nlp_models/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/nlp_engines/spacy_stanza/" class="md-nav__link">
<span class="md-ellipsis">
Spacy/Stanza
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/nlp_engines/transformers/" class="md-nav__link">
<span class="md-ellipsis">
Transformers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/nlp_engines/gpu_usage/" class="md-nav__link">
<span class="md-ellipsis">
GPU Acceleration
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/decision_process/" class="md-nav__link">
<span class="md-ellipsis">
Tracing the decision process
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../analyzer/analyzer_engine_provider/" class="md-nav__link">
<span class="md-ellipsis">
Configure from file
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4_3" >
<label class="md-nav__link" for="__nav_3_4_3" id="__nav_3_4_3_label" tabindex="0">
<span class="md-ellipsis">
Presidio Anonymizer
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="3" aria-labelledby="__nav_3_4_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_4_3">
<span class="md-nav__icon md-icon"></span>
Presidio Anonymizer
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../anonymizer/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../anonymizer/adding_operators/" class="md-nav__link">
<span class="md-ellipsis">
Developing PII anonymization operators
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../../ahds_integration/" class="md-nav__link">
<span class="md-ellipsis">
Azure Health Data Services de-identification service integration
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_6" >
<label class="md-nav__link" for="__nav_3_6" id="__nav_3_6_label" tabindex="0">
<span class="md-ellipsis">
Image de-identification
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_6">
<span class="md-nav__icon md-icon"></span>
Image de-identification
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../image-redactor/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../image-redactor/evaluating_dicom_redaction/" class="md-nav__link">
<span class="md-ellipsis">
Evaluating DICOM redaction
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_7" >
<label class="md-nav__link" for="__nav_3_7" id="__nav_3_7_label" tabindex="0">
<span class="md-ellipsis">
Structured and Semi-structured
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_7">
<span class="md-nav__icon md-icon"></span>
Structured and Semi-structured
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../structured/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../../evaluation/" class="md-nav__link">
<span class="md-ellipsis">
PII detection evaluation
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Resources
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Resources
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../supported_entities/" class="md-nav__link">
<span class="md-ellipsis">
Supported entities
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../project_transition/" class="md-nav__link">
<span class="md-ellipsis">
Project transition update
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../community/" class="md-nav__link">
<span class="md-ellipsis">
Community
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/CHANGELOG.md" class="md-nav__link">
<span class="md-ellipsis">
Change log
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../development/" class="md-nav__link">
<span class="md-ellipsis">
Setting up a development environment
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../build_release/" class="md-nav__link">
<span class="md-ellipsis">
Build and release process
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../presidio_V2/" class="md-nav__link">
<span class="md-ellipsis">
Changes from V1 to V2
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_8" >
<label class="md-nav__link" for="__nav_4_8" id="__nav_4_8_label" tabindex="0">
<span class="md-ellipsis">
Python API reference
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_8_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4_8">
<span class="md-nav__icon md-icon"></span>
Python API reference
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../api/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../api/analyzer_python/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Analyzer Python API
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../api/anonymizer_python/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Anonymizer Python API
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../api/image_redactor_python/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Image Redactor Python API
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../api/structured_python/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Structured Python API
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="https://data-privacy-stack.github.io/presidio/api-docs/api-docs.html" target="_blank" class="md-nav__link">
<span class="md-ellipsis">
REST API reference
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Recipes
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Recipes
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../recipes/" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../recipes/CONTRIBUTING/" class="md-nav__link">
<span class="md-ellipsis">
Contributing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../recipes/template/" class="md-nav__link">
<span class="md-ellipsis">
Template
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--section md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" checked>
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="">
<span class="md-ellipsis">
Samples
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_6">
<span class="md-nav__icon md-icon"></span>
Samples
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../" class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_2" checked>
<label class="md-nav__link" for="__nav_6_2" id="__nav_6_2_label" tabindex="0">
<span class="md-ellipsis">
Text
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_2_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_6_2">
<span class="md-nav__icon md-icon"></span>
Text
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../presidio_notebook/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Basic Usage Notebook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../customizing_presidio_analyzer/" class="md-nav__link">
<span class="md-ellipsis">
Customizing Presidio Analyzer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../ner_model_configuration/" class="md-nav__link">
<span class="md-ellipsis">
Configuring The NLP engine
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../encrypt_decrypt/" class="md-nav__link">
<span class="md-ellipsis">
Encrypting and Decrypting identified entities
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../getting_entity_values/" class="md-nav__link">
<span class="md-ellipsis">
Getting the identified entity value using a custom Operator
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../Anonymizing%20known%20values/" class="md-nav__link">
<span class="md-ellipsis">
Anonymizing known values
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../keep_entities/" class="md-nav__link">
<span class="md-ellipsis">
Keeping some entities from being anonymized
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../integrating_with_external_services/" class="md-nav__link">
<span class="md-ellipsis">
Integrating with external services
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/example_remote_recognizer.py" class="md-nav__link">
<span class="md-ellipsis">
Remote Recognizer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../text_analytics/" class="md-nav__link">
<span class="md-ellipsis">
Azure AI Language as a Remote Recognizer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../ahds/" class="md-nav__link">
<span class="md-ellipsis">
Azure Health DataServices De-identification as a Remote Recognizer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/flair_recognizer.py" class="md-nav__link">
<span class="md-ellipsis">
Using Flair as an external PII model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/span_marker_recognizer.py" class="md-nav__link">
<span class="md-ellipsis">
Using Span Marker as an external PII model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../transformers_recognizer/" class="md-nav__link">
<span class="md-ellipsis">
Using Transformers as an external PII model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../gliner/" class="md-nav__link">
<span class="md-ellipsis">
Using GLiNER as an external PII model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../pseudonymization/" class="md-nav__link">
<span class="md-ellipsis">
Pseudonymization (replace PII values using mappings)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/example_custom_lambda_anonymizer.py" class="md-nav__link">
<span class="md-ellipsis">
Passing a lambda as a Presidio anonymizer using Faker
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Synthetic data generation with OpenAI
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="././" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Synthetic data generation with OpenAI
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="On this page">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
On this page
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#path-to-notebook-httpswwwgithubcomdata-privacy-stackpresidioblobmaindocssamplespythonsynth_data_with_openaiipynb" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Path to notebook: https://www.github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/synth_data_with_openai.ipynb
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#use-presidio-openai-to-turn-real-text-into-fake-text" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Use Presidio + OpenAI to turn real text into fake text
</span>
</span>
</a>
<nav class="md-nav" aria-label="Use Presidio + OpenAI to turn real text into fake text">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#imports-and-set-up-openai-key" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Imports and set up OpenAI Key
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#define-request-for-the-openai-service" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Define request for the OpenAI service
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#de-identify-data-using-presidio-analyzer-and-anonymizer" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
De-identify data using Presidio Analyzer and Anonymizer
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#create-prompt-instructions-text-to-manipulate" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Create prompt (instructions + text to manipulate)
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#call-the-llm" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Call the LLM
</span>
</span>
</a>
<nav class="md-nav" aria-label="Call the LLM">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#alternatively-run-on-a-list-of-template-sentences" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Alternatively, run on a list of template sentences:
</span>
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../no_code_config/" class="md-nav__link">
<span class="md-ellipsis">
YAML based no-code configuration
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_3" >
<label class="md-nav__link" for="__nav_6_3" id="__nav_6_3_label" tabindex="0">
<span class="md-ellipsis">
Data
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_3">
<span class="md-nav__icon md-icon"></span>
Data
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../batch_processing/" class="md-nav__link">
<span class="md-ellipsis">
Analyzing structured / semi-structured data in batch
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../example_structured/" class="md-nav__link">
<span class="md-ellipsis">
Presidio Structured Basic Usage Notebook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/process_csv_file.py" class="md-nav__link">
<span class="md-ellipsis">
Analyze and Anonymize CSV file
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_4" >
<label class="md-nav__link" for="__nav_6_4" id="__nav_6_4_label" tabindex="0">
<span class="md-ellipsis">
Images
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_4">
<span class="md-nav__icon md-icon"></span>
Images
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../example_dicom_image_redactor/" class="md-nav__link">
<span class="md-ellipsis">
Redacting Text PII from DICOM images
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../image_redaction_allow_list_approach/" class="md-nav__link">
<span class="md-ellipsis">
Using an allow list with image redaction
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../plot_custom_bboxes/" class="md-nav__link">
<span class="md-ellipsis">
Plot custom bounding boxes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../example_dicom_redactor_evaluation/" class="md-nav__link">
<span class="md-ellipsis">
Example DICOM redaction evaluation
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_5" >
<label class="md-nav__link" for="__nav_6_5" id="__nav_6_5_label" tabindex="0">
<span class="md-ellipsis">
PDF
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_5">
<span class="md-nav__icon md-icon"></span>
PDF
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../example_pdf_annotation/" class="md-nav__link">
<span class="md-ellipsis">
Annotating PII in a PDF
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_6" >
<label class="md-nav__link" for="__nav_6_6" id="__nav_6_6_label" tabindex="0">
<span class="md-ellipsis">
Deployment
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_6">
<span class="md-nav__icon md-icon"></span>
Deployment
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../deployments/app-service/" class="md-nav__link">
<span class="md-ellipsis">
Presidio with App Service
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../deployments/k8s/" class="md-nav__link">
<span class="md-ellipsis">
Presidio with Kubernetes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../deployments/spark/" class="md-nav__link">
<span class="md-ellipsis">
Presidio with Spark
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../fabric/" class="md-nav__link">
<span class="md-ellipsis">
Presidio with Fabric
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../deployments/redacting-telemetry/" class="md-nav__link">
<span class="md-ellipsis">
Redacting Telemetry with Presidio
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_6_6" >
<label class="md-nav__link" for="__nav_6_6_6" id="__nav_6_6_6_label" tabindex="0">
<span class="md-ellipsis">
Azure Data Factory
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="3" aria-labelledby="__nav_6_6_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_6_6">
<span class="md-nav__icon md-icon"></span>
Azure Data Factory
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../deployments/data-factory/presidio-data-factory/" class="md-nav__link">
<span class="md-ellipsis">
ETL using AppService/Databricks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../deployments/data-factory/presidio-data-factory-template-gallery-http/" class="md-nav__link">
<span class="md-ellipsis">
Add Presidio as an HTTP service to your Azure Data Factory
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../deployments/data-factory/presidio-data-factory-template-gallery-databricks/" class="md-nav__link">
<span class="md-ellipsis">
Add Presidio on Databricks to your Azure Data Factory
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../docker/litellm/" class="md-nav__link">
<span class="md-ellipsis">
PII Masking LLM calls using LiteLLM proxy
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6_7" >
<label class="md-nav__link" for="__nav_6_7" id="__nav_6_7_label" tabindex="0">
<span class="md-ellipsis">
Demo app
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_6_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6_7">
<span class="md-nav__icon md-icon"></span>
Demo app
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../streamlit/" class="md-nav__link">
<span class="md-ellipsis">
Create a simple demo app using Streamlit
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<div class="md-sidebar-button__wrapper">
<label class="md-sidebar-button" for="__toc"></label>
</div>
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="On this page">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
On this page
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#path-to-notebook-httpswwwgithubcomdata-privacy-stackpresidioblobmaindocssamplespythonsynth_data_with_openaiipynb" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Path to notebook: https://www.github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/synth_data_with_openai.ipynb
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#use-presidio-openai-to-turn-real-text-into-fake-text" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Use Presidio + OpenAI to turn real text into fake text
</span>
</span>
</a>
<nav class="md-nav" aria-label="Use Presidio + OpenAI to turn real text into fake text">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#imports-and-set-up-openai-key" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Imports and set up OpenAI Key
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#define-request-for-the-openai-service" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Define request for the OpenAI service
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#de-identify-data-using-presidio-analyzer-and-anonymizer" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
De-identify data using Presidio Analyzer and Anonymizer
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#create-prompt-instructions-text-to-manipulate" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Create prompt (instructions + text to manipulate)
</span>
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#call-the-llm" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Call the LLM
</span>
</span>
</a>
<nav class="md-nav" aria-label="Call the LLM">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#alternatively-run-on-a-list-of-template-sentences" class="md-nav__link">
<span class="md-ellipsis">
<span class="md-typeset">
Alternatively, run on a list of template sentences:
</span>
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<div class="highlight"><pre><span></span><code><span class="c1"># download presidio</span>
<span class="err">!</span><span class="n">pip</span> <span class="n">install</span> <span class="n">presidio_analyzer</span> <span class="n">presidio_anonymizer</span>
<span class="err">!</span><span class="n">pip</span> <span class="n">install</span> <span class="n">openai</span> <span class="n">pandas</span>
<span class="err">!</span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">spacy</span> <span class="n">download</span> <span class="n">en_core_web_lg</span>
</code></pre></div>
<h6 id="path-to-notebook-httpswwwgithubcomdata-privacy-stackpresidioblobmaindocssamplespythonsynth_data_with_openaiipynb">Path to notebook: <a href="https://www.github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/synth_data_with_openai.ipynb">https://www.github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/synth_data_with_openai.ipynb</a></h6>
<h1 id="use-presidio-openai-to-turn-real-text-into-fake-text">Use Presidio + OpenAI to turn real text into fake text</h1>
<p>This notebook uses Presidio to turn text with PII into text where PII entities are replaced with placeholders, e.g. "<code>My name is David</code>" turns into "<code>My name is {{PERSON}}</code>". Then, it calls the OpenAI API to create a fake record which is based on the original one.</p>
<p>Flow:
1. <code>My friend David lives in Paris. He likes it.</code>
1. <code>My friend {{PERSON}} lives in {{CITY}}. He likes it.</code>
1. <code>My friend Lucy lives in Beirut. She likes it.</code></p>
<p>Note that OpenAI completion models could possibly detect PII values and replace them in one call, but it is suggested to validate that all PII entities are indeed detected.</p>
<h2 id="imports-and-set-up-openai-key">Imports and set up OpenAI Key</h2>
<div class="highlight"><pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">pprint</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">dotenv</span><span class="w"> </span><span class="kn">import</span> <span class="n">load_dotenv</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pd</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">openai</span><span class="w"> </span><span class="kn">import</span> <span class="n">OpenAI</span>
<span class="n">load_dotenv</span><span class="p">()</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">OpenAI</span><span class="p">(</span>
<span class="n">api_key</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;OPENAI_API_KEY&quot;</span><span class="p">),</span>
<span class="p">)</span>
<span class="c1">#Or put explicitly in notebook. Find out more here: https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key</span>
</code></pre></div>
<h2 id="define-request-for-the-openai-service">Define request for the OpenAI service</h2>
<div class="highlight"><pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">call_completion_model</span><span class="p">(</span><span class="n">prompt</span><span class="p">:</span><span class="nb">str</span><span class="p">,</span> <span class="n">model</span><span class="p">:</span><span class="nb">str</span><span class="o">=</span><span class="s2">&quot;gpt-3.5-turbo&quot;</span><span class="p">,</span> <span class="n">max_tokens</span><span class="p">:</span><span class="nb">int</span><span class="o">=</span><span class="mi">512</span><span class="p">)</span> <span class="o">-&gt;</span><span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Creates a request for the OpenAI Completion service and returns the response.</span>
<span class="sd"> :param prompt: The prompt for the completion model</span>
<span class="sd"> :param model: OpenAI model name</span>
<span class="sd"> :param max_tokens: Model&#39;s max tokens parameter</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">completion</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">chat</span><span class="o">.</span><span class="n">completions</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
<span class="n">messages</span><span class="o">=</span><span class="p">[</span>
<span class="p">{</span>
<span class="s2">&quot;role&quot;</span><span class="p">:</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span>
<span class="s2">&quot;content&quot;</span><span class="p">:</span> <span class="n">prompt</span><span class="p">,</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">completion</span><span class="o">.</span><span class="n">choices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">content</span>
</code></pre></div>
<h2 id="de-identify-data-using-presidio-analyzer-and-anonymizer">De-identify data using Presidio Analyzer and Anonymizer</h2>
<div class="highlight"><pre><span></span><code><span class="kn">from</span><span class="w"> </span><span class="nn">presidio_analyzer</span><span class="w"> </span><span class="kn">import</span> <span class="n">AnalyzerEngine</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">presidio_anonymizer</span><span class="w"> </span><span class="kn">import</span> <span class="n">AnonymizerEngine</span>
<span class="n">analyzer</span> <span class="o">=</span> <span class="n">AnalyzerEngine</span><span class="p">()</span>
<span class="n">anonymizer</span> <span class="o">=</span> <span class="n">AnonymizerEngine</span><span class="p">()</span>
<span class="n">sample</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">Hello, my name is David Johnson and I live in Maine.</span>
<span class="s2">My credit card number is 4095-2609-9393-4932 and my crypto wallet id is 16Yeky6GMjeNkAiNcBY7ZhrLoMSgg1BoyZ.</span>
<span class="s2">On September 18 I visited microsoft.com and sent an email to test@presidio.site, from the IP 192.168.0.1.</span>
<span class="s2">My passport: 191280342 and my phone number: (212) 555-1234.</span>
<span class="s2">This is a valid International Bank Account Number: IL150120690000003111111 . Can you please check the status on bank account 954567876544?</span>
<span class="s2">Kate&#39;s social security number is 078-05-1126. Her driver license? it is 1234567A.</span>
<span class="s2">&quot;&quot;&quot;</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">analyzer</span><span class="o">.</span><span class="n">analyze</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="n">language</span><span class="o">=</span><span class="s2">&quot;en&quot;</span><span class="p">)</span>
<span class="n">anonymized</span> <span class="o">=</span> <span class="n">anonymizer</span><span class="o">.</span><span class="n">anonymize</span><span class="p">(</span><span class="n">text</span><span class="o">=</span><span class="n">sample</span><span class="p">,</span> <span class="n">analyzer_results</span><span class="o">=</span><span class="n">results</span><span class="p">)</span>
<span class="n">anonymized_text</span> <span class="o">=</span> <span class="n">anonymized</span><span class="o">.</span><span class="n">text</span>
<span class="nb">print</span><span class="p">(</span><span class="n">anonymized_text</span><span class="p">)</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code>Hello, my name is &lt;PERSON&gt; and I live in &lt;LOCATION&gt;.
My credit card number is &lt;CREDIT_CARD&gt; and my crypto wallet id is &lt;CRYPTO&gt;.
On &lt;DATE_TIME&gt; I visited &lt;URL&gt; and sent an email to &lt;EMAIL_ADDRESS&gt;, from the IP &lt;IP_ADDRESS&gt;.
My passport: &lt;US_PASSPORT&gt; and my phone number: &lt;PHONE_NUMBER&gt;.
This is a valid International Bank Account Number: &lt;IBAN_CODE&gt; . Can you please check the status on bank account &lt;US_BANK_NUMBER&gt;?
&lt;PERSON&gt;&#39;s social security number is &lt;US_SSN&gt;. Her driver license? it is &lt;US_DRIVER_LICENSE&gt;.
</code></pre></div>
<h2 id="create-prompt-instructions-text-to-manipulate">Create prompt (instructions + text to manipulate)</h2>
<div class="highlight"><pre><span></span><code><span class="k">def</span><span class="w"> </span><span class="nf">create_prompt</span><span class="p">(</span><span class="n">anonymized_text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create the prompt with instructions to GPT-3.</span>
<span class="sd"> :param anonymized_text: Text with placeholders instead of PII values, e.g. My name is &lt;PERSON&gt;.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">prompt</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2"> Your role is to create synthetic text based on de-identified text with placeholders instead of Personally Identifiable Information (PII).</span>
<span class="s2"> Replace the placeholders (e.g. ,&lt;PERSON&gt;, </span><span class="se">{{</span><span class="s2">DATE</span><span class="se">}}</span><span class="s2">, </span><span class="se">{{</span><span class="s2">ip_address</span><span class="se">}}</span><span class="s2">) with fake values.</span>
<span class="s2"> Instructions:</span>
<span class="s2"> a. Use completely random numbers, so every digit is drawn between 0 and 9.</span>
<span class="s2"> b. Use realistic names that come from diverse genders, ethnicities and countries.</span>
<span class="s2"> c. If there are no placeholders, return the text as is.</span>
<span class="s2"> d. Keep the formatting as close to the original as possible.</span>
<span class="s2"> e. If PII exists in the input, replace it with fake values in the output.</span>
<span class="s2"> f. Remove whitespace before and after the generated text</span>
<span class="s2"> input: [[TEXT STARTS]] How do I change the limit on my credit card </span><span class="se">{{</span><span class="s2">credit_card_number</span><span class="se">}}</span><span class="s2">?[[TEXT ENDS]]</span>
<span class="s2"> output: How do I change the limit on my credit card 2539 3519 2345 1555?</span>
<span class="s2"> input: [[TEXT STARTS]]&lt;PERSON&gt; was the chief science officer at &lt;ORGANIZATION&gt;.[[TEXT ENDS]]</span>
<span class="s2"> output: Katherine Buckjov was the chief science officer at NASA.</span>
<span class="s2"> input: [[TEXT STARTS]]Cameroon lives in &lt;LOCATION&gt;.[[TEXT ENDS]]</span>
<span class="s2"> output: Vladimir lives in Moscow.</span>
<span class="s2"> input: [[TEXT STARTS]]</span><span class="si">{</span><span class="n">anonymized_text</span><span class="si">}</span><span class="s2">[[TEXT ENDS]]</span>
<span class="s2"> output:&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">prompt</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;This is the prompt with de-identified values:&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">create_prompt</span><span class="p">(</span><span class="n">anonymized_text</span><span class="p">))</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code>This is the prompt with de-identified values:
Your role is to create synthetic text based on de-identified text with placeholders instead of Personally Identifiable Information (PII).
Replace the placeholders (e.g. ,&lt;PERSON&gt;, {DATE}, {ip_address}) with fake values.
Instructions:
a. Use completely random numbers, so every digit is drawn between 0 and 9.
b. Use realistic names that come from diverse genders, ethnicities and countries.
c. If there are no placeholders, return the text as is.
d. Keep the formatting as close to the original as possible.
e. If PII exists in the input, replace it with fake values in the output.
f. Remove whitespace before and after the generated text
input: [[TEXT STARTS]] How do I change the limit on my credit card {credit_card_number}?[[TEXT ENDS]]
output: How do I change the limit on my credit card 2539 3519 2345 1555?
input: [[TEXT STARTS]]&lt;PERSON&gt; was the chief science officer at &lt;ORGANIZATION&gt;.[[TEXT ENDS]]
output: Katherine Buckjov was the chief science officer at NASA.
input: [[TEXT STARTS]]Cameroon lives in &lt;LOCATION&gt;.[[TEXT ENDS]]
output: Vladimir lives in Moscow.
input: [[TEXT STARTS]]
Hello, my name is &lt;PERSON&gt; and I live in &lt;LOCATION&gt;.
My credit card number is &lt;CREDIT_CARD&gt; and my crypto wallet id is &lt;CRYPTO&gt;.
On &lt;DATE_TIME&gt; I visited &lt;URL&gt; and sent an email to &lt;EMAIL_ADDRESS&gt;, from the IP &lt;IP_ADDRESS&gt;.
My passport: &lt;US_PASSPORT&gt; and my phone number: &lt;PHONE_NUMBER&gt;.
This is a valid International Bank Account Number: &lt;IBAN_CODE&gt; . Can you please check the status on bank account &lt;US_BANK_NUMBER&gt;?
&lt;PERSON&gt;&#39;s social security number is &lt;US_SSN&gt;. Her driver license? it is &lt;US_DRIVER_LICENSE&gt;.
[[TEXT ENDS]]
output:
</code></pre></div>
<h2 id="call-the-llm">Call the LLM</h2>
<div class="highlight"><pre><span></span><code><span class="n">gpt_res</span> <span class="o">=</span> <span class="n">call_completion_model</span><span class="p">(</span><span class="n">create_prompt</span><span class="p">(</span><span class="n">anonymized_text</span><span class="p">))</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="n">gpt_res</span><span class="p">)</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code>Hello, my name is Aaliyah and I live in Tokyo.
My credit card number is 4928 7562 1034 8907 and my crypto wallet id is 0x3B 7a 5f 1C.
On 02/07/2023 15:45 I visited www.example.com and sent an email to example@email.com, from the IP 127.0.0.1.
My passport: L921483B and my phone number: +1 (555) 123-4567.
This is a valid International Bank Account Number: FR76 1234 5789 1256 3321 7564 901. Can you please check the status on bank account 987654321?
Eliana&#39;s social security number is 123-45-6789. Her driver license? it is DL12345678.
</code></pre></div>
<h3 id="alternatively-run-on-a-list-of-template-sentences">Alternatively, run on a list of template sentences:</h3>
<div class="highlight"><pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">urllib</span>
<span class="n">templates</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;https://raw.githubusercontent.com/data-privacy-stack/presidio-research/master/presidio_evaluator/data_generator/raw_data/templates.txt&quot;</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">):</span>
<span class="n">templates</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Example templates:&quot;</span><span class="p">)</span>
<span class="n">templates</span><span class="p">[:</span><span class="mi">5</span><span class="p">]</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code>Example templates:
[&#39;I want to increase limit on my card # {{credit_card_number}} for certain duration of time. is it possible?\n&#39;,
&#39;My credit card {{credit_card_number}} has been lost, Can I request you to block it.\n&#39;,
&#39;Need to change billing date of my card {{credit_card_number}}\n&#39;,
&#39;I want to update my primary and secondary address to the same: {{address}}\n&#39;,
&quot;In case of my child&#39;s account, we need to add {{person}} as guardian\n&quot;]
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="n">templates_to_use</span> <span class="o">=</span> <span class="n">templates</span><span class="p">[:</span><span class="mi">5</span><span class="p">]</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">time</span>
<span class="n">pp</span> <span class="o">=</span> <span class="n">pprint</span><span class="o">.</span><span class="n">PrettyPrinter</span><span class="p">(</span><span class="n">indent</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">110</span><span class="p">)</span>
<span class="n">sentences</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">template</span> <span class="ow">in</span> <span class="n">templates_to_use</span><span class="p">:</span>
<span class="n">synth_sentence</span> <span class="o">=</span> <span class="n">call_completion_model</span><span class="p">(</span><span class="n">create_prompt</span><span class="p">(</span><span class="n">template</span><span class="p">))</span>
<span class="n">sentence_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;original&quot;</span><span class="p">:</span> <span class="n">template</span><span class="p">,</span> <span class="s2">&quot;synthetic&quot;</span><span class="p">:</span><span class="n">synth_sentence</span><span class="o">.</span><span class="n">strip</span><span class="p">()}</span>
<span class="n">sentences</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sentence_dict</span><span class="p">)</span>
<span class="n">pp</span><span class="o">.</span><span class="n">pprint</span><span class="p">(</span><span class="n">sentence_dict</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># wait to not get blocked by service (only applicable for the free tier)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;--------------&quot;</span><span class="p">)</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code>{ &#39;original&#39;: &#39;I want to increase limit on my card # {{credit_card_number}} for certain duration of time. is &#39;
&#39;it possible?\n&#39;,
&#39;synthetic&#39;: &#39;I want to increase limit on my card # 4701 2895 7462 8306 for certain duration of time. is &#39;
&#39;it possible?&#39;}
--------------
{ &#39;original&#39;: &#39;My credit card {{credit_card_number}} has been lost, Can I request you to block it.\n&#39;,
&#39;synthetic&#39;: &#39;My credit card 4892 7634 1023 8756 has been lost, Can I request you to block it.&#39;}
--------------
{ &#39;original&#39;: &#39;Need to change billing date of my card {{credit_card_number}}\n&#39;,
&#39;synthetic&#39;: &#39;Need to change billing date of my card 4876 2035 6981 7423&#39;}
--------------
{ &#39;original&#39;: &#39;I want to update my primary and secondary address to the same: {{address}}\n&#39;,
&#39;synthetic&#39;: &#39;I want to update my primary and secondary address to the same: 123 Main Street, Apt 4.&#39;}
--------------
{ &#39;original&#39;: &quot;In case of my child&#39;s account, we need to add {{person}} as guardian\n&quot;,
&#39;synthetic&#39;: &quot;In case of my child&#39;s account, we need to add Abdul as guardian&quot;}
--------------
--------------
{ &#39;original&#39;: &#39;{{name}} lives at {{building_number}} {{street_name}}, {{city}}\n&#39;,
&#39;synthetic&#39;: &#39;John Smith lives at 635 Poplar Street, Houston&#39;}
--------------
{ &#39;original&#39;: &#39;{{first_name_male}} had given {{first_name}} his address: {{building_number}} &#39;
&#39;{{street_name}}\n&#39;,
&#39;synthetic&#39;: &#39;Adam had given Sarah his address: 44 Apple Street&#39;}
--------------
{ &#39;original&#39;: &#39;{{first_name_male}} had given {{first_name}} his address: {{building_number}} &#39;
&#39;{{street_name}}, {{city}}\n&#39;,
&#39;synthetic&#39;: &#39;David had given Emma his address: 515 Elm Street, Camden.&#39;}
--------------
{ &#39;original&#39;: &#39;What is your address? it is {{address}}\n&#39;,
&#39;synthetic&#39;: &#39;What is your address? it is 3498 Allensby Street, Los Angeles, CA 90011.&#39;}
--------------
{&#39;original&#39;: &#39;We moved here from {{city}}\n&#39;, &#39;synthetic&#39;: &#39;We moved here from Paris.&#39;}
--------------
{&#39;original&#39;: &#39;We moved here from {{country}}\n&#39;, &#39;synthetic&#39;: &#39;We moved here from Venezuela.&#39;}
--------------
{ &#39;original&#39;: &#39;{{person}}\\n\\n{{building_number}} {{street_name}}\\n {{secondary_address}}\\n {{city}}\\n &#39;
&#39;{{country}} {{postcode}}\\n{{phone_number}}-Office\\,{{phone_number}}-Fax\n&#39;,
&#39;synthetic&#39;: &#39;Jessica Thompson\n&#39;
&#39; 8745 West Drive\n&#39;
&#39; Suite 1402\n&#39;
&#39; Brooklyn, NY USA 12009\n&#39;
&#39; 789-534-9921-Office, 567-945-0023-Fax&#39;}
--------------
{ &#39;original&#39;: &#39;{{person}}\\n{{job}}\\n{{organization}}\\n{{address}}\n&#39;,
&#39;synthetic&#39;: &#39;John Smith\\nAccountant\\nGlobalTech Solutions\\n25 Speedwell Street, Richmond, VA 23223&#39;}
--------------
{ &#39;original&#39;: &#39;Our offices are located at {{address}}\n&#39;,
&#39;synthetic&#39;: &#39;Our offices are located at 1234 Main St, Los Angeles, CA 91234.&#39;}
--------------
{ &#39;original&#39;: &#39;Please return to {{address}} in case of an issue.\n&#39;,
&#39;synthetic&#39;: &#39;Please return to 123 Cherry Street, El Monte, CA 91731 in case of an issue.&#39;}
--------------
{ &#39;original&#39;: &#39;{{organization}}\\n\\n{{address}}\n&#39;,
&#39;synthetic&#39;: &#39;ABC Inc.\n 1234 Main Street, Anytown, ST 12345&#39;}
--------------
{ &#39;original&#39;: &#39;The {{organization}} office is at {{address}}\n&#39;,
&#39;synthetic&#39;: &#39;The ABC Corporation office is at 123 Redwood Street, Anytown, USA.&#39;}
--------------
{ &#39;original&#39;: &#39;{{name}}\\n{{organization}}\\n{{address}}\\n{{phone_number}} office\\n{{phone_number}} &#39;
&#39;fax\\n{{phone_number}} mobile\\n\n&#39;,
&#39;synthetic&#39;: &#39;Larry Fernandez\\nStar Enterprises\\n421 5th Avenue, Los Angeles, CA 90012\\n123-456-7890 &#39;
&#39;office\\n456-789-0123 fax\\n256-454-2397 mobile\\n&#39;}
--------------
{ &#39;original&#39;: &#39;{{name}}\\n{{organization}}\\n{{address}}\\nMobile: {{phone_number}}\\nDesk: &#39;
&#39;{{phone_number}}\\nFax: {{phone_number}}\\n\n&#39;,
&#39;synthetic&#39;: &#39;John Brown\n&#39;
&#39; ABC Consulting\n&#39;
&#39; 5th St., Suite 116, LA CA 90004\n&#39;
&#39; Mobile: 213-294-4497\n&#39;
&#39; Desk: 424-348-1275\n&#39;
&#39; Fax: 323-456-2545&#39;}
--------------
{ &#39;original&#39;: &#39;Billing address: {{name}}\\n {{building_number}} {{street_name}} &#39;
&#39;{{secondary_address}}\\n {{city}}\\n {{state_abbr}}\\n {{zipcode}}\\n\n&#39;,
&#39;synthetic&#39;: &#39;Billing address: Mariam Rajput\n&#39;
&#39; 576 Broadway Street Apartment A8\n&#39;
&#39; Sacramento\n&#39;
&#39; CA\n&#39;
&#39; 95349&#39;}
--------------
{ &#39;original&#39;: &quot;As promised, here&#39;s {{first_name}}&#39;s address:\\n\\n{{address}}\n&quot;,
&#39;synthetic&#39;: &quot;As promised, here&#39;s Aamir&#39;s address:\\n\\n2166 Sesame Street, Fortaleza, Ceará, Brazil.&quot;}
--------------
{ &#39;original&#39;: &#39;&gt;{{name}}\\n&gt;{{organization}}\\n&gt;{{person}}\\n&gt;{{building_number}} &#39;
&#39;{{street_name}}\\n&gt;{{secondary_address}}\\n&gt;{{city}}\\n&gt;{{country}} {{postcode}}\n&#39;,
&#39;synthetic&#39;: &#39;&gt;Freda Chen\n&#39;
&#39;&gt;Example Inc.\n&#39;
&#39;&gt;John Doe\n&#39;
&#39;&gt;50 Main Street\n&#39;
&#39;&gt;Apt. 2\n&#39;
&#39;&gt;New York\n&#39;
&#39;&gt;United States 10005&#39;}
--------------
{ &#39;original&#39;: &#39;??? {{name}}\\n??? {{organization}}\\n??? {{building_number}} {{street_name}}\\n??? &#39;
&#39;{{secondary_address}}\\n??? {{city}}\\n??? {{country}} {{postcode}}\n&#39;,
&#39;synthetic&#39;: &#39;John Smith\n&#39;
&#39; ABC Corporation\n&#39;
&#39; 192 Main Street\n&#39;
&#39; Suite 100\n&#39;
&#39; Austin\n&#39;
&#39; United States 78701&#39;}
--------------
{ &#39;original&#39;: &#39;&gt; \\n&gt; {{name}}\\n&gt; {{organization}}\\n&gt; {{person}}\\n&gt; {{building_number}} &#39;
&#39;{{street_name}}\\n&gt; {{secondary_address}}\\n&gt; {{city}}\\n&gt; {{country}} {{postcode}}\n&#39;,
&#39;synthetic&#39;: &#39;&gt; John Doe\n&#39;
&#39; &gt; ABC Corp\n&#39;
&#39; &gt; Jane Smith\n&#39;
&#39; &gt; 123 Main Street\n&#39;
&#39; &gt; APT 8\n&#39;
&#39; &gt; San Francisco\n&#39;
&#39; &gt; United States 12345&#39;}
--------------
{ &#39;original&#39;: &#39;Pedestrians must enter on {{street_name}} St. the first three months\n&#39;,
&#39;synthetic&#39;: &#39;Pedestrians must enter on Jericho Avenue St. the first three months&#39;}
--------------
{ &#39;original&#39;: &#39;When: {{date_time}}\\nWhere: {{city}} Country Club.\n&#39;,
&#39;synthetic&#39;: &#39;When: 05/01/2020 10:00am\\nWhere: Richmond Country Club.&#39;}
--------------
{ &#39;original&#39;: &quot;We&#39;ll meet {{day_of_week}} at {{organization}}, {{building_number}} {{street_name}}, &quot;
&#39;{{city}}\n&#39;,
&#39;synthetic&#39;: &quot;We&#39;ll meet Monday at Smartdel Solutions, 145 King Street, San Diego.&quot;}
--------------
{ &#39;original&#39;: &#39;They had 6: {{first_name}}, {{first_name}}, {{first_name}}, {{first_name}}, {{first_name}} &#39;
&#39;and {{first_name}}.\n&#39;,
&#39;synthetic&#39;: &#39;They had 6: Sarah, Micheal, Kanak, Hana, Mei and Dan.&#39;}
--------------
{&#39;original&#39;: &#39;She moved here from {{country}}\n&#39;, &#39;synthetic&#39;: &#39;She moved here from Mexico.&#39;}
--------------
{&#39;original&#39;: &#39;My zip code is {{zipcode}}\n&#39;, &#39;synthetic&#39;: &#39;My zip code is 47713.&#39;}
--------------
{&#39;original&#39;: &#39;ZIP: {{zipcode}}\n&#39;, &#39;synthetic&#39;: &#39;ZIP: 08547&#39;}
--------------
{&#39;original&#39;: &#39;The bus station is on {{street_name}}\n&#39;, &#39;synthetic&#39;: &#39;The bus station is on Wilson Avenue.&#39;}
--------------
{ &#39;original&#39;: &quot;They&#39;re not answering at {{phone_number}}\n&quot;,
&#39;synthetic&#39;: &quot;They&#39;re not answering at 654-339-1013.&quot;}
--------------
{ &#39;original&#39;: &#39;God gave rock and roll to you, gave rock and roll to you, put it in the soul of everyone.\n&#39;,
&#39;synthetic&#39;: &#39;God gave rock and roll to you, gave rock and roll to you, put it in the soul of everyone.&#39;}
--------------
{&#39;original&#39;: &#39;3... 2... 1... liftoff!\n&#39;, &#39;synthetic&#39;: &#39;3... 2... 1... liftoff!&#39;}
--------------
{ &#39;original&#39;: &#39;My great great grandfather was called {{name_male}}, and my great great grandmother was &#39;
&#39;called {{name_female}}\n&#39;,
&#39;synthetic&#39;: &#39;My great great grandfather was called Michael, and my great great grandmother was called &#39;
&#39;Emma.&#39;}
--------------
{&#39;original&#39;: &#39;She named him {{first_name_male}}\n&#39;, &#39;synthetic&#39;: &#39;She named him Juan.&#39;}
--------------
{ &#39;original&#39;: &#39;Name: {{name}}\\nAddress: {{address}}\n&#39;,
&#39;synthetic&#39;: &#39;Name: Amari Walters\\nAddress: 32 Webster Street, Salem, MA 01819&#39;}
--------------
{ &#39;original&#39;: &#39;Follow up with {{name}} in a couple of months.\n&#39;,
&#39;synthetic&#39;: &#39;Follow up with Beatriz Lawrence in a couple of months.&#39;}
--------------
{ &#39;original&#39;: &#39;{{prefix_male}} {{last_name_male}} is a {{age}} year old man who grew up in {{city}}.\n&#39;,
&#39;synthetic&#39;: &#39;Mr.Williams is a 28 year old man who grew up in Dallas.&#39;}
--------------
{ &#39;original&#39;: &#39;Date: {{date_time}}\\nName: {{name}}\\nPhone: {{phone_number}}\n&#39;,
&#39;synthetic&#39;: &#39;Date: 01/03/2021 13:45 \\nName: Pratima Joshi \\nPhone: 467-562-8954&#39;}
--------------
{ &#39;original&#39;: &#39;{{first_name}}: &quot;Who are you?&quot;\\n{{first_name_female}}:&quot;I\&#39;m {{first_name}}\&#39;s daughter&quot;.\n&#39;,
&#39;synthetic&#39;: &#39;Bob: &quot;Who are you?&quot;\\nMaria:&quot;I\&#39;m Bob\&#39;s daughter&quot;.&#39;}
--------------
{ &#39;original&#39;: &#39;At my suggestion, one morning over breakfast, she agreed, and on the last Sunday before Labor &#39;
&#39;Day we returned to {{city}} by helicopter.\n&#39;,
&#39;synthetic&#39;: &#39;At my suggestion, one morning over breakfast, she agreed, and on the last Sunday before &#39;
&#39;Labor Day we returned to Paris by helicopter.&#39;}
--------------
{ &#39;original&#39;: &quot;It was a done thing between him and {{first_name}}&#39;s kid; and everybody thought so.\n&quot;,
&#39;synthetic&#39;: &quot;It was a done thing between him and Jeffery&#39;s kid; and everybody thought so.&quot;}
--------------
{ &#39;original&#39;: &#39;Capitalized words like Wisdom and Discipline are often mistaken with names.\n&#39;,
&#39;synthetic&#39;: &#39;Capitalized words like Wisdom and Discipline are often mistaken with names.&#39;}
--------------
{ &#39;original&#39;: &#39;The letter arrived at {{address}} last night.\n&#39;,
&#39;synthetic&#39;: &#39;The letter arrived at 1143 Orange Street last night.&#39;}
--------------
{ &#39;original&#39;: &#39;The Princess Royal arrived at {{city}} this morning from {{country}}.\n&#39;,
&#39;synthetic&#39;: &#39;The Princess Royal arrived at London this morning from France.&#39;}
--------------
{&#39;original&#39;: &quot;I&#39;m in {{city}}, at the conference\n&quot;, &#39;synthetic&#39;: &quot;I&#39;m in Toronto, at the conference.&quot;}
--------------
{ &#39;original&#39;: &#39;{{name}}, the {{job}}, said: &quot;I\&#39;m glad to hear that this has been withdrawn quite why they &#39;
&#39;thought this would go down well is beyond me.&quot;\n&#39;,
&#39;synthetic&#39;: &#39;Gloria Green, the Nurse Practitioner, said: &quot;I\&#39;m glad to hear that this has been withdrawn &#39;
&#39; quite why they thought this would go down well is beyond me.&quot;&#39;}
--------------
{ &#39;original&#39;: &#39;&quot;I\&#39;m glad to hear that {{country}} is moving in that direction,&quot; says {{last_name}}.\n&#39;,
&#39;synthetic&#39;: &#39;&quot;I\&#39;m glad to hear that Canada is moving in that direction,&quot; says Smith.&#39;}
--------------
{ &#39;original&#39;: &#39;I am {{nation_woman}} but I live in {{country}}.\n&#39;,
&#39;synthetic&#39;: &#39;I am Marianna Montenegro but I live in Ukraine.&#39;}
--------------
{&#39;original&#39;: &#39;We are proud {{nation_plural}}\n&#39;, &#39;synthetic&#39;: &#39;We are proud Americans.&#39;}
--------------
{ &#39;original&#39;: &quot;{{person}}&#39;s killers sentenced to life in prison\n&quot;,
&#39;synthetic&#39;: &quot;John Smith&#39;s killers sentenced to life in prison&quot;}
--------------
{ &#39;original&#39;: &quot;{{country}} leader gives &#39;kill without warning&#39; order\n&quot;,
&#39;synthetic&#39;: &quot;Brazilian leader gives &#39;kill without warning&#39; order&quot;}
--------------
{ &#39;original&#39;: &#39;The {{nationality}} Border Force have detained top-flight tennis player {{name_female}} over &#39;
&#39;visa disputes.\n&#39;,
&#39;synthetic&#39;: &#39;The British Border Force have detained top-flight tennis player Maria Rodriguez over visa &#39;
&#39;disputes.&#39;}
--------------
{ &#39;original&#39;: &#39;You will be responsible for the husbandry and care of a large variety of species including &#39;
&#39;lemurs, antelope, camels, and more\n&#39;,
&#39;synthetic&#39;: &#39;You will be responsible for the husbandry and care of a large variety of species including &#39;
&#39;lemurs, antelope, camels, and more.&#39;}
--------------
{ &#39;original&#39;: &#39;{{name}}\\n\\n{{job}}\\n\\nPersonal &#39;
&#39;Info:\\nPhone:\\n{{phone_number}}\\n\\nE-mail:\\n{{email}}\\n\\nWebsite:\\n{{url}}\\n\\nAddress:\\n{{address}}.\n&#39;,
&#39;synthetic&#39;: &#39;Robert James\\n\\nSoftware Engineer\\n\\nPersonal &#39;
&#39;Info:\\nPhone:\\n555-847-8915\\n\\nE-mail:\\nrobertjames@example.com\\n\\nWebsite:\\nwww.example.com\\n\\nAddress:\\n277 &#39;
&#39;Park Ave North, Denver, CO 80100.&#39;}
--------------
{ &#39;original&#39;: &#39;{{name}}\\n\\n{{city}}\\n{{country}}\n&#39;,
&#39;synthetic&#39;: &#39;John Smith\n Los Angeles\n United States&#39;}
--------------
{ &#39;original&#39;: &#39;Title VII of the Civil Rights Act of {{year}} protects individuals against employment &#39;
&#39;discrimination on the basis of race and color as well as national origin, sex, or religion.\n&#39;,
&#39;synthetic&#39;: &#39;Title VII of the Civil Rights Act of 1964 protects individuals against employment &#39;
&#39;discrimination on the basis of race and color as well as national origin, sex, or religion.&#39;}
--------------
{ &#39;original&#39;: &#39;Energetic and driven salesperson with 8+ years of professional experience in inbound and &#39;
&#39;outbound sales. Awarded Salesperson of the Month three times. Helped increase inbound sales &#39;
&#39;by 16% within the first year of employment. Looking to support {{organization}} in {{city}} &#39;
&#39;{{zipcode}} in its mission to become a market-leading solution.\n&#39;,
&#39;synthetic&#39;: &#39;Energetic and driven salesperson with 8+ years of professional experience in inbound and &#39;
&#39;outbound sales. Awarded Salesperson of the Month three times. Helped increase inbound sales &#39;
&#39;by 16% within the first year of employment. Looking to support Acme Corporation in Los &#39;
&#39;Angeles 90018 in its mission to become a market-leading solution.&#39;}
--------------
{ &#39;original&#39;: &#39;The bus drops you off at {{building_number}} {{street_name}} St.\n&#39;,
&#39;synthetic&#39;: &#39;The bus drops you off at 2774 Chestnut St.&#39;}
--------------
{ &#39;original&#39;: &#39;Ask the driver to stop at the corner of {{street_name}} St. and {{street_name}} St.\n&#39;,
&#39;synthetic&#39;: &#39;Ask the driver to stop at the corner of Maple St. and Sycamore St.&#39;}
--------------
{ &#39;original&#39;: &#39;He lives on the north side of {{street_name}}.\n&#39;,
&#39;synthetic&#39;: &#39;He lives on the north side of Abbey Road.&#39;}
--------------
{ &#39;original&#39;: &quot;I used to work for {{organization}} as {{job}}, but quit a few months ago. Now I&#39;m &quot;
&#39;unemployed.\n&#39;,
&#39;synthetic&#39;: &quot;I used to work for ABC Corporation as Software Engineer, but quit a few months ago. Now I&#39;m &quot;
&#39;unemployed.&#39;}
--------------
{&#39;original&#39;: &#39;{{city}} bridge is falling down.\n&#39;, &#39;synthetic&#39;: &#39;Berlin bridge is falling down.&#39;}
--------------
{ &#39;original&#39;: &#39;{{name}} of {{organization}} is the CEO of the year. ABC Business considered several other &#39;
&quot;influential CEOs for this year&#39;s honor, including {{name}} of {{organization}}, &quot;
&quot;{{organization}}&#39;s {{name}}, {{name}} of {{organization}}&#39;s, {{name}} of {{organization}}, &quot;
&quot;and {{organization}}&#39;s {{name}}.\n&quot;,
&#39;synthetic&#39;: &#39;Franklin Smith of Technology Solutions International is the CEO of the year. ABC Business &#39;
&quot;considered several other influential CEOs for this year&#39;s honor, including Madison Chang of &quot;
&quot;Radiance Digital, Radiance Digital&#39;s Ashleigh Jones, Cash Huang of Clark &amp; Partner&#39;s, Sierra &quot;
&quot;Urbina of Intelicity, and Clark &amp; Partners&#39;s Asher Kenney.&quot;}
--------------
{ &#39;original&#39;: &#39;{{organization}} is a design agency based in {{city}}.\n&#39;,
&#39;synthetic&#39;: &#39;Maestro Design Inc. is a design agency based in Amsterdam.&#39;}
--------------
{ &#39;original&#39;: &#39;Action &amp; Adventure, Animation, Comedy, Kids &amp; Family, Mystery &amp; Suspense\\nDirected By: &#39;
&#39;{{name}}\n&#39;,
&#39;synthetic&#39;: &#39;Action &amp; Adventure, Animation, Comedy, Kids &amp; Family, Mystery &amp; Suspense\n&#39;
&#39;Directed By: Esther Jones&#39;}
--------------
{ &#39;original&#39;: &#39;{{first_name}}: What a wife.\\n{{first_name}}: Remember me, {{first_name}}? When I killed &#39;
&#39;your brother, I talked just like this!\\n{{first_name}}: You saved my life! How can I ever &#39;
&#39;repay you?\n&#39;,
&#39;synthetic&#39;: &#39;Emma: What a wife.\n&#39;
&#39; Emma: Remember me, Emma? When I killed your brother, I talked just like this!\n&#39;
&#39; Emma: You saved my life! How can I ever repay you?&#39;}
--------------
{&#39;original&#39;: &#39;He just turned {{age}} years old\n&#39;, &#39;synthetic&#39;: &#39;He just turned 7 years old&#39;}
--------------
{ &#39;original&#39;: &quot;I&#39;m {{name}}, originally from {{city}}, and i&#39;m {{age}} y/o.\n&quot;,
&#39;synthetic&#39;: &quot;I&#39;m Emily Evanston, originally from London, and I&#39;m 24 y/o.&quot;}
--------------
{ &#39;original&#39;: &#39;Patient is a {{age}}-year-old male with a history of headaches\n&#39;,
&#39;synthetic&#39;: &#39;Patient is a 35-year-old male with a history of headaches&#39;}
--------------
{&#39;original&#39;: &#39;I just turned {{age}}\n&#39;, &#39;synthetic&#39;: &#39;I just turned 24.&#39;}
--------------
{&#39;original&#39;: &#39;My father retired at the age of {{age}}\n&#39;, &#39;synthetic&#39;: &#39;My father retired at the age of 60.&#39;}
--------------
{ &#39;original&#39;: &#39;This {{age}} year old female complaining of stomach pain.\n&#39;,
&#39;synthetic&#39;: &#39;This 28 year old female complaining of stomach pain.&#39;}
--------------
{ &#39;original&#39;: &quot;My birthday is on the weekend. I&#39;ll turn {{age}}.\n&quot;,
&#39;synthetic&#39;: &quot;My birthday is on the weekend. I&#39;ll turn 20.&quot;}
--------------
{&#39;original&#39;: &#39;My brother just turned {{age}}\n&#39;, &#39;synthetic&#39;: &#39;My brother just turned 18.&#39;}
--------------
{ &#39;original&#39;: &#39;{{prefix}} {{last_name}} flew to {{city}} on {{day_of_week}} morning.&#39;,
&#39;synthetic&#39;: &#39;Dr. Nguyen flew to Los Angeles on Tuesday morning.&#39;}
--------------
</code></pre></div>
<p>This notebook demonstrates how to leverage OpenAI models for fake/surrogate data generation. It uses Presidio to first de-identify data (as de-identification might be required prior to passing the model to OpenAI), and then uses OpenAI completion models to create synthetic/fake/surrogate data based on real data. OpenAI models would also potentially remove additional PII entities, if those are not detected by Presidio.</p>
<p>Some impressions:
1. LLMs sometimes gives additonal output, especially if the text is a question or concerning a human/bot interaction. Engineering the prompt can mitigate some of these issues. Potential post-processing might be required.
2. LLMs sometimes creates fake values even in the absence of placeholders.
3. LLMs re-uses context from other sentences, which could cause phone numbers are sometimes generated using a credit card pattern or other similar mistakes.
4. Co-references are sometimes missed (i.e. two name placeholders that should be filled with the same name, or referencing he/she to a male/female name)</p>
<div class="highlight"><pre><span></span><code>
</code></pre></div>
</article>
</div>
<script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-circle-arrow-up" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m16 12-4-4-4 4M12 16V8"/></svg>
Back to top
</button>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="https://github.com/data-privacy-stack/presidio/blob/main/docs/samples/python/example_custom_lambda_anonymizer.py" class="md-footer__link md-footer__link--prev" aria-label="Previous: Passing a lambda as a Presidio anonymizer using Faker">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-arrow-left" viewBox="0 0 24 24"><path d="m12 19-7-7 7-7M19 12H5"/></svg>
</div>
<div class="md-footer__title">
<span class="md-footer__direction">
Previous
</span>
<div class="md-ellipsis">
Passing a lambda as a Presidio anonymizer using Faker
</div>
</div>
</a>
<a href="../no_code_config/" class="md-footer__link md-footer__link--next" aria-label="Next: YAML based no-code configuration">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
YAML based no-code configuration
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-arrow-right" viewBox="0 0 24 24"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
</div>
</a>
</nav>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
<div class="md-copyright__highlight">
<a href="https://dataprivacystack.org/">Data Privacy Stack</a>
</div>
Made with
<a href="https://zensical.org/" target="_blank" rel="noopener">
Zensical
</a>
</div>
<div class="md-social">
<a href="https://github.com/data-privacy-stack/presidio" target="_blank" rel="noopener" title="github.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg>
</a>
<a href="https://discord.gg/MewtBGFquB" target="_blank" rel="noopener" title="discord.gg" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M492.5 69.8c-.2-.3-.4-.6-.8-.7-38.1-17.5-78.4-30-119.7-37.1-.4-.1-.8 0-1.1.1s-.6.4-.8.8c-5.5 9.9-10.5 20.2-14.9 30.6-44.6-6.8-89.9-6.8-134.4 0-4.5-10.5-9.5-20.7-15.1-30.6-.2-.3-.5-.6-.8-.8s-.7-.2-1.1-.2C162.5 39 122.2 51.5 84.1 69c-.3.1-.6.4-.8.7C7.1 183.5-13.8 294.6-3.6 404.2c0 .3.1.5.2.8s.3.4.5.6c44.4 32.9 94 58 146.8 74.2.4.1.8.1 1.1 0s.7-.4.9-.7c11.3-15.4 21.4-31.8 30-48.8.1-.2.2-.5.2-.8s0-.5-.1-.8-.2-.5-.4-.6-.4-.3-.7-.4c-15.8-6.1-31.2-13.4-45.9-21.9-.3-.2-.5-.4-.7-.6s-.3-.6-.3-.9 0-.6.2-.9.3-.5.6-.7c3.1-2.3 6.2-4.7 9.1-7.1.3-.2.6-.4.9-.4s.7 0 1 .1c96.2 43.9 200.4 43.9 295.5 0 .3-.1.7-.2 1-.2s.7.2.9.4c2.9 2.4 6 4.9 9.1 7.2.2.2.4.4.6.7s.2.6.2.9-.1.6-.3.9-.4.5-.6.6c-14.7 8.6-30 15.9-45.9 21.8-.2.1-.5.2-.7.4s-.3.4-.4.7-.1.5-.1.8.1.5.2.8c8.8 17 18.8 33.3 30 48.8.2.3.6.6.9.7s.8.1 1.1 0c52.9-16.2 102.6-41.3 147.1-74.2.2-.2.4-.4.5-.6s.2-.5.2-.8c12.3-126.8-20.5-236.9-86.9-334.5zm-302 267.7c-29 0-52.8-26.6-52.8-59.2s23.4-59.2 52.8-59.2c29.7 0 53.3 26.8 52.8 59.2 0 32.7-23.4 59.2-52.8 59.2m195.4 0c-29 0-52.8-26.6-52.8-59.2s23.4-59.2 52.8-59.2c29.7 0 53.3 26.8 52.8 59.2 0 32.7-23.2 59.2-52.8 59.2"/></svg>
</a>
<a href="https://github.com/orgs/data-privacy-stack/packages" target="_blank" rel="noopener" title="github.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M349.9 236.3h-66.1v-59.4h66.1zm0-204.3h-66.1v60.7h66.1zm78.2 144.8H362v59.4h66.1zm-156.3-72.1h-66.1v60.1h66.1zm78.1 0h-66.1v60.1h66.1zm276.8 100c-14.4-9.7-47.6-13.2-73.1-8.4-3.3-24-16.7-44.9-41.1-63.7l-14-9.3-9.3 14c-18.4 27.8-23.4 73.6-3.7 103.8-8.7 4.7-25.8 11.1-48.4 10.7H2.4c-8.7 50.8 5.8 116.8 44 162.1 37.1 43.9 92.7 66.2 165.4 66.2 157.4 0 273.9-72.5 328.4-204.2 21.4.4 67.6.1 91.3-45.2 1.5-2.5 6.6-13.2 8.5-17.1zm-511.1-27.9h-66v59.4h66.1v-59.4zm78.1 0h-66.1v59.4h66.1zm78.1 0h-66.1v59.4h66.1zm-78.1-72.1h-66.1v60.1h66.1z"/></svg>
</a>
<a href="mailto:presidio@dataprivacystack.org" target="_blank" rel="noopener" title="" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4l208 156a48 48 0 0 0 57.6 0l208-156c12.1-9.1 19.2-23.3 19.2-38.4 0-26.5-21.5-48-48-48zM0 196v188c0 35.3 28.7 64 64 64h384c35.3 0 64-28.7 64-64V196L313.6 344.8c-34.1 25.6-81.1 25.6-115.2 0z"/></svg>
</a>
<a href="https://huggingface.co/spaces/presidio/presidio_demo" target="_blank" rel="noopener" title="huggingface.co" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2026 Fonticons, Inc.--><path fill="currentColor" d="M493.7.9 299.5 75.6l2.3-29.3c1-12.8-12.8-21.5-24-15.1L101.3 133.4C38.6 169.7 0 236.6 0 309c0 112.1 90.9 203 203 203 72.4 0 139.3-38.6 175.6-101.3l102.2-176.4c6.5-11.1-2.2-25-15.1-24l-29.3 2.3 74.7-194.2c.6-1.5.9-3.2.9-4.8 0-7.5-6-13.5-13.5-13.5q-2.55 0-4.8.9zM192 192a128 128 0 1 1 0 256 128 128 0 1 1 0-256m0 96a32 32 0 1 0-64 0 32 32 0 1 0 64 0m16 96a16 16 0 1 0 0-32 16 16 0 1 0 0 32"/></svg>
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<div class="md-progress" data-md-component="progress" role="progressbar"></div>
<script id="__config" type="application/json">{"annotate":null,"base":"../../..","features":["navigation.instant","navigation.instant.progress","content.tabs.link","content.code.copy","content.code.annotate","navigation.tabs","navigation.tabs.sticky","navigation.top","navigation.footer","search.suggest","search.highlight","toc.follow"],"search":"../../../assets/javascripts/workers/search.b6b7e04f.min.js","tags":null,"translations":{"clipboard.copied":"Copied to clipboard","clipboard.copy":"Copy to clipboard","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.placeholder":"Type to start searching","search.result.term.missing":"Missing","select.version":"Select version"},"version":null}</script>
<script src="../../../assets/javascripts/bundle.ee611ef6.min.js"></script>
</body>
</html>