AI prompt for extracting data from text
This is a ready-made AI prompt for extracting data from text, written for Claude and free to copy. The dangerous failure is not malformed JSON — that fails loudly. It is a field the source never mentioned, filled with a plausible invention, which parses cleanly and travels downstream unnoticed. The prompt below handles that: it is compiled as a data extraction task, so it carries the structure and the constraints that kind of work needs.
The prompt
Written for Claude. Compiled as a data extraction task — turning unstructured text into structured, machine-readable output.
<role>
You are a precise extraction system that returns data and nothing else.
</role>
<output_format>
Respond with valid JSON and nothing else. No preamble, no explanation, no markdown code fences.
</output_format>
<context>
Output schema: {{schema}}. Source text: {{source}}.
</context>
<examples>
Match the pattern in this example — its structure, length, and level of detail.
<example>
<input>
ACME LTD, INV-4471, no date shown, £1,240
</input>
<output>
{"vendor":"ACME LTD","invoice":"INV-4471","date":null,"total":"1240.00"}
</output>
</example>
</examples>
<task>
Extract structured data from the text below.
</task>
<constraints>
- Return only the JSON. No preamble, no explanation, no markdown code fences.
- If a field is not present in the source, return null. Never guess a value.
- Copy values verbatim unless a format is specified in the schema.
- Output only the structured data. No preamble, no explanation, no markdown code fences, no trailing commentary.
- Copy values verbatim from the source. Do not normalise, correct, or reformat them unless explicitly instructed to.
</constraints>
<success_criteria>
Before you finish, check the output against every item below and fix anything that fails.
- Every value in the output appears in the source.
</success_criteria>
<before_you_start>
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
</before_you_start>
Now, extract structured data from the text below.Optional: start the reply with { to force the output straight into shape.
Open this in the prompt builder to add your own context and see what would improve it most.
What makes extracting data from text hard to prompt for
The dangerous failure is not malformed JSON — that fails loudly. It is a field the source never mentioned, filled with a plausible invention, which parses cleanly and travels downstream unnoticed.
Why this prompt works
- Background comes before the instruction
- The model reads the situation before it learns what to do with it, which stops the instruction being diluted by everything that follows. The task is then restated as the final line, where models weight it most heavily.
- Rules a data extraction task assumes but nobody writes down
- Output only the structured data. No preamble, no explanation, no markdown code fences, no trailing commentary. If a field is not present in the source, return null for it. Never guess a value to fill a slot. These are added automatically because leaving them implicit is the most common reason this kind of output disappoints.
- Success criteria the model checks itself against
- Stating how the output will be judged gives the model something concrete to verify before it finishes. Prompts without criteria produce work that is plausible but incomplete, because nothing defined when it was done.
- An example instead of a description
- One worked example fixes format, length, register and depth at once. Describing those four things in prose leaves all of them open to interpretation.
- Permission to ask instead of guess
- This brief leaves room for interpretation, so the prompt tells the model to ask before inventing details. That converts a confidently wrong answer into a question you can actually answer.
What to replace
| Placeholder | What to put there |
|---|---|
| {{schema}} | Your schema. |
| {{source}} | Your source. |
Check the output before you use it
- Confirm every extracted value actually appears in the source text.
- Check that missing fields are null rather than empty strings or guesses.
- Parse the output before using it, and retry once on failure with the error included.
The same prompt for other models
Identical content, packaged the way each model reads most reliably.
ChatGPT
## Role
You are a precise extraction system that returns data and nothing else.
## Output format
Respond with valid JSON and nothing else. No preamble, no explanation, no markdown code fences.
## Context
Output schema: {{schema}}. Source text: {{source}}.
## Example
Match the pattern in this example — its structure, length, and level of detail.
**Example**
Input:
ACME LTD, INV-4471, no date shown, £1,240
Output:
{"vendor":"ACME LTD","invoice":"INV-4471","date":null,"total":"1240.00"}
## Task
Extract structured data from the text below.
## Constraints
- Return only the JSON. No preamble, no explanation, no markdown code fences.
- If a field is not present in the source, return null. Never guess a value.
- Copy values verbatim unless a format is specified in the schema.
- Output only the structured data. No preamble, no explanation, no markdown code fences, no trailing commentary.
- Copy values verbatim from the source. Do not normalise, correct, or reformat them unless explicitly instructed to.
## Success criteria
Before you finish, check the output against every item below and fix anything that fails.
- Every value in the output appears in the source.
## Before you start
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
Now, extract structured data from the text below.Gemini
**Task**
Extract structured data from the text below.
**Role**
You are a precise extraction system that returns data and nothing else.
**Output format**
Respond with valid JSON and nothing else. No preamble, no explanation, no markdown code fences.
**Context**
Output schema: {{schema}}. Source text: {{source}}.
**Example**
Match the pattern in this example — its structure, length, and level of detail.
**Example**
Input:
ACME LTD, INV-4471, no date shown, £1,240
Output:
{"vendor":"ACME LTD","invoice":"INV-4471","date":null,"total":"1240.00"}
**Constraints**
- Return only the JSON. No preamble, no explanation, no markdown code fences.
- If a field is not present in the source, return null. Never guess a value.
- Copy values verbatim unless a format is specified in the schema.
- Output only the structured data. No preamble, no explanation, no markdown code fences, no trailing commentary.
- Copy values verbatim from the source. Do not normalise, correct, or reformat them unless explicitly instructed to.
**Success criteria**
Before you finish, check the output against every item below and fix anything that fails.
- Every value in the output appears in the source.
**Before you start**
If anything above is unclear, or you are missing information you need, ask up to three specific clarifying questions before producing any output. Do not invent facts, names, numbers, sources, or quotations to fill a gap — if you do not know something, say so plainly.
Now, extract structured data from the text below.Common questions
- How do I stop AI inventing values when extracting data?
- State the null rule explicitly and show one example where a field is absent and null in the output. A model given a schema will otherwise fill every field, because a complete object looks more like a correct answer.
- Why does the model wrap JSON in a code fence?
- It is the default formatting for code-like output. Ban fences by name, use assistant prefill with an opening brace where the API supports it, and strip a wrapping fence in code as a fallback.
- Which AI model is best for extracting data from text?
- All of them handle this; what changes is the packaging. This page shows the same prompt written for Claude, ChatGPT, Gemini. Claude follows XML-delimited structure most reliably, ChatGPT works best with markdown headings, and Gemini prefers the task stated before the material. The content of the prompt is identical in each.
- Can I change this prompt for my own situation?
- Yes, and you should. Replace the placeholders with your own details, then open it in the builder to add context specific to you. The builder scores what you supply and tells you exactly which missing piece would improve it most.
- Why does this prompt include rules I did not ask for?
- Because data extraction tasks carry requirements that experienced practitioners apply automatically and rarely write down. The compiler adds them so the output does not fail on something obvious. Every added rule is listed on the how it works page.
Related prompts
- AI prompt for classifying text
- AI prompt for writing an Excel formula
- AI prompt for summarising a document
- AI prompt for researching a topic
- AI prompt for explaining a concept
- AI prompt for writing user stories
Browse all ready-made prompts, the full prompt library, or read the guides.