Back to cookbook

JSON Data Extraction Pipeline

17 views Published

Make this prompt yours

Share

This prompt converts messy, unstructured text (emails, articles, transcripts) into a predictable JSON array that your code can parse without cleanup.

It solves the three usual failures: the model wrapping JSON in markdown fences, adding friendly commentary, and inventing values for missing fields. A fixed schema plus an explicit null rule makes the output machine-safe.

Prompt template

Make this prompt yours

prompt-template
113 tokens
Extract the following fields from the text below: [FIELD 1, FIELD 2, FIELD 3, FIELD 4]. Output rules: - Return strictly a JSON array of objects, one per entity found. - Use exactly these keys: [key_1, key_2, key_3, key_4]. - If a value is missing or unclear, use null. Never guess. - Do not wrap the output in markdown code fences. - Do not add any explanation before or after the JSON. Text: """ [PASTE TEXT] """

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
60 tokens
Fields: company_name, revenue, ceo_name, industry Text: Acme Robotics reported $42M in annual revenue this quarter. CEO Dana Whitfield said the warehouse-automation firm plans to expand into Europe. Separately, Northwind Foods, a grocery distributor, declined to share figures.

When to use it

  • Pulling company, person or price data out of news and filings
  • Structuring support tickets or survey answers
  • ETL steps where a script consumes the model output
  • Bulk processing where each document must yield the same shape

Best practices

  • Provide the exact schema with field names and types.
  • Say what to do for missing data (null), never leave it implicit.
  • Use your provider's JSON / structured-output mode when available.
  • Validate the result with a schema library and retry on failure.

Common mistakes

  • Not specifying the schema, so keys change between runs.
  • Letting the model guess missing values; you get plausible fabrications.
  • Parsing with a bare JSON.parse and no retry path.

FAQs

How do I stop the model adding markdown fences?

State it explicitly, as the template does, and prefer your API's structured-output or JSON mode, which guarantees valid JSON.

What if the text contains many entities?

The array format handles that. For very long documents, chunk the text and merge the arrays afterwards.

Can I extract nested data?

Yes. Describe the nested shape in the rules and add an example object.

Found this prompt useful? Share it.

Share

More in Data Analysis

Data Analysis

AI Prompt to Build a Data Dictionary From a Spreadsheet or Database Table

This data dictionary prompt asks ChatGPT, Claude, or Gemini to turn a raw spreadsheet or database table into a clear reference document: eve…

You are a data analyst creating a data dictionary for a dataset so other people can understand and use it correctly.

Context:
- Source: [e.g., spreadsheet export, PostgreSQL table, CSV file]
- Table or sheet name: [NAME]
- Audience: [e.g., BI analysts, a new engineer, external partner]

Data sample (paste column headers plus 10-20 real rows below):
[PASTE SAMPLE DATA HERE]

Task:
For each column in the sample, produce:
1. Column name as it appears in the source.
2. Inferred data type (string, integer, decimal, date, boolean, categorical, etc.).
3. A one-sentence description of what the column represents, based only on the sample data.
4. Notes on anything unusual: nulls, mixed formats, inconsistent units, likely key or foreign key, or values that look like placeholders.
5. A confidence level (High, Medium, Low) for how certain you are about the description.

Constraints:
- Do not state a description as certain if the sample doesn't clearly support it; use Medium or Low confidence instead.
- Call out any columns that look like duplicates of each other or likely primary/foreign keys in a separate summary section.
- Keep descriptions to one sentence each.

Output format:
A single Markdown table with columns: Column Name | Data Type | Description | Notes | Confidence, followed by a short 'Keys and Relationships' summary section.

Make this prompt yours

Data Analysis

AI Prompt to Query and Analyze Supabase Data via Supabase's MCP Server

This prompt is for teams running Claude or ChatGPT with Supabase's MCP server connected, so the model can read a live Postgres database dire…

You are a data analyst with read-only access to a Postgres database through an MCP database connection. Follow these rules for every request:

ROLE
- Act as a careful analyst who verifies before concluding.

CONTEXT
- Database: [DATABASE NAME]
- Relevant tables: [TABLE NAMES, e.g. users, subscriptions, events]
- Business question: [QUESTION, e.g. how many trial users converted to paid in the last 30 days]

CONSTRAINTS
- Only run read-only SELECT queries. Never run INSERT, UPDATE, DELETE, or DDL statements.
- Before answering, list the exact query or queries you plan to run and wait for confirmation if any query touches more than [ROW LIMIT] rows.
- If a referenced table or column does not exist, say so explicitly instead of guessing a substitute.
- Show a sample of up to 5 returned rows alongside any aggregate numbers.

OUTPUT FORMAT
1. Queries run (as SQL)
2. Row counts and sample data
3. Plain-language answer to the business question
4. Any caveats about data quality or missing values

Task: [SPECIFIC ANALYSIS REQUEST]

Make this prompt yours

Data Analysis

AI Prompt to Find Correlations and Trends Across Multiple Metrics in a Dataset

This prompt is for analysts, marketers, and founders who need to find correlations and trends across multiple metrics in a dataset without w…

Role: You are a data analyst who specializes in identifying patterns across business metrics.

Context:
- Dataset: [PASTE_DATA_OR_DESCRIBE_COLUMNS]
- Metrics to analyze: [LIST_OF_METRIC_COLUMNS]
- Time period covered: [TIME_PERIOD]
- Business context: [BRIEF_DESCRIPTION_OF_WHAT_THESE_METRICS_MEASURE]

Task:
Analyze the relationships between the listed metrics and identify:
1. Which pairs of metrics show a notable positive or negative relationship
2. The approximate strength of each relationship (strong, moderate, weak)
3. A plain-language explanation of what the relationship might mean in this business context
4. Any relationship that looks correlated but is more likely coincidental or explained by a third factor

Constraints:
- Clearly label every finding as correlation, not causation, unless a controlled comparison is explicitly provided
- Do not report relationships based on fewer than [MINIMUM_DATA_POINTS] data points
- Flag any missing or inconsistent data that could affect the reliability of a finding

Output format:
A summary paragraph followed by a numbered list of relationships, each with strength, explanation, and a caution note where relevant.

Make this prompt yours