What matters in AI.

Subscribe

Learn / AI security

Definition · AI security

Training data extraction

Training data extraction is an attack that uses queries to make an AI model output verbatim copies of its training data. The copies can hold names, phone numbers, email addresses, code and full images. NIST limits the term to generative models that an attacker prompts with selected inputs.

Last reviewed

Key points

  • Training data extraction makes a model output verbatim copies of its training data. The attacker needs only queries.
  • In 2021, Carlini and colleagues got hundreds of verbatim texts from GPT-2, with names, phone numbers and email addresses.
  • In 2023, Nasr and colleagues got more than 10,000 unique memorized examples from ChatGPT (gpt-3.5-turbo) with $200 of queries.
  • Larger models, text seen many times, and longer prompts all make extraction easier.
  • No single control stops it. Data cleanup, deduplication, differential privacy and output filters each decrease the risk, and each has limits.

How training data extraction works

A model keeps some of its training data verbatim. That is memorization. Extraction finds those copies with queries, and with no access to the data.

Carlini and colleagues used two steps against GPT-2 (USENIX Security 2021):

  1. Sample. Get a large quantity of text from the model.
  2. Rank. Score each output with tests such as perplexity and zlib compression. Text that the model finds too easy is probably memorized.
Training data extraction: get many outputs, rank them, keep the ones that are probably memorized.
Training data extraction: get many outputs, rank them, keep the ones that are probably memorized.

Of the 1,800 top outputs they examined, 604 were unique training examples (33.5%).

Why training data extraction is a risk

Training data extraction turns a model into a data leak. The leaked items come from the training data.

Study Model Result
Carlini et al., 2021 GPT-2 Hundreds of verbatim texts: names, phone numbers, email addresses, code
Carlini et al., 2023 Stable Diffusion v1.4 109 training images from 175 million outputs
Nasr et al., 2023 ChatGPT (gpt-3.5-turbo) More than 10,000 unique examples for $200 of queries
Cooper et al., 2025 Llama 3.1 70B The first Harry Potter book, near verbatim

Three results are of interest to a security team:

  • One copy can be sufficient. Some GPT-2 texts, such as names, code and UUIDs, were in only one training document.
  • Private facts come out. In the ChatGPT attack, 16.9% of the tested outputs held memorized personal data.
  • Safety training does not stop it. A prompt to say the word “poem” forever made ChatGPT give training data 150 times more frequently than earlier attacks.

In practice

What makes extraction easier

Carlini and colleagues (2022) found that memorization increases with three causes:

  • Model capacity. Larger models memorize more.
  • Copies of a text. Kandpal and colleagues (2022) found a text seen 10 times comes out about 1,000 times more frequently. The baseline is a text seen one time.
  • Prompt length. More of the correct text in the prompt gives back more of it.

The risk is not the same for all models. Cooper and colleagues (2025) tested 50 books in 17 open weight models. Most models did not memorize most books.

Controls and their limits

OWASP LLM Top 10 puts a training data leak in LLM02:2025 Sensitive Information Disclosure.

Control What it does Limit, from the sources
Sanitize training data Removes personal data before training Carlini and colleagues: “some private data will always slip through”
Deduplication Removes copies of the same text Diffusion study: “not a perfect solution”
Differential privacy Limits what one record adds to the model Carlini and colleagues: “unclear how to apply DP” correctly on web data
Output filter Stops outputs that agree with known training text Works only if it can find memorized text reliably
System prompt rules Tell the model not to share data OWASP: these “may not always be honored”

Carlini and colleagues say that audits are “vital”. Use the same two steps on your own model before release. Then measure how much known private text comes back. AI red teaming can include this test.

Where definitions disagree

The sources do not give the term the same scope.

  • NIST limits it to generative models that the attacker prompts.
  • Carlini and colleagues use it for any attack that gets individual training examples by queries.
  • Nasr and colleagues count only data that an attacker can get with no training data. Their term for this is extractable memorization.

Some tests prompt the model with the correct start of a training text. Nasr and colleagues use the term discoverable memorization for the result, which is a maximum. Extractable memorization is the part that an attacker can get efficiently.

Model inversion and membership inference are different attacks. They infer facts about the data, and do not output verbatim copies.

Questions and answers

What is the difference between training data extraction and membership inference?

Membership inference gives a yes or no result: a record was in the training set, or it was not. Training data extraction gets the record itself, verbatim, with no prior knowledge of it. Carlini and colleagues used membership inference scores in the second step of their attack on GPT-2.

Does safety training stop training data extraction?

No. ChatGPT (gpt-3.5-turbo) was an aligned production model. In 2023, Nasr and colleagues got more than 10,000 unique memorized examples from it with $200 of queries. They write that "current alignment techniques do not eliminate memorization."

Does training data extraction work on image models?

Yes. In 2023, Carlini and colleagues got 109 training images from Stable Diffusion v1.4, with photos of individual persons. They found diffusion models much less private than earlier GAN models.

Sources

  1. NIST Glossary: training data extraction (from NIST AI 100-2e2025)NIST, Mar 2025
  2. Extracting Training Data from Large Language ModelsUSENIX Security 21 (Carlini et al.), Aug 2021
  3. Extracting Training Data from Large Language Models (full text)arXiv (Carlini et al.), 14 Dec 2020
  4. Scalable Extraction of Training Data from (Production) Language ModelsarXiv (Nasr et al.), 28 Nov 2023
  5. Scalable Extraction of Training Data from (Production) Language ModelsarXiv (Nasr et al.), 28 Nov 2023
  6. Extracting Training Data from Diffusion ModelsarXiv (Carlini et al.), 30 Jan 2023
  7. Quantifying Memorization Across Neural Language ModelsarXiv (Carlini et al.), 15 Feb 2022
  8. Deduplicating Training Data Mitigates Privacy Risks in Language ModelsarXiv (Kandpal, Wallace, Raffel), 14 Feb 2022
  9. Extracting memorized pieces of (copyrighted) books from open-weight language models (v4)arXiv (Cooper, Lemley et al.), 30 Nov 2025
  10. LLM02:2025 Sensitive Information DisclosureOWASP GenAI Security Project