JSON Data Extraction Pipeline
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
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] """
Example input
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.
Example output
[
{ "company_name": "Acme Robotics", "revenue": "$42M", "ceo_name": "Dana Whitfield", "industry": "Warehouse automation" },
{ "company_name": "Northwind Foods", "revenue": null, "ceo_name": null, "industry": "Grocery distribution" }
]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.parseand 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.