Prompt Engineering Data Extraction Structured Output

Extract Data From Text with AI

Free text in, named fields out. The extraction prompt pattern that turns any unstructured text into consistent, parseable records.

Overview

Asking a model to "pull out the important information" produces different fields every run. Reliable extraction means naming the fields, describing what each one holds, and deciding two things up front: what happens when a value is missing, and how much inference is allowed. This resource loads a lead-form extraction — free text from a contact form into six named CRM fields, strict ambiguity, null for anything absent — the smallest complete example of the pattern that works on any text.

How to use this resource

  1. Name the fields, not the wish

    Replace "important details" with lead_name, email, use_case — fields the consumer can rely on existing.

  2. Decide the missing-data behavior

    Null keeps keys stable for pipelines; empty or "unknown" keeps gaps visible for humans. Decide once, in the prompt.

  3. Set the ambiguity policy

    Strict for data you'll act on, best guess for data you'll review. The default drift between the two is where inconsistency comes from.

Why This Works

  • Named fields with descriptions turn a vague request into a checkable contract
  • Explicit missing-data rules eliminate the model's biggest improvisation point
  • The example extraction shows the exact shape, so the model imitates instead of inventing

Best for

  • Any pipeline that feeds model output into code or a spreadsheet
  • Teams tired of extraction results that change shape between runs
  • Texts with no fixed layout — notes, messages, form dumps

Not for

  • Defining the output format in depth — that's the JSON Output Prompt Builder
  • Assigning labels from a fixed set — that's classification, not extraction

Use cases

  • Turning free-text form submissions into CRM-ready records
  • Getting the same six fields out of every text, every run
  • Replacing "summarize the key info" prompts with named-field extraction

FAQ

How does this extraction prompt handle a field like company or timeline that isn't in the text?

It sets that field to null and keeps the key. The MISSING DATA rule says "If a field is not found in the source, set it to null — do not omit the key," and "Never invent or guess a value." With the AMBIGUITY POLICY — extract only what's "explicitly stated" — the six-field shape stays stable every run. You run the prompt; downstream code consumes the JSON.

Why does team_size come out as a number instead of words?

An explicit EXTRACTION RULE handles it: "team_size: Extract as a digit, not words," and the valid-extraction example shows "team_size": 3 unquoted. That keeps the field parseable for a spreadsheet or CRM rather than yielding "three." The prompt instructs the model on this; whether your assistant honors it perfectly is something you verify — the AI Output Validator is the separate step for that.

Is this extraction prompt the same as classifying text into categories?

Extraction pulls named values that exist in the text into fields like use_case and email; classification assigns a label from a fixed set, which the notFor line calls out as a different job. Here the model reads free text and returns the six defined fields as one JSON object with no extra fields. If you need fixed-label tagging instead of value extraction, this preset isn't the pattern.

More resources from Extraction Prompt Generator

Resources that pair well

Related tools

Projects that use this resource

Workflows that use this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.